Logging JAX-WS SOAP messages in Spring

Whenever you’re using JAX-WS within Spring you’ll probably want to log the incoming and outgoing SOAP messages – if only for debugging during development. So the first thing to do is increase the log levels, right? Unfortunately this will have no effect. What you will have to do is to make use of the javax.xml.ws.handler.HandlerResolver interface. So how do we do this?

First of all, you’ll want to create a class that implements the HandlerResolver interface. This is a very basic class that will be used to get control over the handler chain. It could look something like the following:

We then have to implement the class that will do the actual logging. This class will have to implement the SOAPHandler<SOAPMessageContext> interface. A very simple implementation that only logs the message using SLF4J:

Finally, we’ll have to wire things together in Spring. Using xml configuration, all you have to do is add a new bean definition:

And that’s all there is to it. Your application should now log all JAX-WS SOAP messages.

One Reply to “Logging JAX-WS SOAP messages in Spring”

Comments are closed.