I need all SOAP requests logged in the CommonLogFormat
(see http://en.wikipedia.org/wiki/Common_Log_Format), plus the duration (the amount of time it takes to process the request).
What's the best way to do this? It looks like it's possible to configure log4j for Spring WebServices but will it log all the values I'm interested in? http://pijava.wordpress.com/2009/12/04/spring-webservice-soap-requestresponse-logging-with-log4j/
EDIT: We're actually using SLF4J
, not Log4j
. Also, it looks like it's possible to do this by configuring the PayloadLoggingInterceptor: http://static.springsource.org/spring-ws/site/reference/html/server.html#server-endpoint-interceptor
But I am not sure where the log messages will go. I added that interceptor to our interceptors and I don't see any log messages.
In SOAP web service, each HTTP request or response encapsulates a SOAP envelope, these messages are easy to trace by using Eclipse IDE, build-in “TCP/IP monitor” tool. The idea is host another server in between the client and server to perform port forward function to intercept the HTTP traffic.
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.
Steps to Consume a SOAP service :Create spring boot project and Get the WSDL from the provider . Convert the WSDL to Stub. Understand the request ,response and the types ,operations using any tool like SOAP UI. Form the request object by mapping data and call the soap uri with marshal the java objects as XML.
For Spring Boot project adding below in application.properties
worked for me:
logging.level.org.springframework.web=DEBUG logging.level.org.springframework.ws.client.MessageTracing.sent=DEBUG logging.level.org.springframework.ws.server.MessageTracing.sent=DEBUG logging.level.org.springframework.ws.client.MessageTracing.received=TRACE logging.level.org.springframework.ws.server.MessageTracing.received=TRACE
You can use this to log the raw paylod of incoming and outgoing web service calls.. I'm not sure how to log how long the webservice communication took.
<!-- Spring Web Service Payload Logging--> <logger name="org.springframework.ws.client.MessageTracing"> <level value="TRACE"/> </logger> <logger name="org.springframework.ws.server.MessageTracing"> <level value="TRACE"/> </logger>
Additional details can be found at http://static.springsource.org/spring-ws/site/reference/html/common.html#logging
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