HttpResponseWrapper extends HttpServletResponseWrapper implements ResponseWithSessionId { @Override public SaveSessionServletOutputStream getOutputStream() throws IOException { if (writer != null) { throw new IllegalStateException("Only one of getWriter()/getOutputStream() can be called, and writer is already used."); } if (outputStream == null) { outputStream = wrapOutputStream(super.getOutputStream()); } return outputStream; } HttpResponseWrapper(HttpRequestWrapper request, HttpServletResponse response); @Override final void sendError(int sc); @Override final void sendError(int sc, String msg); @Override final void sendRedirect(String location); @Override SaveSessionServletOutputStream getOutputStream(); @Override PrintWriter getWriter(); @Override void addHeader(String name, String value); @Override void setHeader(String name, String value); @Override void setContentLength(int len); @Override void reset(); @Override String encodeURL(String url); @Override void flushBuffer();  }
@Test public void testPropagateOnOutputStreamFlush() throws IOException { ServletOutputStream os = responseWrapper.getOutputStream(); verify(response).getOutputStream(); verify(requestWrapper, never()).propagateSession(); os.flush(); verify(requestWrapper).propagateSession(); }
@Test public void testStreamClose() throws IOException { ServletOutputStream os = responseWrapper.getOutputStream(); os.close(); verify(requestWrapper).propagateSession(); os.close(); verify(requestWrapper).propagateSession(); }
@Test public void testTwiceStream() throws IOException { SaveSessionServletOutputStream stream1 = responseWrapper.getOutputStream(); SaveSessionServletOutputStream stream2 = responseWrapper.getOutputStream(); assertSame(stream1, stream2); }