3

I have added interceptor only in cxf_client.xml but same interceptor are invoking for incoming apis as well(i.e cxf_server). below are my changes. Can some one please tell me why this interceptor are invoking for incoming APIs? is it because same bus use for both server and client?

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>*
user5417198
  • 53
  • 1
  • 4

1 Answers1

1

Because you are using

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

Check documentation http://cxf.apache.org/docs/bus-configuration.html

inInterceptors The interceptors contributed to inbound message interceptor chains. A list of s or s

You can use specific interceptors for inbound connection and outbound connections in server and cliente

For example, here it is the configuration of a jax-ws endpoint and client with in and out interceptors

<!-- 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>
pedrofb
  • 37,271
  • 5
  • 94
  • 142
  • Thanks so cant we make it only for client? For server we can add for each end point does CXF provide similar for client. – user5417198 Jun 11 '16 at 10:27
  • You can use interceptor acting as client for outbound connections. And a different interceptor for incoming connections. But if you want fine grain configuration for each endpoint, you can use filters configured in the jax-rs server to preproccess the request or post proceda the response – pedrofb Jun 11 '16 at 10:58
  • Thanks i ma using javaws do you mean add interceptor by pragmatically? – user5417198 Jun 11 '16 at 11:21
  • You can add an interceptor programmatically or using spring configuration. See answer – pedrofb Jun 11 '16 at 11:36
  • Yes but where can we mention for outbound? – user5417198 Jun 11 '16 at 14:11
  • You can use specific interceptors for inbound connection and outbound connections both client and server. Declare each one inside the jax-ws client or server – pedrofb Jun 11 '16 at 17:21