我有下面的方法来提取响应并将其包装在包装器类中。
使用调试器,我可以看到responseContent
具有应有的全部内容,但是当将其打印到屏幕上时,只有部分请求返回。
我可以看到变量data
具有应有的完整值。
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper((HttpServletResponse) response);
chain.doFilter(request, responseWrapper);
String responseContent = new String(responseWrapper.getContentAsByteArray());
BasicResponse<Object> fullResponse = new BasicResponse<>();
fullResponse.setData(new ObjectMapper().readValue(responseContent, Object.class));
String data = new ObjectMapper().writeValueAsString(fullResponse);
response.getWriter().write(data);//data has the entire value
response.getWriter().close();
}