搜索

59.2. 使用配置添加拦截器

download PDF

概述

将拦截器附加到端点的最简单方法是使用配置文件。要附加到端点的每个拦截器都使用标准 Spring bean 配置。然后,可以使用 Apache CXF 配置元素将拦截器的 bean 添加到正确的拦截器链中。

具有关联拦截器链的每个运行时组件都可以使用专用的 Spring 元素进行配置。组件的每个元素都有一组标准的子项,用于指定其拦截器链。每个与组件关联的拦截器链都有一个子级。要添加到链中的拦截器的 Bean 的子项列表。

配置元素

表 59.1 “拦截器链配置元素” 描述将拦截器附加到运行时组件的四个配置元素。

表 59.1. 拦截器链配置元素
元素描述

inInterceptors

包含 Bean 列表,配置拦截器以添加到端点的入站拦截器链中。

outInterceptors

包含 Bean 列表,配置拦截器以添加到端点的出站拦截器链中。

inFaultInterceptors

包含 Bean 列表,配置拦截器以添加到端点的入站故障处理拦截器链中。

outFaultInterceptors

包含 Bean 列表,配置拦截器以添加到端点的出站故障处理拦截器链中。

所有拦截器链配置元素都取一个 list 子元素。list 元素有一个子对象,用于附加到链的每个拦截器。可以使用 bean 元素直接配置拦截器或 ref 元素来指定拦截器,该元素引用配置拦截器的 bean 元素。

例子

例 59.1 “将拦截器附加到总线” 显示将拦截器附加到总线的入站拦截器链的配置。

例 59.1. 将拦截器附加到总线

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cxf="http://cxf.apache.org/core"
       xmlns:http="http://cxf.apache.org/transports/http/configuration"
       xsi:schemaLocation="
       http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
       http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  ...
  <bean id="GZIPStream" class="demo.stream.interceptor.StreamInterceptor"/>

  <cxf:bus>
    *<cxf:inInterceptors>
      <list>
        <ref bean="GZIPStream"/>
      </list>
    </cxf:inInterceptors>*
  </cxf:bus>
</beans>

例 59.2 “将拦截器附加到 JAX-WS 服务提供商” 显示将拦截器附加到 JAX-WS 服务的出站拦截器链的配置。

例 59.2. 将拦截器附加到 JAX-WS 服务提供商

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:wsa="http://cxf.apache.org/ws/addressing"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

  <jaxws:endpoint ...>
    *<jaxws:outInterceptors>
      <list>
        <bean id="GZIPStream" class="demo.stream.interceptor.StreamInterceptor" />
      </list>
    </jaxws:outInterceptors>*
  </jaxws:endpoint>
</beans>

更多信息

有关使用 Spring 配置配置端点的更多信息,请参阅 第 IV 部分 “配置 Web 服务端点”

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.