tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/startup Tomcat.java
Date Tue, 22 Feb 2000 22:53:26 GMT
costin      00/02/22 14:53:26

  Modified:    src/share/org/apache/tomcat/context DefaultCMSetter.java
               src/share/org/apache/tomcat/core ContextManager.java
                        ServletWrapper.java
               src/share/org/apache/tomcat/startup Tomcat.java
  Log:
  - Error checking - don't start in a wrong directory
  
  - ErrorServlet - if the default error can't be found, remove the context
  and report the problem.
  
  - ContextManager.init() - if contextInit() throws TomcatException, remove
  the context and report the error.
  
  - ErrorServlet - detect loops in default error servlet, if an error happens
  inside error servlet.
  
  Revision  Changes    Path
  1.17      +23 -1     jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java
  
  Index: DefaultCMSetter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DefaultCMSetter.java	2000/02/17 07:52:18	1.16
  +++ DefaultCMSetter.java	2000/02/22 22:53:22	1.17
  @@ -80,7 +80,15 @@
   
       public DefaultCMSetter() {
       }
  -	
  +
  +    public void engineInit(ContextManager cm) throws TomcatException {
  +	// check if we are in the right directory
  +	File f=new File( cm.getHome() + "/conf/web.xml");
  +	if( ! f.exists() ) {
  +	    throw new TomcatException( "Wrong home " + cm.getHome());
  +	}
  +    }
  +    
       /** Called when a new context is added to the server.
        *
        *  - Check it and set defaults for WorkDir, EngineHeader and SessionManager.
  @@ -127,6 +135,20 @@
   	initURLs( ctx );
       }
   
  +    public void contextInit( Context ctx)
  +	throws TomcatException
  +    {
  +	// Validation for error  servlet
  +	try {
  +	    ServletWrapper errorWrapper=ctx.getServletByName( "tomcat.errorPage");
  +	    errorWrapper.loadServlet();
  +	} catch( Exception ex ) {
  +	    System.out.println("Error loading default servlet ");
  +	    // XXX remove this context from CM
  +	    throw new TomcatException( "Error loading default error servlet ", ex );
  +	}
  +    }
  +    
       private void initURLs(Context context) {
   	ServletLoader loader=context.getServletLoader();
   	if( loader==null) return;
  
  
  
  1.53      +17 -7     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.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- ContextManager.java	2000/02/22 21:44:28	1.52
  +++ ContextManager.java	2000/02/22 22:53:23	1.53
  @@ -193,9 +193,19 @@
   	
       	// init contexts
   	Enumeration enum = getContextNames();
  +	Context context=null;
   	while (enum.hasMoreElements()) {
  -            Context context = getContext((String)enum.nextElement());
  -            initContext( context );
  +	    context = getContext((String)enum.nextElement());
  +	    try {
  +		initContext( context );
  +	    } catch (TomcatException ex ) {
  +		if( context!=null ) {
  +		    log( "ERROR initializing " + context.toString() );
  +		    removeContext( context.getPath() );	    
  +		    Throwable ex1=ex.getRootCause();
  +		    if( ex1!=null ) ex.printStackTrace();
  +		}
  +	    }
   	}
   	//	log("Time to initialize: "+ (System.currentTimeMillis()-time), Logger.INFORMATION);
       }
  @@ -299,11 +309,8 @@
        * @param name Name of the Context to be removed
        */
       public void removeContext(String name) throws TomcatException {
  -	if (name.equals("")){
  -	    throw new IllegalArgumentException(name);
  -	}
  -
   	Context context = (Context)contexts.get(name);
  +	log( "<l:removeContext path=\"" + context.getPath() + "\" />");
   
   	ContextInterceptor cI[]=getContextInterceptors();
   	for( int i=0; i< cI.length; i++ ) {
  @@ -627,8 +634,11 @@
   
   
   	// No error page or "Exception in exception handler", call internal servlet
  -	if( path==null && errorServlet==null)
  +	if( path==null && errorServlet==null) {
  +	    // this is the default handler -  avoid loops
  +	    req.setAttribute( "tomcat.servlet.error.defaultHandler", "true");
   	    errorServlet=ctx.getServletByName("tomcat.errorPage");
  +	}
   
   	// Try a normal "error page"
   	if( errorServlet==null && path != null ) {
  
  
  
  1.32      +10 -4     jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- ServletWrapper.java	2000/02/22 21:06:38	1.31
  +++ ServletWrapper.java	2000/02/22 22:53:23	1.32
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
1.31 2000/02/22 21:06:38 costin Exp $
  - * $Revision: 1.31 $
  - * $Date: 2000/02/22 21:06:38 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
1.32 2000/02/22 22:53:23 costin Exp $
  + * $Revision: 1.32 $
  + * $Date: 2000/02/22 22:53:23 $
    *
    * ====================================================================
    *
  @@ -401,7 +401,13 @@
   	    // 	    }
   	    // 	}
   	} catch( Throwable t ) {
  -	    contextM.handleError( req, res, t, 0 );
  +	    if( null!=req.getAttribute("tomcat.servlet.error.defaultHandler") ) {
  +		// we are in handleRequest for the "default
  +		System.out.println("ERROR: can't find default error handler or error in default error
page");
  +		t.printStackTrace();
  +	    } else {
  +		contextM.handleError( req, res, t, 0 );
  +	    }
   	}
       }
   
  
  
  
  1.12      +1 -0      jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java
  
  Index: Tomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Tomcat.java	2000/02/22 21:44:29	1.11
  +++ Tomcat.java	2000/02/22 22:53:25	1.12
  @@ -117,6 +117,7 @@
   	    Tomcat tomcat=new Tomcat();
   	    tomcat.execute( args );
   	} catch(Exception ex ) {
  +	    System.out.println("FATAL: " + ex );
   	    ex.printStackTrace();
   	}
   
  
  
  

Mime
View raw message