如何截获Spring MVC序列化响应? [英] How to intercept Spring MVC serialized response?
问题描述
我想在请求结束时截取Spring servlet响应.我的意思是,我想做的是记录服务响应,服务返回的json和statusCode.这就是我要记录的所有内容.
I want to intercept Spring servlet response just at the end of the request. I mean, what i want to do is to log service response, that json which services returns and the statusCode. That is all what i want to log.
为此,我已经尝试使用HandlerInterceptorAdapter这样
For that, i've already tried using HandlerInterceptorAdapter like this
public class ResponseLoggerInterceptor
extends HandlerInterceptorAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(ResponseLoggerInterceptor.class);
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
LOGGER.info("Intercepted");
super.postHandle(request, response, handler, modelAndView);
}
}
该处理程序"对象是对象的居所,但未序列化.您知道我必须在哪里截取最后的servlet响应吗?预先感谢
That "handler" object is the object respose, but it is not serialized. Do you know where and how i have to intercept the very last servlet response? Thanks in advance
推荐答案
您将需要一个'HttpResponse'对象 并建议您使用'afterCompletion'方法
You will need a 'HttpResponse' object And will suggest that you do it in the 'afterCompletion' method
这篇关于如何截获Spring MVC序列化响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!