You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@apache.org on 2001/04/26 05:09:09 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core StandardWrapperValve.java
craigmcc 01/04/25 20:09:09
Modified: catalina/src/share/org/apache/catalina/core
StandardWrapperValve.java
Log:
[PFD2-9.9.2] - Implement the revised algorithm for looking up the error page
associated with an exception thrown by the top-level servlet (first match
wins):
- Look for an error page with this exact exception class
- Look for an error page for progressive superclasses of the exception class
- If this exception is a ServletException with a rootCause property,
rerun the above two steps on the rootCause exception
- Display the container's standard error page.
NOTE: Currently, four of the ErrorPage tests in tester will fail, because
they assume that the exception forwarded to the error page will be the root
cause exception, rather that the ServletException. I've submitted a request
for clarification to know which behavior is correct, and will change either
the logic or the tests accordingly.
Revision Changes Path
1.24 +44 -18 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java
Index: StandardWrapperValve.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- StandardWrapperValve.java 2001/03/30 19:33:37 1.23
+++ StandardWrapperValve.java 2001/04/26 03:09:07 1.24
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v 1.23 2001/03/30 19:33:37 craigmcc Exp $
- * $Revision: 1.23 $
- * $Date: 2001/03/30 19:33:37 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v 1.24 2001/04/26 03:09:07 craigmcc Exp $
+ * $Revision: 1.24 $
+ * $Date: 2001/04/26 03:09:07 $
*
* ====================================================================
*
@@ -103,7 +103,7 @@
* <code>StandardWrapper</code> container implementation.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.23 $ $Date: 2001/03/30 19:33:37 $
+ * @version $Revision: 1.24 $ $Date: 2001/04/26 03:09:07 $
*/
final class StandardWrapperValve
@@ -499,26 +499,23 @@
Throwable exception) {
// Handle a custom error page for this status code
- Context context = (Context) container.getParent();
- Throwable realError = exception;
- if (exception instanceof ServletException) {
- Throwable rootCause =
- ((ServletException) exception).getRootCause();
- if (rootCause != null)
- realError = rootCause;
- }
if (debug >= 1)
- log("Handling exception: " + realError.toString());
- ErrorPage errorPage =
- context.findErrorPage(realError.getClass().getName());
+ log("Handling exception: " + exception);
+ Context context = (Context) container.getParent();
+ Throwable realError = exception;
+ ErrorPage errorPage = findErrorPage(context, realError);
+ if ((errorPage == null) && (realError instanceof ServletException)) {
+ realError = ((ServletException) exception).getRootCause();
+ errorPage = findErrorPage(context, realError);
+ }
if (errorPage != null) {
// if (debug >= 1)
// log(" Sending to custom error page " + errorPage);
ServletRequest sreq = request.getRequest();
sreq.setAttribute(Globals.ERROR_MESSAGE_ATTR,
- realError.getMessage());
+ exception.getMessage());
sreq.setAttribute(Globals.EXCEPTION_ATTR,
- realError);
+ exception);
Wrapper wrapper = (Wrapper) getContainer();
sreq.setAttribute(Globals.SERVLET_NAME_ATTR,
wrapper.getName());
@@ -526,7 +523,7 @@
sreq.setAttribute(Globals.EXCEPTION_PAGE_ATTR,
((HttpServletRequest) sreq).getRequestURI());
sreq.setAttribute(Globals.EXCEPTION_TYPE_ATTR,
- realError.getClass());
+ exception.getClass());
if (custom(request, response, errorPage))
return;
}
@@ -618,6 +615,35 @@
}
// if (debug >= 1)
// log(" Finished with exception() report");
+
+ }
+
+
+ /**
+ * Find and return the ErrorPage instance for the specified exception's
+ * class, or an ErrorPage instance for the closest superclass for which
+ * there is such a definition. If no associated ErrorPage instance is
+ * found, return <code>null</code>.
+ *
+ * @param context The Context in which to search
+ * @param exception The exception for which to find an ErrorPage
+ */
+ private ErrorPage findErrorPage(Context context, Throwable exception) {
+
+ if (exception == null)
+ return (null);
+ Class clazz = exception.getClass();
+ String name = clazz.getName();
+ while (!"java.lang.Object".equals(clazz)) {
+ ErrorPage errorPage = context.findErrorPage(name);
+ if (errorPage != null)
+ return (errorPage);
+ clazz = clazz.getSuperclass();
+ if (clazz == null)
+ break;
+ name = clazz.getName();
+ }
+ return (null);
}