2016-06-11 109 views
2

我只在cxf_client.xml中添加了拦截器,但是对于传入apis也调用了相同的拦截器(即cxf_server)。以下是我的变化。 有人可以告诉我为什么这个拦截器正在调用传入的API吗? 是否因为服务器和客户端使用相同的总线?仅适用于使用配置的客户端的CXF拦截器

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>* 

回答

1

由于您使用

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

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

inInterceptors 拦截器促成入站消息拦截器链。或S的表S

您可以使用入站连接,并在服务器的出站连接和cliente

例如具体的拦截器,在这里它是一个JAX-WS端点和客户端的配置与和out拦截器

<!-- 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> 
+0

非常感谢,所以我们只为客户端?对于服务器,我们可以为每个端点添加CXF为客户端提供的类似功能。 – user5417198

+0

您可以使用拦截器作为出站连接的客户端。和传入连接的一个不同的拦截器。但是,如果你想为每个端点配置精细的粒度,你可以使用在jax-rs服务器中配置的过滤器来预处理请求或者发布响应。 – pedrofb

+0

谢谢我使用javaws你的意思是实际添加拦截器吗? – user5417198