tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/core ContextManager.java Handler.java ServletWrapper.java
Date Sat, 04 Nov 2000 22:33:59 GMT
craigmcc    00/11/04 14:33:59

  Modified:    src/share/org/apache/tomcat/core Tag: tomcat_32
                        ContextManager.java Handler.java
                        ServletWrapper.java
  Log:
  Fix a spec compliance bug -- Tomcat 3.2 was swallowing exceptions thrown
  by a servlet (or JSP page) called via RequestDispatcher.include(), rather
  than throwing them on to the calling servlet.  (See Servlet 2.2
  Specification, Section 8.5.)
  
  Now, an included servlet throwing an exception will have its exception
  rethrown (wrapped in a new ServletException as a root cause if needed)
  rather than trying to run the normal error handling machinery that deals
  with exceptions thrown by a top-level servlet.
  
  Note:  This fix needs to be evaluated for unintended side effects!
  
  PR: BugRat Bug Report #213
  Submitted by:	Ethan Wallwork <ethan.wallwork@net-linx.com>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.100.2.14 +14 -2     jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
  retrieving revision 1.100.2.13
  retrieving revision 1.100.2.14
  diff -u -r1.100.2.13 -r1.100.2.14
  --- ContextManager.java	2000/11/04 20:28:47	1.100.2.13
  +++ ContextManager.java	2000/11/04 22:33:58	1.100.2.14
  @@ -1042,7 +1042,13 @@
   
   	req.setAttribute("tomcat.servlet.error.request", req);
   
  -	errorServlet.service( req, res );
  +        try {
  +            errorServlet.service( req, res );
  +        } catch( IOException e ) {
  +            ;   // ASSERT: Only thrown by included servlets
  +        } catch( ServletException e ) {
  +            ;   // ASSERT: Only thrown by included servlets
  +        }
       }
   
       // XXX XXX Security - we should log the message, but nothing
  @@ -1120,7 +1126,13 @@
   	req.setAttribute("tomcat.servlet.error.throwable", t);
   	req.setAttribute("tomcat.servlet.error.request", req);
   
  -	errorServlet.service( req, res );
  +        try {
  +            errorServlet.service( req, res );
  +        } catch( IOException e ) {
  +            ;   // ASSERT: Only thrown by included servlets
  +        } catch( ServletException e) {
  +            ;   // ASSERT: Only thrown by included servlets
  +        }
       }
   
       public ServletWrapper getHandlerForPath( Context ctx, String path ) {
  
  
  
  1.7.2.2   +34 -3     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.7.2.1
  retrieving revision 1.7.2.2
  diff -u -r1.7.2.1 -r1.7.2.2
  --- Handler.java	2000/08/27 00:40:04	1.7.2.1
  +++ Handler.java	2000/11/04 22:33:58	1.7.2.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v 1.7.2.1
2000/08/27 00:40:04 larryi Exp $
  - * $Revision: 1.7.2.1 $
  - * $Date: 2000/08/27 00:40:04 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v 1.7.2.2
2000/11/04 22:33:58 craigmcc Exp $
  + * $Revision: 1.7.2.2 $
  + * $Date: 2000/11/04 22:33:58 $
    *
    * ====================================================================
    *
  @@ -235,8 +235,16 @@
       }
   
       /** 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
  +     *  we are processing an included servlet (otherwise it is swallowed
  +     *  and handled by the top level error handler mechanism)
        */
       public void service(Request req, Response res) 
  +        throws IOException, ServletException
       {
   	if( ! initialized ) {
   	    try {
  @@ -250,6 +258,15 @@
   		    return;
   		}
   		context.log("Exception in init  " + ex.getMessage(), ex );
  +                if (res.isIncluded()) {
  +                    if (ex instanceof IOException)
  +                        throw (IOException) ex;
  +                    else if (ex instanceof ServletException)
  +                        throw (ServletException) ex;
  +                    else
  +                        throw new ServletException
  +                            ("Included Servlet Init Exception", ex);
  +                }
   		contextM.handleError( req, res, ex );
   		return;
   	    }
  @@ -270,7 +287,21 @@
   	    contextM.doPostService( req, res );
   
   	if( t==null ) return;
  +
  +        // Rethrow an exception if we are inside an include
  +        if (res.isIncluded()) {
  +            context.log("Rethrowing included exception: " + t);
  +            if (t instanceof IOException)
  +                throw (IOException) t;
  +            else if (t instanceof ServletException)
  +                throw (ServletException) t;
  +            else
  +                throw new ServletException("Included Servlet Exception", t);
  +        }
  +
  +        // Otherwise, handle a top-level error as usual
   	contextM.handleError( req, res, t );
  +
       }
   
   //     protected void handleError( Request req, Response res, Throwable t) {
  
  
  
  1.60.2.3  +23 -9     jakarta-tomcat/src/share/org/apache/tomcat/core/Attic/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Attic/ServletWrapper.java,v
  retrieving revision 1.60.2.2
  retrieving revision 1.60.2.3
  diff -u -r1.60.2.2 -r1.60.2.3
  --- ServletWrapper.java	2000/08/27 00:40:04	1.60.2.2
  +++ ServletWrapper.java	2000/11/04 22:33:58	1.60.2.3
  @@ -327,10 +327,18 @@
       }
   
       /** Override service to hook reloading - it can be done in a clean
  -	interceptor. It also hooks jsp - we should have a separate
  -	JspHandler
  -    */
  -    public void service(Request req, Response res) 
  +     * interceptor. It also hooks jsp - we should have a separate
  +     * JspHandler
  +     *
  +     * @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
  +     *  we are processing an included servlet (otherwise it is swallowed
  +     *  and handled by the top level error handler mechanism)
  +     */
  +    public void service(Request req, Response res)
  +        throws IOException, ServletException
       {
   	try {
   	    handleReload(req);
  @@ -368,11 +376,17 @@
   
   	// called only if unavailable==null or timer expired.
   	// will do an init
  -	super.service( req, res );
  -
  -	// if unavailable set, assume problem in init()
  -	if (unavailable!=null)
  -		handleUnavailable( req, res);
  +        try {
  +            super.service( req, res );
  +        } catch( IOException e ) {
  +            throw e;
  +        } catch( UnavailableException e ) {
  +            // if unavailable set, assume problem in init()
  +            handleUnavailable( req, res );
  +            throw e;
  +        } catch( ServletException e ) {
  +            throw e;
  +        }
       }
   
       protected void doService(Request req, Response res)
  
  
  

Mime
View raw message