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

Response content is lost if buffer is not of type ByteArrayOutputStream

    XMLWordPrintable

Details

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

    Description

      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
      

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

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

              Dates

                Created:
                Updated:

                Checklists

                  Bug DoR
                  Task DoD