简体   繁体   中英

How to intercept Spring MVC serialized response?

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

您将需要一个'HttpResponse'对象,并建议您在'afterCompletion'方法中进行操作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM