@Override public void setStatus(int status) { if (!this.isCommitted()) { this.status = status; } }
@Override @Deprecated public void setStatus(int status, String errorMessage) { if (!this.isCommitted()) { this.status = status; this.errorMessage = errorMessage; } }
@Override public void resetBuffer() { Assert.state(!isCommitted(), "Cannot reset buffer - response is already committed"); this.content.reset(); }
@Override public void sendError(int status, String errorMessage) throws IOException { Assert.state(!isCommitted(), "Cannot set error status - response is already committed"); this.status = status; this.errorMessage = errorMessage; setCommitted(true); }
@Override public void sendError(int status) throws IOException { Assert.state(!isCommitted(), "Cannot set error status - response is already committed"); this.status = status; setCommitted(true); }
@Override public void sendRedirect(String url) throws IOException { Assert.state(!isCommitted(), "Cannot send redirect - response is already committed"); Assert.notNull(url, "Redirect URL must not be null"); setHeader(HttpHeaders.LOCATION, url); setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); setCommitted(true); }
@Test public void servletOutputStreamCommittedOnOutputStreamFlush() throws IOException { assertFalse(response.isCommitted()); response.getOutputStream().write('X'); assertFalse(response.isCommitted()); response.getOutputStream().flush(); assertTrue(response.isCommitted()); assertEquals(1, response.getContentAsByteArray().length); }
@Test // SPR-16683 public void servletWriterCommittedOnWriterClose() throws IOException { assertFalse(response.isCommitted()); response.getWriter().write("X"); assertFalse(response.isCommitted()); response.getWriter().close(); assertTrue(response.isCommitted()); assertEquals(1, response.getContentAsByteArray().length); }
@Test public void servletWriterCommittedOnWriterFlush() throws IOException { assertFalse(response.isCommitted()); response.getWriter().write("X"); assertFalse(response.isCommitted()); response.getWriter().flush(); assertTrue(response.isCommitted()); assertEquals(1, response.getContentAsByteArray().length); }
@Test public void servletWriterCommittedWhenBufferSizeExceeded() throws IOException { assertFalse(response.isCommitted()); response.getWriter().write("X"); assertFalse(response.isCommitted()); int size = response.getBufferSize(); char[] data = new char[size]; Arrays.fill(data, 'p'); response.getWriter().write(data); assertTrue(response.isCommitted()); assertEquals(size + 1, response.getContentAsByteArray().length); }
@Test public void servletOutputStreamCommittedOnFlushBuffer() throws IOException { assertFalse(response.isCommitted()); response.getOutputStream().write('X'); assertFalse(response.isCommitted()); response.flushBuffer(); assertTrue(response.isCommitted()); assertEquals(1, response.getContentAsByteArray().length); }
@Test public void servletOutputStreamCommittedWhenBufferSizeExceeded() throws IOException { assertFalse(response.isCommitted()); response.getOutputStream().write('X'); assertFalse(response.isCommitted()); int size = response.getBufferSize(); response.getOutputStream().write(new byte[size]); assertTrue(response.isCommitted()); assertEquals(size + 1, response.getContentAsByteArray().length); }
@Test public void sendRedirect() throws IOException { String redirectUrl = "/redirect"; response.sendRedirect(redirectUrl); assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus()); assertEquals(redirectUrl, response.getHeader("Location")); assertEquals(redirectUrl, response.getRedirectedUrl()); assertTrue(response.isCommitted()); }
@Test public void testHandleWhenNotLoggedIn() throws Exception { AccessDeniedException ex = new AccessDeniedException("something"); handler.handle(request, response, ex); assertEquals(HttpServletResponse.SC_FOUND, response.getStatus()); assertSame(request.getAttribute(WebAttributes.ACCESS_DENIED_403), ex); assertTrue(response.isCommitted()); assertEquals("http://localhost/login", response.getHeader("Location")); assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus()); }
@Test public void testHandleWhenNotLoggedInAndNoCsrf() throws Exception { AccessDeniedException ex = new MissingCsrfTokenException("something"); handler.handle(request, response, ex); assertEquals(HttpServletResponse.SC_FOUND, response.getStatus()); assertSame(request.getAttribute(WebAttributes.ACCESS_DENIED_403), ex); assertTrue(response.isCommitted()); assertEquals("http://localhost/login", response.getHeader("Location")); assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus()); }
@Override public void setStatus(int status) { if (!this.isCommitted()) { this.status = status; } }
@Override public void setStatus(int status) { if (!this.isCommitted()) { this.status = status; } }
@Override public void resetBuffer() { Assert.state(!isCommitted(), "Cannot reset buffer - response is already committed"); this.content.reset(); }
@Override public void sendError(int status) throws IOException { if (isCommitted()) { throw new IllegalStateException("Cannot set error status - response is already committed"); } this.status = status; setCommitted(true); }
@Override public void sendError(int status) throws IOException { Assert.state(!isCommitted(), "Cannot set error status - response is already committed"); this.status = status; setCommitted(true); }