Spring mvc ContentCachingResponseWrapper:如何使用ContentCachingResponseWrapper获取应用程序响应对象(而不是httpResponse)
在SpringWeb中使用拦截器验证请求。 我已经扩展了HandlerInterceptorAdapter来实现postHandle方法。 我想检查应用程序响应对象中的值,并相应地执行一些操作 我尝试使用IOUtils获取应用程序响应对象,但得到了一个“”字符串Spring mvc ContentCachingResponseWrapper:如何使用ContentCachingResponseWrapper获取应用程序响应对象(而不是httpResponse),spring-mvc,httpresponse,Spring Mvc,Httpresponse,在SpringWeb中使用拦截器验证请求。 我已经扩展了HandlerInterceptorAdapter来实现postHandle方法。 我想检查应用程序响应对象中的值,并相应地执行一些操作 我尝试使用IOUtils获取应用程序响应对象,但得到了一个“”字符串 在阅读了许多文档并亲自动手之后,我发现输入流/输出流只能访问一次。响应对象在到达postHandler之前已经在某处写入了输出流。所以输出流在postHandle的响应对象中为空 若要访问postHandle中的响应对象,请使用实际响应
在阅读了许多文档并亲自动手之后,我发现输入流/输出流只能访问一次。响应对象在到达postHandler之前已经在某处写入了输出流。所以输出流在postHandle的响应对象中为空 若要访问postHandle中的响应对象,请使用实际响应对象设置请求对象的属性
public class XYZInterceptor extends HandlerInterceptorAdapter {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
throws Exception {
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);
// need to retrieve application response object
return;
}
}