问题
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