Spring: Response time

坚强是说给别人听的谎言 提交于 2019-12-23 04:58:06

问题


I have a SOAP webservice(spring ws)and need to save the response time of every request that I receive. I could create a servlet filter that measures time difference between HTTP Request and HTTP Response. But, I need to log the response time together with some values that I read from soap request envelope, and since at that time request is raw and needs to be unmarshalled, that's an expensive and redundant operation to unmarshall for every request.

So is there a way to calculate it using SpringWS? like in a payloadInterceptor?


回答1:


Yes, implementing an EndpointInterceptor is the best fit for this task, as it gives you access to the SOAP messages through the MessageContext. See the Reference Documenation.




回答2:


I think you can use two tools.

  1. AspectJ with its annotation @Before and @AfterReturning. The pointcut could be the method that receives the request (@WebMethod).

    @Before("call([package, class and method that receives the request]")
    public void before(JoinPoint joinPoint) throws Throwable {
        ...
    }
    
    @AfterReturning(pointcut = "call([package, class and method that receives the request])", returning = "result")
    public void after(JoinPoint joinPoint, Object result) throws Throwable {
        ...
    }
    

The JoinPoint object has the information of the method's parameters

  1. Override the method handleMessage of a custom class that implements the SOAPHandler class. This method will be executed every time a SOAP request is received.

I hope this can give you ideas to resolve your problem.



来源:https://stackoverflow.com/questions/30850182/spring-response-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!