costin      00/12/05 19:59:30

  Modified:    src/facade22/org/apache/tomcat/facade
                        RequestDispatcherImpl.java ServletWrapper.java
               src/share/org/apache/tomcat/context ErrorHandler.java
               src/share/org/apache/tomcat/core Handler.java
  Log:
  Few changes to Larry's commit. Handler needs more work and cleanup,
  probably we'll need to add a "state" there too.
  
  - service() method can throw any Exception, handler is not specific
  to servlets ( internal handlers could throw TomcatException).
  
  - keep the 2 layers separated ( i.e. no dependencies between core
  to facade/servlets)
  
  - log the fact that an exception happens in an exception handler ( except
  IOExceptions ) - it's a serious situation.
  
  Revision  Changes    Path
  1.6       +20 -8     
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/RequestDispatcherImpl.java
  
  Index: RequestDispatcherImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/RequestDispatcherImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RequestDispatcherImpl.java        2000/12/05 14:02:37     1.5
  +++ RequestDispatcherImpl.java        2000/12/06 03:59:29     1.6
  @@ -188,9 +188,8 @@
   
        // CM should have set the wrapper - call it
        Handler wr=realRequest.getHandler();
  -     if( wr!=null )
  -         wr.service(realRequest, realResponse);
  -
  +     if( wr!=null ) 
  +         invoke( wr, realRequest, realResponse);
        // Clean up the request and response as needed
        ;       // No action required
   
  @@ -328,9 +327,9 @@
        // for the realRequest ( since the real request will still have the
        // original handler/wrapper )
        Handler wr=subRequest.getHandler();
  -     if( wr!=null )
  -         wr.service(realRequest, realResponse);
  -
  +     if( wr!=null ) 
  +         invoke( wr, realRequest, realResponse);
  +     
        // After request, we want to restore the include attributes - for
        // chained includes.
        realRequest.setChild( old_child );
  @@ -385,7 +384,7 @@
        if( ! old_included ) realResponse.setIncluded( true );
   
        if( wr!=null)
  -         wr.service( realRequest, realResponse);
  +         invoke( wr, realRequest, realResponse);
   
           // Clean up the request and response as needed
        if( ! old_included ) {
  @@ -423,7 +422,7 @@
        if( ! old_included ) realResponse.setIncluded( true );
   
        if( wr!=null)
  -         wr.service( realRequest, realResponse);
  +         invoke( wr, realRequest, realResponse);
   
        // Clean up the request and response as needed
        ;       // No action required
  @@ -517,4 +516,17 @@
            realRequest.setAttribute( name, value );
       }
   
  +    private void invoke( Handler wr, Request req, Response resp )
  +     throws IOException, ServletException
  +    {
  +     try {
  +         wr.service(req, resp);
  +     } catch( Exception ex ) {
  +         if( ex instanceof ServletException )
  +             throw (ServletException)ex;
  +         if( ex instanceof IOException )
  +             throw (IOException)ex;
  +         throw new ServletException( ex );
  +     }
  +    }
   }
  
  
  
  1.12      +3 -2      
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletWrapper.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ServletWrapper.java       2000/12/05 14:02:37     1.11
  +++ ServletWrapper.java       2000/12/06 03:59:29     1.12
  @@ -399,7 +399,7 @@
        JspHandler
       */
       public void service(Request req, Response res) 
  -     throws IOException, ServletException
  +     throws Exception
       {
        // <servlet><jsp-file> case
        if( path!=null ) {
  @@ -424,7 +424,8 @@
                // otherwise handle error
                contextM.handleError( req, res, getErrorException());
            }
  -         context.log(getServletName() + " unavailable time expired, trying again ");
  +         context.log(getServletName() +
  +                     " unavailable time expired, trying again ");
        }
   
        // we reach here of there is no error or the exception has expired
  
  
  
  1.9       +16 -9     
