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-4.0/catalina/src/share/org/apache/catalina/servlets InvokerServlet.java
Date Thu, 28 Sep 2000 19:00:37 GMT
craigmcc    00/09/28 12:00:30

  Modified:    catalina/src/share/org/apache/catalina/core
                        StandardWrapper.java
               catalina/src/share/org/apache/catalina/servlets
                        InvokerServlet.java
  Log:
  Clean up the error handling behavior of the invoker servlet (/servlet/*
  mapping) when you do not specify a servlet class or name, or the servlet
  class or name you specify is not found.  Now, all of the following cases
  will return a 404 (not found) error:
  
  	http://localhost:8080/servlet
  	http://localhost:8080/servlet/
  	http://localhost:8080/servlet/nonExistentServlet
  
  instead of the previous 503 error.
  
  A 500 (internal server error) will be returned if the servlet actually
  exists but cannot be initialized (for example, the init() method returns
  an UnavailableException).
  
  PR: BugRat Bug Report #177
  Submitted by:	Anil Amarakoon <anil@awcoldstream.com>
  
  Revision  Changes    Path
  1.9       +6 -5      jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java
  
  Index: StandardWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StandardWrapper.java	2000/09/06 00:11:18	1.8
  +++ StandardWrapper.java	2000/09/28 19:00:18	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v
1.8 2000/09/06 00:11:18 craigmcc Exp $
  - * $Revision: 1.8 $
  - * $Date: 2000/09/06 00:11:18 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v
1.9 2000/09/28 19:00:18 craigmcc Exp $
  + * $Revision: 1.9 $
  + * $Date: 2000/09/28 19:00:18 $
    *
    * ====================================================================
    *
  @@ -101,7 +101,7 @@
    * make them efficient are counter-productive.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.8 $ $Date: 2000/09/06 00:11:18 $
  + * @version $Revision: 1.9 $ $Date: 2000/09/28 19:00:18 $
    */
   
   public final class StandardWrapper
  @@ -370,7 +370,8 @@
        */
       public void setParent(Container container) {
   
  -	if (!(container instanceof Context))
  +        if ((container != null) &&
  +            !(container instanceof Context))
   	    throw new IllegalArgumentException
   		(sm.getString("standardWrapper.notContext"));
   	super.setParent(container);
  
  
  
  1.2       +39 -6     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java
  
  Index: InvokerServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InvokerServlet.java	2000/08/11 23:39:52	1.1
  +++ InvokerServlet.java	2000/09/28 19:00:26	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java,v
1.1 2000/08/11 23:39:52 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 23:39:52 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java,v
1.2 2000/09/28 19:00:26 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/09/28 19:00:26 $
    *
    * ====================================================================
    *
  @@ -67,6 +67,7 @@
   
   import java.io.IOException;
   import javax.servlet.RequestDispatcher;
  +import javax.servlet.Servlet;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
  @@ -83,7 +84,7 @@
    * in the web application deployment descriptor.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 23:39:52 $
  + * @version $Revision: 1.2 $ $Date: 2000/09/28 19:00:26 $
    */
   
   public final class InvokerServlet
  @@ -224,7 +225,7 @@
   	if (pathInfo == null) {
   	    if (debug >= 1)
   	        log("serveRequest:  Invalid pathInfo '" + pathInfo + "'");
  -	    response.sendError(HttpServletResponse.SC_BAD_REQUEST,
  +	    response.sendError(HttpServletResponse.SC_NOT_FOUND,
   	                       request.getRequestURI());
   	    return;
           }
  @@ -253,9 +254,12 @@
   
   	// No, create a new wrapper for the specified servlet class
           else {
  +
   	    if (debug >= 1)
   		log("serveRequest:  Creating wrapper for '" + servletClass +
   		    "' with mapping '" + pattern + "'");
  +
  +            // Create and install a new wrapper
   	    try {
   	        wrapper = context.createWrapper();
   		wrapper.setName(name);
  @@ -264,11 +268,40 @@
   		context.addChild(wrapper);
   		context.addServletMapping(pattern, name);
               } catch (Throwable t) {
  -		log("serveRequest", t);
  +		log("serveRequest.create", t);
   		response.sendError(HttpServletResponse.SC_NOT_FOUND,
   				   request.getRequestURI());
   		return;
               }
  +
  +            // Ensure that we can actually allocate and release an instance
  +            try {
  +                Servlet instance = wrapper.allocate();
  +                wrapper.deallocate(instance);
  +            } catch (ServletException e) {
  +                log("serveRequest.test", e);
  +                Throwable rootCause = e.getRootCause();
  +                if ((rootCause != null) &&
  +                    (rootCause instanceof ClassNotFoundException))
  +                    response.sendError(HttpServletResponse.SC_NOT_FOUND,
  +                                       request.getRequestURI());
  +                else
  +                    response.sendError
  +                        (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
  +                         request.getRequestURI());
  +                context.removeServletMapping(pattern);
  +                context.removeChild(wrapper);
  +                return;
  +            } catch (Throwable t) {
  +                log("serveRequest.test", t);
  +                response.sendError
  +                    (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
  +                     request.getRequestURI());
  +                context.removeServletMapping(pattern);
  +                context.removeChild(wrapper);
  +                return;
  +            }
  +
   	}
   
   	// Pass this request on to the identified or newly created wrapper
  
  
  

Mime
View raw message