简体   繁体   中英

How to read the SOAP raw rquest and response messages in axis2 webservices

I am using the axis2 web-service client and I want to capture the request and response raw xml. I have created a LogHandler to read the response raw xml, but I don't know how to configure this LogHandler file in an axis2 webservice. Could you please help me how to configure this LogHandler or tell me if there is any way to get the request and response xml's.

import org.apache.axis2.AxisFault;`enter code here`
import org.apache.axis2.context.MessageContext;`enter code here`
import org.apache.axis2.engine.Handler;`enter code here`
import org.apache.axis2.handlers.AbstractHandler;`enter code here`
import org.apache.axis2.description.AxisService;`enter code here`
import org.apache.log4j.Logger;`enter code here`
public class LogHandler extends AbstractHandler implements Handler {
    private static Logger logger = Logger.getLogger(LogHandler.class);

    private String name;

    public LogHandler() {
        System.out.println(" & from LogHandler &&& constructor :");
    }
    public String getName() {
        System.out
                .println("LogHandler.getName() LogHandlerLogHandlerLogHandlerLogHandlerLogHandler");
        return name;
    }
    public InvocationResponse invoke(MessageContext msgContext)
            throws AxisFault {
        logger.info("***" + msgContext.getEnvelope().toString());
        System.out.println("LogHandler.invoke()"
                + msgContext.getEnvelope().toString());
        AxisService axService = msgContext.getAxisService();
        logger.info("*Service******" + axService.toString());
        System.out.println("*axService******" + axService.toString());

        return InvocationResponse.CONTINUE;
    }
    public void revoke(MessageContext msgContext) {
        System.out.println("& LogHandler.revoke()");
    }
    public void setName(String name) {
        System.out.println("LogHandler " + name);
        this.name = name;
    }
}

You can have your custom phase defined and add your handler there and see your handler get executed or not. //i have added below configuration in axis2.xml but the service is not running.//Seems somewhere your message flow is broken.

Check this flowing guide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM