title: Apache CXF interceptor configuration
body: <p>I created a SOAP interceptor as described in <a href="http://cxf.apache.org/docs/interceptors.html" rel="nofollow">CXF docs</a>:</p>
  
  <pre><code>public class SoapMessageInterceptor extends AbstractSoapInterceptor {
      public SoapMessageInterceptor() {
          super(Phase.USER_PROTOCOL);
      }
      public void handleMessage(SoapMessage soapMessage) throws Fault {
          // ...
      }
  }
  </code></pre>
  
  <p>and registered it with the bus in Spring's application context:</p>
  
  <pre><code>  &lt;cxf:bus&gt;
      &lt;cxf:inInterceptors&gt;
        &lt;ref bean="soapMessageInterceptor"/&gt;
      &lt;/cxf:inInterceptors&gt;
    &lt;/cxf:bus&gt;
  
    &lt;jaxws:endpoint id="customerWebServiceSoap"
          implementor="#customerWebServiceSoapEndpoint"
          address="/customerService"/&gt;
  </code></pre>
  
  <p>All was working fine until I added a REST service:</p>
  
  <pre><code>  &lt;jaxrs:server id="customerWebServiceRest" address="/rest"&gt;
      &lt;jaxrs:serviceBeans&gt;
        &lt;ref bean="customerWebServiceRestEndpoint" /&gt;
      &lt;/jaxrs:serviceBeans&gt;
    &lt;/jaxrs:server&gt;
  </code></pre>
  
  <p>The problems is that the SOAP interceptor is now being triggered on REST requests also, which results in a class cast exception when the REST service is invoked.</p>
  
  <pre><code>&lt;ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"&gt;
    &lt;ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat"&gt;
      java.lang.ClassCastException: org.apache.cxf.message.XMLMessage
      cannot be cast to org.apache.cxf.binding.soap.SoapMessage
    &lt;/ns1:faultstring&gt;
  &lt;/ns1:XMLFault&gt;
  </code></pre>
  
  <p>Is there any way to restrict the interceptor to SOAP messages only through configuration?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Looks like I missed the page in the docs that describes this.
  Scroll down to <a href="http://cxf.apache.org/docs/jax-rs-filters.html" rel="nofollow">Difference between JAXRS filters and CXF interceptors</a></p>