Reputation: 11185
I have the below method that extracts the response and wraps it in a wrapper class.
With the debugger, I can see that responseContent
has the full content as it should be, but when it is printed to the screen, only part of the request is returning.
I can see that the variable data
has the entire value as it should have.
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();
}
Upvotes: 3
Views: 65
Reputation: 44970
Most likely the response Content-Length
header is set with value lower than the new data length. Make sure to set this header with new value which matches the new data length.
Upvotes: 1