From 0d44e6e0d222d77b057390c6b6411594f7779381 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 16 Apr 2014 16:29:08 -0700 Subject: [PATCH] Ensure response is committed after ErrorPageFilter Otherwise Tomcat will go ahead and uncommit it and handle it again in the ErrorReportValve (duh!) Fixes gh-684 --- .../org/springframework/boot/context/web/ErrorPageFilter.java | 2 ++ .../boot/context/web/ErrorPageFilterTests.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java index de1828c8ca..8ce25e3e33 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java @@ -91,6 +91,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { + ErrorWrapperResponse wrapped = new ErrorWrapperResponse(response); try { chain.doFilter(request, wrapped); @@ -102,6 +103,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple catch (Throwable ex) { handleException(request, response, wrapped, ex); } + response.flushBuffer(); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java index a7cdb113a2..a7e389bb91 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java @@ -34,6 +34,7 @@ import org.springframework.mock.web.MockHttpServletResponse; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; /** * Tests for {@link ErrorPageFilter}. @@ -76,6 +77,7 @@ public class ErrorPageFilterTests { equalTo((Object) 400)); assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE), equalTo((Object) "BAD")); + assertTrue(this.response.isCommitted()); } @Test @@ -96,6 +98,7 @@ public class ErrorPageFilterTests { equalTo((Object) 400)); assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE), equalTo((Object) "BAD")); + assertTrue(this.response.isCommitted()); } @Test @@ -118,6 +121,7 @@ public class ErrorPageFilterTests { equalTo((Object) "BAD")); assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE), equalTo((Object) RuntimeException.class.getName())); + assertTrue(this.response.isCommitted()); } @Test