(Java 6, Spring 3, Spring-WS 2, JAXB2, Tomcat 6)
I have a requirement to log the request and response XML to a database table. I would like to be able to create a record on receipt of the request XML and update the same record when the response XML (or fault) is ready. Is there a way to do this with Spring-WS 2?
I want to wrap the invocation of the endpoint prior to unmarshalling the XML so I can save request XML, invoke the endpoint, and finally save response XML. I would use the unique ID returned from the DB after saving the request XML to identify the record that needs to be updated with the response XML.
All help is much appreciated!
You can use Spring-WS EndpointInterceptors.
Implement an interceptor.
You have to implement the
org.springframework.ws.server.EndpointInterceptorinterface where methods to act on the request and response events are provided.By accessing the MessageContext object, you can retrieve the request and response mesages (getRequest and getResponse methods).
You can also use the setProperty method to store information in the request moment that is accessible in the response to correlate information (e.g., the ID of the record to update in the DB for example).
Configure the interceptor.
The interceptor either can be configured for a specific request or globally for all the web services. I copy some configuration from the documentation: