title: CXF WS, Interceptor: stop processing, respond with fault
body: <p>I'm scratching my head over this:
  Using an Interceptor to check a few SOAP headers, how can I abort the interceptor chain but still respond with an error to the user?</p>
  
  <p>Throwing a Fault works regarding the output, but the request is still being processed and I'd rather not have all services check for some flag in the message context.</p>
  
  <p>Aborting with "message.getInterceptorChain().abort();" really aborts all processing, but then there's also nothing returned to the client.</p>
  
  <p>What's the right way to go?</p>
  
  <pre class="lang-java prettyprint-override"><code>public class HeadersInterceptor extends AbstractSoapInterceptor {
  
      public HeadersInterceptor() {
          super(Phase.PRE_LOGICAL);
      }
  
      @Override
      public void handleMessage(SoapMessage message) throws Fault {
          Exchange exchange = message.getExchange();
          BindingOperationInfo bop = exchange.getBindingOperationInfo();
          Method action = ((MethodDispatcher) exchange.get(Service.class)
                  .get(MethodDispatcher.class.getName())).getMethod(bop);
  
          if (action.isAnnotationPresent(NeedsHeaders.class)
                  &amp;&amp; !headersPresent(message)) {
              Fault fault = new Fault(new Exception("No headers Exception"));
              fault.setFaultCode(new QName("Client"));
  
              try {
                  Document doc = DocumentBuilderFactory.newInstance()
                          .newDocumentBuilder().newDocument();
                  Element detail = doc.createElementNS(Soap12.SOAP_NAMESPACE, "mynamespace");
                  detail.setTextContent("Missing some headers...blah");
                  fault.setDetail(detail);
  
              } catch (ParserConfigurationException e) {
              }
  
              // bad: message.getInterceptorChain().abort();
              throw fault;
          }
      }
  }
  </code></pre>