billbarker    01/10/05 19:31:10

  Modified:    src/share/org/apache/tomcat/modules/generators
                        ErrorHandler.java
               src/share/org/apache/tomcat/modules/mappers
                        SimpleMapper1.java
  Log:
  Impove error handling when the user has choosen not to define a ROOT context.
  
  A better solution is to force the definition of DEFAULT@ROOT, but that creates too 
many problems this close to release.  I'm the first to vote to role this back once 
someInterceptor takes responsibilty for DEFAULT@ROOT.
  
  It is very easy (and, it seems common) to setup Tomcat without a ROOT context. This 
caused Tomcat to generate useless exception reports in the log.  With this patch, you 
get the expected 404 response to an un-mappable request.
  
  This fixes Bug #3988
  Reported by: Alex Polverini [EMAIL PROTECTED]
  Reported by: Hans Schmid [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.20      +20 -0     
jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/ErrorHandler.java
  
  Index: ErrorHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/ErrorHandler.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ErrorHandler.java 2001/09/23 18:17:48     1.19
  +++ ErrorHandler.java 2001/10/06 02:31:10     1.20
  @@ -90,6 +90,26 @@
   
       public void engineInit(ContextManager cm ) {
       }
  +
  +    /** Check that we are in a stable state.
  +     */
  +    public  void engineStart(ContextManager cm )
  +     throws TomcatException
  +    {
  +     /* It is very possible to configure Tomcat without a rootContext.
  +        We make certain here that the rootContext is set.  Note that we
  +        can't add the context, since we don't have a docRoot.  This one is 
  +        only used for error handling.  If somebody subsequently adds a
  +        default context, then this one just harmlessly goes to gc 
  +        (since it's not part of the app, we don't have to follow Life Cycle)
  +     */
  +     if(rootContext == null){
  +         rootContext = cm.createContext();
  +         rootContext.setContextManager(cm);
  +         rootContext.setPath("");
  +         contextInit(rootContext);
  +     }
  +    }
       
       /** Add default error handlers
        */
  
  
  
  1.12      +9 -3      
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SimpleMapper1.java        2001/09/18 06:48:26     1.11
  +++ SimpleMapper1.java        2001/10/06 02:31:10     1.12
  @@ -294,9 +294,15 @@
            Container container =(Container)map.
                getLongestPrefixMatch(  hostMB, pathMB);
            
  -         if( container == null )
  -             throw new RuntimeException( "Assertion failed: " +
  -                                         "container==null");
  +         if( container == null ) {
  +             // It is too easy to configure Tomcat w/o a default context
  +             // Add this back in when we do better checking
  +             //throw new RuntimeException( "Assertion failed: " +
  +             //                          "container==null");
  +             cm.log("Assertion failed: " +
  +                    "container==null (no Default Context?)");
  +             return 404;
  +         }
   
            if(debug>0)
                cm.log("SM: Prefix match " + pathMB.toString() + " -> " +
  
  
  


Reply via email to