[SWS-803] WebServiceTemple -> add logRequest method analogue to existing logResponse Created: 11/Oct/12  Updated: 03/Dec/12  Resolved: 03/Dec/12

Status: Resolved
Project: Spring Web Services
Component/s: Core
Affects Version/s: 2.1.1
Fix Version/s: 2.1.2

Type: Improvement Priority: Minor
Reporter: Tamás Láng Assignee: Arjen Poutsma
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hi!

I want to log the webservice requests and responses in the application I'm currently working on.
My approach would be to use AOP and watch the methods you use in your code for logging.
I found "logResponse(MessageContext messageContext)throws IOException" method in the WebServiceTemplate, for that I could create a pointcut.

But I would need something for the request logging as well and now the request logging currently located in the method:
sendRequest(WebServiceConnection connection, WebServiceMessage request) throws IOException
which is also good, just It would be good to separate the logging part imho.
So you could add a similar method to logResponse.

Additional question is that I found that there are so called TracingLogger's creatd with logFactory. Maybe instead of thinking in AOP I could use them with defining my own somehow?

What do you think?

THanks!



 Comments   
Comment by Arjen Poutsma [ 03/Dec/12 ]

Instead of using AOP, I think it's a lot easier to just use a org.springframework.ws.client.support.interceptor.ClientInterceptor for logging request and response, and register that with the template. Something like:

public class LoggingClientInterceptor implements ClientInterceptor {
 
    private static final Log logger = LogFactory.getLog(LoggingClientInterceptor.class);
 
    public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
        logger.debug("Request: " + messageContext.getRequest());
        return true;
    }
 
    public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
        logger.debug("Response :" + messageContext.getResponse());
        return true;
    }
 
    public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
        logger.debug("Fault:" + messageContext.getResponse());
        return true;
    }
}

Generated at Mon Dec 11 13:04:05 UTC 2017 using JIRA 6.4.14#64029-sha1:ae256fe0fbb912241490ff1cecfb323ea0905ca5.