Search code examples
javaapache-axis

Print Axis2 Request Response XML


I want to print RAW Request Response XML to console. I have created the stubs using wsdl2java axis2.

wsdl2java has created 2 java files, one for stub and one for callbackhandler.

I am trying with below method but getting null value for

operationContext.getMessageContext("Out");
/
operationContext.getMessageContext("In");.

Code

public void SOAPLogHandler(Stub stub){  

ServiceContext serviceConxt = stub._getServiceClient().getServiceContext();

//**** Enable the Cache to hold the last operation
OperationContext OperationContext  = new OperationContext();
boolean cacheLastOperationContext = true;
OperationContext.setComplete(true); // Enable the Cache value
serviceConxt.setCachingOperationContext(cacheLastOperationContext);
serviceConxt.setLastOperationContext(OperationContext);

OperationContext operationContext = serviceConxt.getLastOperationContext();

if (operationContext != null) {
         MessageContext outMessageContext = operationContext.getMessageContext("Out");
             operationContext.getMessageContexts();
        if (outMessageContext != null) {
            System.out.println("OUT SOAP: "+outMessageContext.getEnvelope().toString());
             }
     MessageContext inMessageContext = operationContext.getMessageContext("In");
if (inMessageContext != null) {
    System.out.println("IN SOAP: "+ inMessageContext.getEnvelope().toString());
                  }
           }

Can you please let me know is there any other way to get the raw xml


Solution

  • unfortunately unless you intercept the message via say tcp monitor, you will have a tough time getting the raw message.