How to intercept Spring MVC serialized response?

这一生的挚爱 提交于 2020-01-06 19:29:56

问题


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.

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);
    }

}

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


回答1:


You will need a 'HttpResponse' object And will suggest that you do it in the 'afterCompletion' method



来源:https://stackoverflow.com/questions/30491790/how-to-intercept-spring-mvc-serialized-response

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