title: ContentCachingResponseWrapper Produces Empty Response
body: <p>I'm trying to implement filter for logging requests and responses in <code>Spring MVC</code> application.
  I use the following code:</p>
  
  <pre><code>@Component
  public class LoggingFilter extends OncePerRequestFilter {
  
      private static final Logger LOGGER = LoggerFactory.getLogger(LoggingFilter.class);
  
      @Override
      protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
  
          ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);
          ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
  
          LOGGER.debug(REQUEST_MESSAGE_FORMAT, requestWrapper.getRequestURI(), requestWrapper.getMethod(), requestWrapper.getContentType(),
                  new ServletServerHttpRequest(requestWrapper).getHeaders(), IOUtils.toString(requestWrapper.getInputStream(), UTF_8));
  
          filterChain.doFilter(requestWrapper, responseWrapper);
  
          LOGGER.debug(RESPONSE_MESSAGE_FORMAT, responseWrapper.getStatus(), responseWrapper.getContentType(),
                  new ServletServerHttpResponse(responseWrapper).getHeaders(), IOUtils.toString(responseWrapper.getContentInputStream(), UTF_8));
      }
  }
  </code></pre>
  
  <p>So, I get my request and respone logged as expected. Here are the logs:</p>
  
  <pre><code>2016-10-08 19:10:11.212 DEBUG 11072 --- [qtp108982313-19] by.kolodyuk.logging.LoggingFilter
  ----------------------------
  ID: 1
  URI: /resources/1
  Http-Method: GET
  Content-Type: null
  Headers: {User-Agent=[curl/7.41.0], Accept=[*/*], Host=[localhost:9015]}
  Body: 
  --------------------------------------
  2016-10-08 19:10:11.277 DEBUG 11072 --- [qtp108982313-19] by.kolodyuk.logging.LoggingFilter
  ----------------------------
  ID: 1
  Response-Code: 200
  Content-Type: application/json;charset=UTF-8
  Headers: {}
  Body: {"id":"1"}
  --------------------------------------
  </code></pre>
  
  <p>However, the empty response is returned. Here's the output from <code>curl</code>:</p>
  
  <pre><code>$ curl http://localhost:9015/resources/1 --verbose
  *   Trying ::1...
  * Connected to localhost (::1) port 9015 (#0)
  &gt; GET /resources/1 HTTP/1.1
  &gt; User-Agent: curl/7.41.0
  &gt; Host: localhost:9015
  &gt; Accept: */*
  &gt;
  &lt; HTTP/1.1 200 OK
  &lt; Date: Sat, 08 Oct 2016 17:10:11 GMT
  &lt; Content-Type: application/json;charset=UTF-8
  &lt; Content-Length: 0
  &lt;
  * Connection #0 to host localhost left intact
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>