【问题标题】:CXF interceptors only for client using configurationCXF 拦截器仅适用于使用配置的客户端
【发布时间】:2016-10-12 05:49:48
【问题描述】:

我只在 cxf_client.xml 中添加了拦截器,但同样的拦截器也在调用传入的 api(即 cxf_server)。以下是我的更改。 有人可以告诉我为什么这个拦截器会调用传入的 API 吗? 是因为服务器和客户端使用相同的总线吗?

cxf_client.xml

  <bean id="XCustomInterceptor" class="com.test.XCustomInterceptor"/>
<cxf:bus>
        <cxf:inInterceptors>
            <ref bean="XCustomInterceptor"/>
        </cxf:inInterceptors>
        <cxf:outInterceptors>
            <ref bean="XCustomInterceptor"/>
       </cxf:outInterceptors>
    </cxf:bus>*

【问题讨论】:

    标签: web-services cxf cxf-client java-ws


    【解决方案1】:

    因为你在使用

    <cxf:inInterceptors>
         <ref bean="XCustomInterceptor"/>
    </cxf:inInterceptors>
    

    查看文档http://cxf.apache.org/docs/bus-configuration.html

    在拦截器中 拦截器有助于入站消息拦截器链。 s 或 s 的列表

    您可以在服务器和客户端中使用特定的拦截器进行入站连接和出站连接

    例如,这里是配置一个 jax-ws 端点和带有输入和输出拦截器的客户端

    <!-- The SOAP endpoint --> 
    <jaxws:endpoint
       id="helloWorld"
       implementor="demo.spring.HelloWorldImpl"
       address="http://localhost/HelloWorld">
       <jaxws:inInterceptors>
          <ref bean="customInInterceptor"/>
        </jaxws:inInterceptors>
       <jaxws:outInterceptors>
          <ref bean="customOutInterceptor"/>
       </jaxws:outInterceptors>
    
    </jaxws:endpoint>
    
    <!-- The SOAP client bean -->
    <jaxws:client id="helloClient"
                serviceClass="demo.spring.HelloWorld"
                address="http://localhost/HelloWorld">
        <jaxws:inInterceptors>
            <ref bean="customClientInInterceptor"/>
        </jaxws:inInterceptors>
        <jaxws:outInterceptors>
            <ref bean="customClientOutInterceptor"/>
        </jaxws:outInterceptors>
     </jaxws:client>
    

    【讨论】:

    • 谢谢,我们不能只为客户制作吗?对于我们可以为每个端点添加的服务器,CXF 是否为客户端提供了类似的功能。
    • 您可以使用拦截器作为出站连接的客户端。以及用于传入连接的不同拦截器。但是如果你想为每个端点进行细粒度配置,你可以使用在 jax-rs 服务器中配置的过滤器来预处理请求或后处理响应
    • 谢谢我使用javaws你的意思是通过务实地添加拦截器?
    • 您可以通过编程方式或使用 spring 配置添加拦截器。查看答案
    • 是的,但是我们可以在哪里提及出站?
    猜你喜欢
    • 2012-10-03
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多