Author: markt Date: Tue Feb 12 20:06:11 2013 New Revision: 1445328 URL: http://svn.apache.org/r1445328 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54536 If a custom error status is used and a message is provided, display that message via the default error page.
Modified: tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties 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=1445328&r1=1445327&r2=1445328&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java (original) +++ tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java Tue Feb 12 20:06:11 2013 @@ -155,7 +155,8 @@ public class ErrorReportValve extends Va } } - // Do nothing if there is no report for the specified status code + // Do nothing if there is no report for the specified status code and + // no error message provided String report = null; try { report = sm.getString("http." + statusCode); @@ -163,7 +164,11 @@ public class ErrorReportValve extends Va ExceptionUtils.handleThrowable(t); } if (report == null) { - return; + if (message.length() == 0) { + return; + } else { + report = sm.getString("errorReportValve.noDescription"); + } } StringBuilder sb = new StringBuilder(); Modified: tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties?rev=1445328&r1=1445327&r2=1445328&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties Tue Feb 12 20:06:11 2013 @@ -38,6 +38,7 @@ errorReportValve.exception=exception errorReportValve.rootCause=root cause errorReportValve.note=note errorReportValve.rootCauseInLogs=The full stack trace of the root cause is available in the {0} logs. +errorReportValve.noDescription=No description available # Remote IP valve remoteIpValve.invalidPortHeader=Invalid value [{0}] found for port in HTTP header [{1}] 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=1445328&r1=1445327&r2=1445328&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java (original) +++ tomcat/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java Tue Feb 12 20:06:11 2013 @@ -129,4 +129,44 @@ public class TestErrorReportValve extend } } } + + + /** + * Custom error/status codes should not result in a blank response. + */ + @Test + public void testBug54536() 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, "bug54536", new Bug54536Servlet()); + ctx.addServletMapping("/", "bug54536"); + + tomcat.start(); + + ByteChunk res = new ByteChunk(); + int rc = getUrl("http://localhost:" + getPort(), res, null); + + Assert.assertEquals(Bug54536Servlet.ERROR_STATUS, rc); + String body = res.toString(); + Assert.assertNotNull(body); + Assert.assertTrue(body, body.contains(Bug54536Servlet.ERROR_MESSAGE)); + } + + + private static final class Bug54536Servlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + private static final int ERROR_STATUS = 999; + private static final String ERROR_MESSAGE = "The sky is falling"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.sendError(ERROR_STATUS, ERROR_MESSAGE); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org