Uploaded image for project: 'Cache Modules'
  1. Cache Modules
  2. MGNLCACHE-191

Response content is lost if buffer is not of type ByteArrayOutputStream

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Neutral Neutral
    • None
    • 5.6
    • cache core
    • None
    • Yes

      CacheResponseWrapper#getBufferedContent tries to cast a generic OutputStream into a ByteArrayOutputStream in order to extract already written content. Otherwise it simply returns an empty array (instead of already buffered content).

      This is particularly relevant for cases where response content exceeds the given size threshold. The output buffer gets replaced by a different one (see CacheResponseWrapper.ThresholdingCacheOutputStream#thresholdReached).

      Test code to reproduce

      final byte[] payload = "Foo bar baz".getBytes();
      
      final HttpServletResponse originalResponse = mock(HttpServletResponse.class);
      when(originalResponse.getOutputStream()).thenReturn(new SimpleServletOutputStream(new ByteArrayOutputStream()));
      final HttpServletResponse target = mock(HttpServletResponse.class);
      final ByteArrayOutputStream targetStream = new ByteArrayOutputStream();
      when(target.getOutputStream()).thenReturn(new SimpleServletOutputStream(targetStream));
      
      final CacheResponseWrapper serveWrapper = new CacheResponseWrapper(originalResponse, payload.length - 1, true);
      
      serveWrapper.getOutputStream().write(payload);
      serveWrapper.replayContent(target, true);
      assertThat(targetStream.toByteArray(), is(payload)); // fails
      

        Acceptance criteria

              Unassigned Unassigned
              creichenbach Cedric Reichenbach
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:

                  Bug DoR
                  Task DoD