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
I managed to do so by adding a couple of lines in a method of the stub (the one you call to invoke the web service). I identified the line, i.e.
_operationClient.execute(true);
that effectively contacts the web service and added just after it:
_operationClient.getMessageContext("Out").getEnvelope().serialize(System.out);
_operationClient.getMessageContext("In").getEnvelope().serialize(System.out);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With