Question

I am very new to Web Service.

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.

I am using Axis2-1.6.2 This is what I tried so far, I wrote one custom Handler and Module class

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;
    }
}

I also wrote Module for above Handler

public class LoggingModule implements Module {
   //implemented methods
}

From above Handler, I am able to Log Incoming SOAP Request and Outgoing SOAP Response.

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.

Logs in general it write

Request1 SOAP 
Request2 SOAP 
Response1 SOAP
Request3 SOAP
Request4 SOAP
Response2 SOAP

invoke(MessageContext msgContext) 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.

So, I want some solution where in I can consolidate Request SOAP in Response SOAP, So 1 Log is complete Request-Response both.

If any body can suggest some good solution for it will be helpful.

Was it helpful?

Solution

You are getting request and response is logged, because you register your handler in both IN/OUT flows..

Say, if you register your handler at out flow, you will be able to pick your relevant request and response. That is, from response messgaecontext, you can access your request message context. from that, you can read your request message.[1]

But here you will see an issue, which if your request is failed, you wont be able to capture it in your outflow.That log might miss.

[1]http://vvratha.blogspot.com/2013/05/accessing-request-messagecontext-from.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top