title: Extracting whole SOAP message with JAX-WS
body: <p>I have an EJB stateless bean web service and would like to get access to the whole SOAP message, not just the SOAP Body as I'm currently getting in the parameter. I want to submit the message to a different component. I'm using Spring configuration but not Spring-WS. I followed this tutorial:</p>
  
  <p><a href="http://java.dzone.com/articles/creating-soap-message-handlers" rel="nofollow">http://java.dzone.com/articles/creating-soap-message-handlers</a></p>
  
  <p>as is and didn't make any changes for now.  It just logs the SOAP message.  handleMessage() isn't getting called.</p>
  
  <pre><code>@Stateless
  @WebService(portName = "XRequest_PortType", serviceName = "XRequestService", endpointInterface = "XRequestPortType")
  @Addressing(enabled = true)
  @HandlerChain(file = "LogMessage_handler.xml")
  @Interceptors(SpringBeanAutowiringInterceptor.class)
  public class XRequest_PortTypeWS implements
          XRequestPortType {
  ...}
  </code></pre>
  
  <p>The LogMessage_handler.xml is slightly different from the tutorial but I tried it both ways:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;javaee:handler-chains 
       xmlns:javaee="http://java.sun.com/xml/ns/javaee" 
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;javaee:handler-chain&gt;
      &lt;javaee:handler&gt;
        &lt;javaee:handler-class&gt;com.test.ws.LogMessageHandle&lt;/javaee:handler-class&gt;
      &lt;/javaee:handler&gt;
    &lt;/javaee:handler-chain&gt;
  &lt;/javaee:handler-chains&gt;
  </code></pre>
  
  <p>LogMessageHandler:</p>
  
  <pre><code>package com.test.ws;
  
  import java.io.IOException;
  import java.util.Collections;
  import java.util.Set;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.xml.namespace.QName;
  import javax.xml.soap.SOAPException;
  import javax.xml.soap.SOAPMessage;
  import javax.xml.ws.handler.MessageContext;
  import javax.xml.ws.handler.soap.SOAPHandler;
  import javax.xml.ws.handler.soap.SOAPMessageContext;
  
  /**
   * 
   * @author meerasubbarao
   */
  public class LogMessageHandler implements SOAPHandler&lt;SOAPMessageContext&gt; {
  
      public boolean handleMessage(SOAPMessageContext messageContext) {
          log(messageContext);
          return true;
  
      }
  
      public Set&lt;QName&gt; getHeaders() {
          return Collections.EMPTY_SET;
      }
  
      public boolean handleFault(SOAPMessageContext messageContext) {
          return true;
      }
  
      public void close(MessageContext context) {
      }
  
      private void log(SOAPMessageContext messageContext) {
          SOAPMessage msg = messageContext.getMessage(); // Line 1
          try {
              msg.writeTo(System.out); // Line 3
          } catch (SOAPException ex) {
              Logger.getLogger(LogMessageHandler.class.getName()).log(
                      Level.SEVERE, null, ex);
          } catch (IOException ex) {
              Logger.getLogger(LogMessageHandler.class.getName()).log(
                      Level.SEVERE, null, ex);
          }
      }
  
  }
  </code></pre>
  
  <p>Is this even the best way to get the whole SOAP message? I would still need to to call a Spring bean from XRequest_PortTypeWS to send the SOAP message.</p>