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 2007/01/24 03:55:07 UTC

svn commit: r499215 - in /tomcat/container/tc5.5.x/catalina: build.xml src/share/org/apache/catalina/core/StandardWrapper.java src/share/org/apache/catalina/valves/ErrorReportValve.java

Author: markt
Date: Tue Jan 23 18:55:06 2007
New Revision: 499215

URL: http://svn.apache.org/viewvc?view=rev&rev=499215
Log:
Further improvements to the fix for bug 39088
 - Remove dependency on jsp-api using Tim Funk's suggested approach
 - Add the recursion part of the patch I missed previously
 - Handle the case where initCause() has been used rather than the nesting mechanism provided by the well known type

Testing showed that ErrorReportValve was not getting to the root of some of the admittedly crazy sets of nested exceptions I was testing with so this has also been updated to use the same approach as StandardWrapper

Modified:
    tomcat/container/tc5.5.x/catalina/build.xml
    tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java
    tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/valves/ErrorReportValve.java

Modified: tomcat/container/tc5.5.x/catalina/build.xml
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/build.xml?view=diff&rev=499215&r1=499214&r2=499215
==============================================================================
--- tomcat/container/tc5.5.x/catalina/build.xml (original)
+++ tomcat/container/tc5.5.x/catalina/build.xml Tue Jan 23 18:55:06 2007
@@ -30,7 +30,6 @@
   <!-- Dependent JARs and files -->
   <property name="ant.jar" value="${ant.home}/lib/ant.jar"/>
   <property name="servlet-api.jar" value="${api.home}/jsr154/dist/lib/servlet-api.jar"/>
-  <property name="jsp-api.jar" value="${api.home}/jsr152/dist/lib/jsp-api.jar"/>
   <property name="tomcat-util.jar"
            value="${tomcat-util.home}/build/lib/tomcat-util.jar"/>
   <property name="tomcat-coyote.jar"
@@ -73,7 +72,6 @@
     <pathelement location="${mail.jar}"/>
     <pathelement location="${regexp.jar}"/>
     <pathelement location="${servlet-api.jar}"/>
-    <pathelement location="${jsp-api.jar}"/>
     <pathelement location="${xercesImpl.jar}"/>
     <pathelement location="${xml-apis.jar}"/>
     <pathelement location="${classes.dir}"/>
@@ -103,7 +101,6 @@
     <pathelement location="${mail.jar}"/>
     <pathelement location="${regexp.jar}"/>
     <pathelement location="${servlet-api.jar}"/>
-    <pathelement location="${jsp-api.jar}"/>
     <pathelement location="${xercesImpl.jar}"/>
     <pathelement location="${xml-apis.jar}"/>
     <pathelement location="${classes.dir}"/>

Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java?view=diff&rev=499215&r1=499214&r2=499215
==============================================================================
--- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java (original)
+++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java Tue Jan 23 18:55:06 2007
@@ -38,7 +38,6 @@
 import javax.servlet.ServletResponse;
 import javax.servlet.SingleThreadModel;
 import javax.servlet.UnavailableException;
-import javax.servlet.jsp.JspException;
 import javax.management.ListenerNotFoundException;
 import javax.management.MBeanNotificationInfo;
 import javax.management.Notification;
@@ -59,6 +58,7 @@
 import org.apache.catalina.security.SecurityUtil;
 import org.apache.catalina.util.Enumerator;
 import org.apache.catalina.util.InstanceSupport;
+import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.log.SystemLogHandler;
 import org.apache.commons.modeler.Registry;
 
@@ -268,6 +268,19 @@
     private static Class[] classTypeUsedInService = new Class[]{
                                                          ServletRequest.class,
                                                          ServletResponse.class};
+    
+    private static Class jspExceptionClazz;
+    
+    static {
+        try {
+            jspExceptionClazz = Class.forName("javax.servlet.jsp.JspException");
+        } catch (ClassNotFoundException e) {
+            // Expected if jsp-api not on classpath, eg when embedding
+            jspExceptionClazz = null;
+        }
+    }
+        
+
     // ------------------------------------------------------------- Properties
 
 
@@ -638,6 +651,7 @@
         return findRootCause(e, rootCause);
     }
 
+
     /*
      * Work through the root causes using specific methods for well known types
      * and getCause() for the rest. Stop when the next rootCause is null or
@@ -649,18 +663,23 @@
         Throwable deeperRootCause = null;
 
         if (theRootCause == null || theRootCause == theException) {
-            deeperRootCause = theException;
-        } else if (theRootCause instanceof ServletException) {
+            return theException;
+        }
+        
+        if (theRootCause instanceof ServletException) {
             deeperRootCause = ((ServletException) theRootCause).getRootCause();
-        } else if (theRootCause instanceof JspException) {
-            deeperRootCause = ((JspException) theRootCause).getRootCause();
+        } else if (jspExceptionClazz!=null &&
+                jspExceptionClazz.isAssignableFrom(theRootCause.getClass())) {
+            deeperRootCause = (Throwable)IntrospectionUtils.getProperty(
+                    theRootCause, "rootCause"); 
         } else if (theRootCause instanceof SQLException) {
             deeperRootCause = ((SQLException) theRootCause).getNextException();
-        } else {
+        }
+        if (deeperRootCause == null) {
             deeperRootCause = theRootCause.getCause();
         }
         
-        return deeperRootCause;
+        return findRootCause(theRootCause, deeperRootCause);
     }
 
 

Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/valves/ErrorReportValve.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/valves/ErrorReportValve.java?view=diff&rev=499215&r1=499214&r2=499215
==============================================================================
--- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/valves/ErrorReportValve.java (original)
+++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/valves/ErrorReportValve.java Tue Jan 23 18:55:06 2007
@@ -21,6 +21,7 @@
 
 import java.io.IOException;
 import java.io.Writer;
+import java.sql.SQLException;
 
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
@@ -72,6 +73,16 @@
     protected static StringManager sm =
         StringManager.getManager(Constants.Package);
 
+    private static Class jspExceptionClazz;
+    
+    static {
+        try {
+            jspExceptionClazz = Class.forName("javax.servlet.jsp.JspException");
+        } catch (ClassNotFoundException e) {
+            // Expected if jsp-api not on classpath, eg when embedding
+            jspExceptionClazz = null;
+        }
+    }
 
     // ------------------------------------------------------------- Properties
 
@@ -240,8 +251,22 @@
                 sb.append("</pre></p>");
                 // In case root cause is somehow heavily nested
                 try {
-                    nestedRootCause = (Throwable)IntrospectionUtils.getProperty
-                                                (rootCause, "rootCause");
+                    if (rootCause instanceof ServletException) {
+                        nestedRootCause =
+                            ((ServletException) rootCause).getRootCause();
+                    } else if (jspExceptionClazz!=null &&
+                            jspExceptionClazz.isAssignableFrom(
+                                    rootCause.getClass())) {
+                        nestedRootCause = (Throwable)IntrospectionUtils.
+                                getProperty(rootCause, "rootCause"); 
+                    } else if (rootCause instanceof SQLException) {
+                        nestedRootCause = ((SQLException) rootCause).
+                                getNextException();
+                    }
+                    if (nestedRootCause == null) {
+                        nestedRootCause = rootCause.getCause();
+                    }
+
                     if (rootCause == nestedRootCause)
                         rootCause = null;
                     else



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org