title: axis2 Log Response with Request
body: <p>I am very new to Web Service. </p>
  
  <p>I have one web service exposed, So client is consuming it but due to importance of service we want to Log SOAP Request and SOAP Response flowing IN and OUT.</p>
  
  <p>I am using Axis2-1.6.2
  This is what I tried so far, I wrote one custom Handler and Module class</p>
  
  <pre><code>import org.apache.axis2.AxisFault;
  import org.apache.axis2.context.MessageContext;
  import org.apache.axis2.engine.Handler;
  import org.apache.axis2.handlers.AbstractHandler;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  public class LogHandler extends AbstractHandler implements Handler {
      private static final Log log = LogFactory.getLog(LogHandler.class);
      private String name;
  
      public String getName() {
          System.out.println("LogHandler.getName()");
          return name;
      }
  
      public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
          log.info(msgContext.getEnvelope().toString());
          System.out.println("LogHandler.invoke()");
          return InvocationResponse.CONTINUE;        
      }
  
      public void revoke(MessageContext msgContext) {
          System.out.println("LogHandler.revoke()");
          log.info(msgContext.getEnvelope().toString());
      }
  
      public void setName(String name) {
          System.out.println("LogHandler.setName()");
          this.name = name;
      }
  }
  </code></pre>
  
  <p>I also wrote Module for above Handler</p>
  
  <pre><code>public class LoggingModule implements Module {
     //implemented methods
  }
  </code></pre>
  
  <p>From above Handler, I am able to Log Incoming SOAP Request and Outgoing SOAP Response.</p>
  
  <p>But the Problem is, I am getting many request at a time, So If i write Plain Request and Response, then while looking at Logs I am not able to identify whose Response is this.</p>
  
  <p>Logs in general it write</p>
  
  <pre><code>Request1 SOAP 
  Request2 SOAP 
  Response1 SOAP
  Request3 SOAP
  Request4 SOAP
  Response2 SOAP
  </code></pre>
  
  <p><code>invoke(MessageContext msgContext)</code> This method is getting invoked while request comes in and response goes out. Is there anything I can get request SOAP while response time it get called. </p>
  
  <p>So, I want some solution where in I can consolidate Request SOAP in Response SOAP, So 1 Log is complete Request-Response both. </p>
  
  <p>If any body can suggest some good solution for it will be helpful.</p>