Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see XML output of SOAP request in Spring?

I am new to Spring SOAP requests. I want to see the final XML output of the SOAP request which includes SOAP header and SOAP envelop.

While debugging I reached up to this piece of code

sendSourceAndReceiveToResult(partnerURI, source,
    new WebServiceMessageCallback() {

        public void doWithMessage(WebServiceMessage message)
        throws IOException, TransformerException {

            StringSource mefHeaderSource = new StringSource(
                header);

            SoapHeader soapHeader = ((SoapMessage) message)
                .getSoapHeader();

            Transformer transformer = TransformerFactory
                .newInstance().newTransformer();

            transformer.transform(mefHeaderSource,
                soapHeader.getResult());

        }
    }, result);

I suspect here I can see somewhere the output XML SOAP request by putting some logger but I am not sure I am correct. I tried searching for it but in all the posts available on google nothing is clear.

The issue which we are debugging is client is not able to see SOAP header in the SOAP request.

like image 583
Nikhil Agrawal Avatar asked Dec 02 '25 20:12

Nikhil Agrawal


1 Answers

Make sure to use Commons Logging version 1.1 or higher.

To log all server-side messages, simply set the org.springframework.ws.server.MessageTracing logger to level DEBUG or TRACE. On the debug level, only the payload root element is logged; on the TRACE level, the entire message content. If you only want to log sent messages, use the org.springframework.ws.server.MessageTracing.sent logger; or org.springframework.ws.server.MessageTracing.received to log received messages.

On the client-side, similar loggers exist: org.springframework.ws.client.MessageTracing.sent and org.springframework.ws.client.MessageTracing.received.

Here is an example log4j.properties configuration, logging the full content of sent messages on the client side, and only the payload root element for client-side received messages. On the server-side, the payload root is logged for both sent and received messages:

log4j.rootCategory=INFO, stdout
log4j.logger.org.springframework.ws.client.MessageTracing.sent=TRACE
log4j.logger.org.springframework.ws.client.MessageTracing.received=DEBUG

log4j.logger.org.springframework.ws.server.MessageTracing=DEBUG

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p [%c{3}] %m%n
like image 158
user Avatar answered Dec 04 '25 10:12

user



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!