You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/02/12 21:08:43 UTC
svn commit: r1445329 - in /tomcat/tc7.0.x/trunk: ./
java/org/apache/catalina/valves/ErrorReportValve.java
java/org/apache/catalina/valves/LocalStrings.properties
test/org/apache/catalina/valves/TestErrorReportValve.java
webapps/docs/changelog.xml
Author: markt
Date: Tue Feb 12 20:08:43 2013
New Revision: 1445329
URL: http://svn.apache.org/r1445329
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/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties
tomcat/tc7.0.x/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1445328
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java?rev=1445329&r1=1445328&r2=1445329&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java Tue Feb 12 20:08:43 2013
@@ -179,7 +179,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);
@@ -187,7 +188,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/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties?rev=1445329&r1=1445328&r2=1445329&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties Tue Feb 12 20:08:43 2013
@@ -42,6 +42,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.syntax=Invalid regular expressions [{0}] provided.
Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java?rev=1445329&r1=1445328&r2=1445329&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/valves/TestErrorReportValve.java Tue Feb 12 20:08:43 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);
+ }
+ }
}
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1445329&r1=1445328&r2=1445329&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Feb 12 20:08:43 2013
@@ -65,6 +65,11 @@
<code>StandardWrapper#isSingleThreadModel()</code> triggers the loading
of a Servlet, the correct class loader is used. (markt)
</fix>
+ <fix>
+ <bug>54536</bug>: Ensure the default error page is displayed if a custom
+ HHTP status code is used when calling
+ <code>HttpServletResponse#sendError(int, String)</code>. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org