Author: markt Date: Mon Dec 3 14:19:39 2012 New Revision: 1416535 URL: http://svn.apache.org/viewvc?rev=1416535&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54220 The ErrorReportValve should only generate an error response if the error flag on the response is true.
Modified: tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java tomcat/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java Modified: tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java?rev=1416535&r1=1416534&r2=1416535&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java (original) +++ tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java Mon Dec 3 14:19:39 2012 @@ -136,7 +136,8 @@ public class ErrorReportValve extends Va // Do nothing on a 1xx, 2xx and 3xx status // Do nothing if anything has been written already - if ((statusCode < 400) || (response.getContentWritten() > 0)) { + if (statusCode < 400 || response.getContentWritten() > 0 || + !response.isError()) { return; } Modified: tomcat/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java?rev=1416535&r1=1416534&r2=1416535&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java (original) +++ tomcat/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java Mon Dec 3 14:19:39 2012 @@ -66,4 +66,67 @@ public class TestErrorReportValve extend resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } + + + @Test + public void testBug54220DoNotSetNotFound() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + // Must have a real docBase - just use temp + Context ctx = + tomcat.addContext("", System.getProperty("java.io.tmpdir")); + + Tomcat.addServlet(ctx, "bug54220", new Bug54220Servlet(false)); + ctx.addServletMapping("/", "bug54220"); + + tomcat.start(); + + ByteChunk res = new ByteChunk(); + int rc = getUrl("http://localhost:" + getPort(), res, null); + + Assert.assertNull(res.toString()); + Assert.assertEquals(HttpServletResponse.SC_OK, rc); + } + + + @Test + public void testBug54220SetNotFound() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + // Must have a real docBase - just use temp + Context ctx = + tomcat.addContext("", System.getProperty("java.io.tmpdir")); + + Tomcat.addServlet(ctx, "bug54220", new Bug54220Servlet(true)); + ctx.addServletMapping("/", "bug54220"); + + tomcat.start(); + + ByteChunk res = new ByteChunk(); + int rc = getUrl("http://localhost:" + getPort(), res, null); + + Assert.assertNull(res.toString()); + Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); + } + + + private static final class Bug54220Servlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private boolean setNotFound; + + private Bug54220Servlet(boolean setNotFound) { + this.setNotFound = setNotFound; + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + if (setNotFound) { + resp.setStatus(HttpServletResponse.SC_NOT_FOUND); + } + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org