2

How can i log all client side SOAP messages sent (and their responses) via webservice template using the Logback as the logging framework?

The answers i have seen so far, such as the: How can I make Spring WebServices log all SOAP requests?

refer either to commons logging, which i have excluded as dependency:

<exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>

, or endpoint logging.

If i understood correctly, i should provide implementation of interceptor which should be set as webservice template property.

Could someone show me code example how to do that?

Community
  • 1
  • 1
John
  • 5,189
  • 2
  • 38
  • 62

1 Answers1

3

Something like this:

public class LogbackInterceptor implements ClientInterceptor {

    private final Logger logger = LoggerFactory.getLogger(LogbackInterceptor .class);


     public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
           logger.debug("Sent request [" + messageContext.getRequest() + "]");
           return true;
     }

     public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
           logger.debug("Received response [" + messageContext.getResponse() + "] for request [" +
                                messageContext.getRequest() + "]");
           return true;
}

.....
}

However it isn't clear why just don't add jcl-over-slf4j.jar and follow with standard WS loggin option from that SO answer?..

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118