SOAP Logging

I created a class that intercepts a SOAP messaging request-response loop, and I wanted to register messaging. What is the best way so that I can write a SOAP message to a log file?

I do not want it to be quite printed in my log file, but I just want to access and view the SOAP request and response 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 does not receive the required message.

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

Any clues?

+6
source share
3 answers

What you see is toString SOAPMessage. You may need to search javadocs to find out if you can get SOAPEnvelope from Oracle SOAPMessage and contain an inbound / outbound SOAP message.

Edit: Please check this for getSoapHeader () and getSoapBody () to deconstruct the soap message. You may need to find the same for the Oracle SOAPMessage shell.

+2
source

If message is SOAPMessage , follow these steps:

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

Now String msg has a soap message and you can register 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); } 
+10
source

Cratylus's answer is inadequate if you do not want to register SOAP attachments.

Here you can write only the envelope:

 // Get the Envelope Source Source src = message.getSOAPPart().getContent() ; // Transform the Source into a StreamResult to get the XML Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "no"); StreamResult result = new StreamResult(new StringWriter()); transformer.transform(src, result); String xmlString = result.getWriter().toString(); 
+1
source

Source: https://habr.com/ru/post/890985/


All Articles