Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log SOAP Messages

I created a class that intercepts the Request-Response cycle of SOAP message exchange and I wanted to log the exchange of messages. What's the best way so that I could log the SOAP message in my log file?

I dont want it to be pretty printed in my log file but I just want to access and view the request and response SOAP envelope.

I tried with this code:

public class LogHandler{    
    private static final Logger _LOG;
    @Override
    protected void handleResponse(SOAPMessage message)
        logSOAPMessage(message);
    }
    @Override
    protected void handleRequest(SOAPMessage message)
        logSOAPMessage(message);
    }    
    private void logSOAPMessage(SOAPMessage message){
      _LOG.info(":: Logging SOAP Message :: " + message.toString());
    }
}

But doesnt get the required message.

:: Logging SOAP Message :: oracle.j2ee.ws.saaj.soap.soap11.Message11@715346

Any hints?

like image 356
Mark Estrada Avatar asked Jun 21 '11 07:06

Mark Estrada


People also ask

What are SOAP messages?

A SOAP message is an XML document that consists of a SOAP envelope, an optional SOAP header, and a SOAP body. The SOAP message header contains information that allows the message to be routed through one or more intermediate nodes before it reaches its final destination.

Where can I find SOAP logs?

SoapUI log displays the response information from the web-server. The same information is stored in soapui. log file of the SOAP-UI installed folder under 'bin' directory.


2 Answers

If message is the SOAPMessage then do the following:

ByteArrayOutputStream bout = new ByteArrayOutputStream();   
message.writeTo(bout);   
String msg = bout.toString("UTF-8");

Now String msg has the soap message and you can log it.

In your example:

private void logSOAPMessage(SOAPMessage message){
    ByteArrayOutputStream bout = new ByteArrayOutputStream();  
    message.writeTo(bout);  
    String msg = bout.toString("UTF-8");  
    _LOG.info(":: Logging SOAP Message :: " + msg);     
}
like image 99
Cratylus Avatar answered Oct 05 '22 00:10

Cratylus


What you are seeing is the toString of the SOAPMessage. You might have to lookup the javadocs to see if you can get the SOAPEnvelope from Oracle's SOAPMessage and that should contain the incoming/outgoing SOAP message.

Edit: Please check this for getSoapHeader() and getSoapBody() to deconstruct the soap message. You might have to figure out the same for Oracle's wrapper of SOAPMessage.

like image 40
rajasaur Avatar answered Oct 05 '22 02:10

rajasaur