Search code examples
web-servicescxfcxf-clientjava-ws

CXF interceptors only for client using configuration


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

Solution

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