jakarta-tomcat/src/share/org/apache/tomcat/context/ErrorHandler.java
  
  Index: ErrorHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/ErrorHandler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ErrorHandler.java 2000/12/05 14:02:39     1.8
  +++ ErrorHandler.java 2000/12/06 03:59:29     1.9
  @@ -67,7 +67,6 @@
   import java.net.*;
   import java.util.*;
   import java.security.*;
  -import javax.servlet.*;
   
   
   import org.apache.tomcat.util.log.*;
  @@ -183,10 +182,14 @@
        try {
            errorServlet.service( req, res );
        } catch( IOException e ) {
  -         ;   // ASSERT: Only thrown by included servlets
  -     } catch( ServletException e) {
  -         ;   // ASSERT: Only thrown by included servlets
  -     }
  +         // ASSERT: Only thrown by included servlets
  +         // we can ignore it and it's very common - probably the user
  +         // has clicked "STOP"
  +     } catch( Exception e ) {
  +         // we need to log any other error - something may be
  +         // broken if the error servlet has errors.
  +         ctx.log( "Error in errorServlet", e);
  +     } 
       }
   
       // XXX XXX Security - we should log the message, but nothing
  @@ -280,10 +283,14 @@
        try {
            errorServlet.service( req, res );
        } catch( IOException e ) {
  -         ;   // ASSERT: Only thrown by included servlets
  -     } catch( ServletException e) {
  -         ;   // ASSERT: Only thrown by included servlets
  -     }
  +         // ASSERT: Only thrown by included servlets
  +         // we can ignore it and it's very common - probably the user
  +         // has clicked "STOP"
  +     } catch( Exception e ) {
  +         // we need to log any other error - something may be
  +         // broken if the error servlet has errors.
  +         ctx.log( "Error in errorServlet", e);
  +     } 
       }
   
       public final Handler getHandlerForPath( ContextManager cm,
  
  
  
  1.23      +18 -8     jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java
  
  Index: Handler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Handler.java      2000/12/05 14:02:40     1.22
  +++ Handler.java      2000/12/06 03:59:30     1.23
  @@ -62,7 +62,6 @@
   import java.io.*;
   import java.net.*;
   import java.util.*;
  -import javax.servlet.*;
   
   /**
    * The class that will generate the actual response.
  @@ -329,17 +328,28 @@
        }
       }
   
  +    // XXX XXX XXX
  +    // Must be changed - it's very confusing since it has the same name
  +    // with the servlet's service() method.
  +    // The Handler is at a different ( lower ) level, we should
  +    // use different names ( invoke() ? )
  +
       /** Call the service method, and notify all listeners
        *
  -     * @exception IOException if an input/output error occurs and we are
  -     *  processing an included servlet (otherwise it is swallowed and
  -     *  handled by the top level error handler mechanism)
  -     * @exception ServletException if a servlet throws an exception and
  +     * @exception Exception if an error happens during handling of
  +     *   the request. Common errors are:
  +     *   <ul><li>IOException if an input/output error occurs and we are
  +     *   processing an included servlet (otherwise it is swallowed and
  +     *   handled by the top level error handler mechanism)
  +     *       <li>ServletException if a servlet throws an exception and
        *  we are processing an included servlet (otherwise it is swallowed
        *  and handled by the top level error handler mechanism)
  +     *  </ul>
  +     *  Tomcat should be able to handle and log any other exception ( including
  +     *  runtime exceptions )
        */
  -    public void service(Request req, Response res)
  -     throws IOException, ServletException
  +    public /*final*/ void service(Request req, Response res)
  +     throws Exception
       {
        if( ! initialized ) {
            Exception ex=null;
  @@ -371,7 +381,7 @@
                return;
            }
        }
  -
  +     
        if( ! internal ) {
            BaseInterceptor reqI[]=
                req.getContainer().getInterceptors(Container.H_preService);
  
  
  

Reply via email to