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
This commit is contained in:
Dave Syer 2014-04-16 16:29:08 -07:00
parent d613cc795e
commit 0d44e6e0d2
2 changed files with 6 additions and 0 deletions

View File

@ -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();
}

View File

@ -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