title: Communication between cxf interceptors, listeners and webservice (jaxws)
body: <p>We have web service (jaxws) which is calling another web service (aslo jaxws). Jaxws client configuration looks like this  -- </p>
  
  <pre><code> &lt;jaxws:client id="helloClient"
                serviceClass="demo.spring.HelloWorld"
                address="http://localhost:9002/HelloWorld" &gt;
        &lt;jaxws:outInterceptors&gt;
               &lt;bean class="com.company.MyOutInterceptor"/&gt;
        &lt;/jaxws:outInterceptors&gt;
        &lt;jaxws:inFaultInterceptors&gt;
               &lt;bean class="com.company.MyInFaultInterceptor"/&gt;
        &lt;/jaxws:inFaultInterceptors&gt;
        &lt;cxf:properties&gt;
               &lt;entry key="org.apache.cxf.logging.FaultListener"&gt;
                   &lt;bean class="com.company.MyFaultListener"/&gt;
               &lt;/entry&gt;
        &lt;/cxf:properties&gt;
   &lt;/jaxws:client&gt;
  </code></pre>
  
  <p>As you can see we have two interceptors and one fault listener. We want to communication among these interceptors, fault listeners and web service code.
  As given in <a href="https://stackoverflow.com/questions/26184781/sharing-data-between-cxf-interceptor-and-webservice">SO THREAD</a>, we used cxf <a href="https://cxf.apache.org/javadoc/latest/org/apache/cxf/message/Exchange.html" rel="nofollow noreferrer">Exchange</a> object for communication between web service and interceptor. </p>
  
  <p>Our inFaultInterceptor code look like this -- </p>
  
  <pre><code>public class MyInFaultInterceptor extends AbstractPhaseInterceptor&lt;Message&gt;      {
        public MyInFaultInterceptor() {
             super(Phase.RECEIVE);
        }
  
        public void handleMessage(Message message) {
            message.getExchange().put("key", "value");
        }
  </code></pre>
  
  <p>}</p>
  
  <p>Out web service code look like this -- </p>
  
  <pre><code>public String addNumbers(int a, int b){
       try{
            myService.add(a,b);
       }catch(MyServiceException e){
            //Logging
       }
       Object value = PhaseInterceptorChain.getCurrentMessage().getExchange().get("key");
  }  
  </code></pre>
  
  <p>But, int the web service code we are getting null for given "key", means "key" is not present. </p>
  
  <blockquote>
    <p>Is there any way in which we can communicate between interceptors and
    web service?</p>
    
    <p><strong>P.S</strong> : We are able to communicate within interceptors and listeners with the above method. That is, we are able to access key set in
    outInterceptor in inFaultInterceptor, but keys set in any interceptor
    or listener is not accessible in web service.</p>
  </blockquote>