You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pa...@apache.org on 2002/08/15 21:11:32 UTC

cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves ErrorDispatcherValve.java

patrickl    2002/08/15 12:11:31

  Modified:    catalina/src/share/org/apache/catalina/valves
                        ErrorDispatcherValve.java
  Log:
  If a Servlet generates a RuntimeException, it is wrapped by a ServletException.  Since there is an entry for ServletException in the web.xml, the actual root cause (in this case, an IllegalStateException) was never unwrapped, thus leading to unexpected behavior.
  
  I made a simple modification to the logic so that if the throwable passed to the ErrorDispatcherValve is a ServletException, it will attempt to get the root cause.  If the root cause is null, then proceed with the error page lookup with the ServletException as the throwable object, otherwise, use the root cause for the error page lookup.
  Submitted by:	Ryan Lubke (ryan.lubke@sun.com)
  
  Revision  Changes    Path
  1.2       +14 -14    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/ErrorDispatcherValve.java
  
  Index: ErrorDispatcherValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/ErrorDispatcherValve.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ErrorDispatcherValve.java	18 Jul 2002 16:47:42 -0000	1.1
  +++ ErrorDispatcherValve.java	15 Aug 2002 19:11:31 -0000	1.2
  @@ -212,20 +212,20 @@
        */
       protected void throwable(Request request, Response response,
                                Throwable throwable) {
  -
           Context context = request.getContext();
           if (context == null)
               return;
  -
  +        
           Throwable realError = throwable;
  -        ErrorPage errorPage = findErrorPage(context, realError);
  -        if ((errorPage == null) && (realError instanceof ServletException)) {
  +        
  +        if (realError instanceof ServletException) {
               realError = ((ServletException) realError).getRootCause();
  -            if (realError != null)
  -                errorPage = findErrorPage(context, realError);
  -            else
  +            if (realError == null) {
                   realError = throwable;
  -        }
  +            }
  +        } 
  +            
  +        ErrorPage errorPage = findErrorPage(context, realError);
   
           if (errorPage != null) {
               response.setAppCommitted(false);
  @@ -237,7 +237,7 @@
               sreq.setAttribute(Globals.ERROR_MESSAGE_ATTR,
                                 throwable.getMessage());
               sreq.setAttribute(Globals.EXCEPTION_ATTR,
  -                              throwable);
  +                              realError);
               Wrapper wrapper = request.getWrapper();
               if (wrapper != null)
                   sreq.setAttribute(Globals.SERVLET_NAME_ATTR,
  @@ -246,7 +246,7 @@
                   sreq.setAttribute(Globals.EXCEPTION_PAGE_ATTR,
                                     ((HttpServletRequest) sreq).getRequestURI());
               sreq.setAttribute(Globals.EXCEPTION_TYPE_ATTR,
  -                              throwable.getClass());
  +                              realError.getClass());
               if (custom(request, response, errorPage)) {
                   try {
                       sresp.flushBuffer();
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves ErrorDispatcherValve.java

Posted by Remy Maucherat <re...@apache.org>.
patrickl@apache.org wrote:
> patrickl    2002/08/15 12:11:31
> 
>   Modified:    catalina/src/share/org/apache/catalina/valves
>                         ErrorDispatcherValve.java
>   Log:
>   If a Servlet generates a RuntimeException, it is wrapped by a ServletException.  Since there is an entry for ServletException in the web.xml, the actual root cause (in this case, an IllegalStateException) was never unwrapped, thus leading to unexpected behavior.
>   
>   I made a simple modification to the logic so that if the throwable passed to the ErrorDispatcherValve is a ServletException, it will attempt to get the root cause.  If the root cause is null, then proceed with the error page lookup with the ServletException as the throwable object, otherwise, use the root cause for the error page lookup.
>   Submitted by:	Ryan Lubke (ryan.lubke@sun.com)

I lacked some time, and couldn't commit it.
Can you also commit it to Tomcat 4.1.x (as this appears to be fixing 
things) ?

Thanks,
Remy


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>