You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/10/01 08:37:53 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/task ApacheConfig.java StopTomcat.java

costin      00/09/30 23:37:53

  Modified:    src/facade22/org/apache/tomcat/facade
                        Servlet22Interceptor.java ServletWrapper.java
               src/facade23/org/apache/tomcat/facade23 ServletWrapper.java
               src/share/org/apache/tomcat/context DefaultCMSetter.java
               src/share/org/apache/tomcat/core BaseInterceptor.java
                        Container.java Context.java ContextManager.java
                        Handler.java Request.java Response.java
               src/share/org/apache/tomcat/helper ServerXmlHelper.java
               src/share/org/apache/tomcat/request StaticInterceptor.java
               src/share/org/apache/tomcat/startup EmbededTomcat.java
               src/share/org/apache/tomcat/task ApacheConfig.java
                        StopTomcat.java
  Log:
  Few big changes in ContextManager.
  
  - removed RequestInterceptors and ContextInterceptors. We only have
  Interceptors ( no need to make distinction )
  
  - most of the doHOOK moved next to the caller, no need to
  call context manager to intermediate. That will also help when/if we
  add some mechanism to define dynamic hooks.
  
  - IMPORTANT - documented the order of startup ( at least the way I understand
  it), and make sure no hooks are called until CM is initialized.
  We still need to make sure that
  1. No request is served until CM is in STARTED state
  2. A context will not serve requests until it's in ACTIVE state.
  
  - A lot of cleanup and simplifactions resulting from this ( the state of
  ContextManager should be consistent now). For example we can move more
  functionality in interceptors ( fixing the paths is now done in
  DefaultCMSetter and it's much improved, etc).
  
  So far I thought MessageBytes and OutputBuffer are the most important changes
  for 3.3. Now I think making sure we have a clear definition of state
  for CM and interceptors is much more important. Please help and review
  ( at least the comments at the beginning of ContextManager )
  
  Revision  Changes    Path
  1.4       +0 -18     jakarta-tomcat/src/facade22/org/apache/tomcat/facade/Servlet22Interceptor.java
  
  Index: Servlet22Interceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/Servlet22Interceptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Servlet22Interceptor.java	2000/09/30 04:03:33	1.3
  +++ Servlet22Interceptor.java	2000/10/01 06:37:42	1.4
  @@ -132,24 +132,6 @@
   	    
       }
       
  -    public Object createServletContextFacade(Context ctx) {
  -	//if( ctx != this.ctx ) return null; // throw
  -	return new ServletContextFacade(ctx.getContextManager() , ctx);
  -    }
  -    
  -    
  -    public Object createHttpServletRequestFacade(Request req) {
  -	Context reqCtx=req.getContext();
  -	//	if( reqCtx != ctx && reqCtx != null ) return null; // throw
  -	return new HttpServletRequestFacade(req);
  -    }
  -
  -    public Object createHttpServletResponseFacade(Response res) {
  -	Context resCtx=res.getRequest().getContext();
  -	//if( resCtx != ctx && resCtx != null ) return null; // throw
  -	return new HttpServletResponseFacade(res);
  -    }
  -
       public int postRequest(Request rreq, Response rres ) {
   	//if( rreq.getContext() != ctx ) return; // throw
   
  
  
  
  1.8       +2 -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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ServletWrapper.java	2000/09/30 04:57:51	1.7
  +++ ServletWrapper.java	2000/10/01 06:37:42	1.8
  @@ -252,7 +252,7 @@
   
   	    try {
   		if( servlet!=null) {
  -		    BaseInterceptor cI[]=contextM.getContextInterceptors(context);
  +		    BaseInterceptor cI[]=contextM.getInterceptors(context.getContainer());
   		    for( int i=0; i< cI.length; i++ ) {
   			try {
   			    cI[i].preServletDestroy( context, this );
  @@ -323,7 +323,7 @@
   	//}
   
   	// Call pre, doInit and post
  -	BaseInterceptor cI[]=contextM.getContextInterceptors(context);
  +	BaseInterceptor cI[]=contextM.getInterceptors(context.getContainer());
   	for( int i=0; i< cI.length; i++ ) {
   	    try {
   		cI[i].preServletInit( context, this );
  
  
  
  1.6       +2 -2      jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/ServletWrapper.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServletWrapper.java	2000/09/30 04:57:51	1.5
  +++ ServletWrapper.java	2000/10/01 06:37:43	1.6
  @@ -249,7 +249,7 @@
   
   	    try {
   		if( servlet!=null) {
  -		    BaseInterceptor cI[]=contextM.getContextInterceptors(context);
  +		    BaseInterceptor cI[]=contextM.getInterceptors(context.getContainer());
   		    for( int i=0; i< cI.length; i++ ) {
   			try {
   			    cI[i].preServletDestroy( context, this );
  @@ -320,7 +320,7 @@
   	//}
   
   	// Call pre, doInit and post
  -	BaseInterceptor cI[]=contextM.getContextInterceptors(context);
  +	BaseInterceptor cI[]=contextM.getInterceptors(context.getContainer());
   	for( int i=0; i< cI.length; i++ ) {
   	    try {
   		cI[i].preServletInit( context, this );
  
  
  
  1.54      +68 -2     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.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- DefaultCMSetter.java	2000/09/30 04:03:38	1.53
  +++ DefaultCMSetter.java	2000/10/01 06:37:44	1.54
  @@ -70,16 +70,80 @@
   
   import org.apache.tomcat.util.log.*;
   
  +// don't extend - replace !
  +
   /**
    * Check ContextManager and set defaults for non-set properties
    *
    * @author costin@dnt.ro
    */
  -public class DefaultCMSetter extends BaseInterceptor {
  +public final class DefaultCMSetter extends BaseInterceptor {
   
       public DefaultCMSetter() {
       }
   
  +    /** Adjust context manager paths
  +     */
  +    public void engineInit( ContextManager cm )
  +    	throws TomcatException
  +    {
  +	// Adjust paths in CM
  +	String home=cm.getHome();
  +	if( home==null ) {
  +	    // try system property
  +	    home=System.getProperty(ContextManager.TOMCAT_HOME);
  +	}
  +	
  +	// Make it absolute
  +	if( home!= null ) {
  +	    home=FileUtil.getCanonicalPath( home );
  +	    cm.setHome( home );
  +	    log( "Setting server home to " + home );
  +	}
  +	
  +	
  +	String installDir=cm.getInstallDir();
  +	if( installDir!= null ) {
  +	    installDir=FileUtil.getCanonicalPath( installDir );
  +	    cm.setInstallDir( installDir );
  +	    log( "Setting server install dir to " + installDir );
  +	}
  +
  +	// if only one is set home==installDir
  +
  +	if( home!=null && installDir == null )
  +	    cm.setInstallDir( home );
  +
  +	if( home==null && installDir != null )
  +	    cm.setHome( installDir );
  +
  +	// if neither home or install is set,
  +	// and no system property, try "."
  +	if( home==null && installDir==null ) {
  +	    home=FileUtil.getCanonicalPath( "." );
  +	    installDir=home;
  +
  +	    cm.setHome( home );
  +	    cm.setInstallDir( home );
  +	}
  +
  +	// Adjust work dir
  +	String workDir=cm.getWorkDir();
  +	if( workDir==null ) {
  +	    workDir= ContextManager.DEFAULT_WORK_DIR;
  +	}
  +
  +	if( ! FileUtil.isAbsolute( workDir )) {
  +	    workDir=FileUtil.
  +		getCanonicalPath(home + File.separator+
  +				 workDir);
  +	}
  +	cm.setWorkDir( workDir );
  +
  +    }
  +    
  +    /** Adjust paths
  +     */
       public void addContext( ContextManager cm, Context ctx)
   	throws TomcatException
       {
  @@ -98,7 +162,7 @@
   	    }
   	    ctx.setAbsolutePath( absPath );
   	}
  -
  +	log( ctx.getPath() + " " + docBase + " " + absPath + " " +cm.getHome());
   	
   	// this would belong to a logger interceptor ?
   	Log loghelper=ctx.getLog();
  @@ -111,6 +175,8 @@
   	    cm.addLogger( loghelperServlet.getLogger() );
       }
   
  +    /** Add default error handlers
  +     */
       public void contextInit( Context ctx)
   	throws TomcatException
       {
  
  
  
  1.23      +11 -3     jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java
  
  Index: BaseInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- BaseInterceptor.java	2000/09/30 04:03:39	1.22
  +++ BaseInterceptor.java	2000/10/01 06:37:44	1.23
  @@ -208,8 +208,12 @@
   
       /** Called before the first body write, and before sending
        *  the headers. The interceptor have a chance to change the
  -     *  output headers. 
  -     */
  +     *  output headers.
  +     *
  +     *  Before body allows you do do various
  +     *	actions before the first byte of the response is sent. After all
  +     *  those callbacks are called tomcat may send the status and headers
  +    */
       public int beforeBody( Request rrequest, Response response ) {
   	return 0;
       }
  @@ -233,7 +237,11 @@
   
       /** Called after the output stream is closed ( either by servlet
        *  or automatically at end of service ).
  -     */
  +     *
  +     * It is called after the servlet finished
  +     * sending the response ( either closeing the stream or ending ). You
  +     * can deal with connection reuse or do other actions
  +    */
       public int afterBody( Request request, Response response) {
   	return 0;
       }
  
  
  
  1.36      +18 -136   jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java
  
  Index: Container.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- Container.java	2000/09/30 04:57:56	1.35
  +++ Container.java	2000/10/01 06:37:44	1.36
  @@ -408,7 +408,7 @@
       BaseInterceptor hooks[][]=new BaseInterceptor[MAX_HOOKS][];
   
       // used internally 
  -    Vector getLocalInterceptors(int hookId) {
  +    private Vector getLocalInterceptors(int hookId) {
   	if( interceptors[hookId]==null )
   	    interceptors[hookId]=new Vector();
   	return interceptors[hookId];
  @@ -418,7 +418,7 @@
   	in
       */
       public void addInterceptor( BaseInterceptor bi ) {
  -	for( int i=0; i< PREDEFINED_I.length; i++ ) {
  +	for( int i=0; i< PREDEFINED_I.length -1 ; i++ ) {
   	    if( bi.hasHook( PREDEFINED_I[i] )) {
   		if( interceptors[i]==null )
   		    interceptors[i]=new Vector();
  @@ -426,6 +426,12 @@
   		interceptors[i].addElement( bi );
   	    }
   	}
  +	// last position just gets all interceptors
  +	// ( to be used for context-level hooks )
  +	if( interceptors[H_engineInit]==null )
  +	    interceptors[H_engineInit]=new Vector();
  +	
  +	interceptors[ H_engineInit ].addElement( bi );
       }
   
       // make sure we reset the cache.
  @@ -450,7 +456,7 @@
   	if( hooks[type] != null ) {
   	    return hooks[type];
   	}
  -	if( dL>0 ) 
  +	if( dL>5 ) 
   	    debug("create hooks for " + type + " " + PREDEFINED_I[type]);
   	
   	Container globalIntContainer=getContextManager().getContainer();
  @@ -466,152 +472,28 @@
   	
   	for ( int i = 0 ; i < gsize ; i++ ){
   	    hooks[type][i]=(BaseInterceptor)globals.elementAt(i);
  -	    if( dL > 0 ) debug( "Add " + i + " " + hooks[type][i]);
  +	    if( dL > 5 ) debug( "Add " + i + " " + hooks[type][i]);
   	}
   	for ( int i = 0 ; i < lsize  ; i++ ){
   	    hooks[type][gsize+i]=(BaseInterceptor)locals.elementAt(i);
  -	    if( dL > 0 ) debug( "Add " + i + " " + hooks[type][i+gsize]);
  +	    if( dL > 5 ) debug( "Add " + i + " " + hooks[type][i+gsize]);
   	}
   
   	return hooks[type];
       }
  -
  -    
  -    // -------------------- Old code handling interceptors 
  -    // DEPRECATED ( after the new code is tested )
   
  -    /** Per/container interceptors.
  +    /** Get all interceptors
        */
  -    Vector contextInterceptors=new Vector();
  -    Vector requestInterceptors=new Vector();
  -
  -    // interceptor cache - avoid Vector enumeration
  -    BaseInterceptor cInterceptors[];
  -    BaseInterceptor rInterceptors[];
  -    BaseInterceptor rCachedRequestInterceptors[]={};
  -    BaseInterceptor rCachedContextInterceptors[]={};
  -
  -    /** Add a per/container context interceptor. It will be notified
  -     *  of all context events happening inside this container.
  -     *   XXX incomplete implementation
  -     */
  -    public void addContextInterceptor( BaseInterceptor ci) {
  -	addInterceptor( (BaseInterceptor) ci );
  -        // XXX will be deprecated when hooks end testing
  -	contextInterceptors.addElement( ci );
  -    }
  -
  -    /** Add a per/container request interceptor. It will be called back for
  -     *  all operations for requests that are mapped to this container.
  -     *  Note that all global interceptors will be called first.
  -     *   XXX incomplete implementation.
  -     */
  -    public void addRequestInterceptor( BaseInterceptor ri) {
  -	addInterceptor( (BaseInterceptor) ri );
  -        // XXX will be deprecated when hooks end testing
  -	requestInterceptors.addElement( ri );
  -	if( ri instanceof BaseInterceptor )
  -	        contextInterceptors.addElement( ri );
  -    }
  -
  -    // -------------------- Getting the active interceptors 
  -    
  -    /** Return the context interceptors as an array.
  -     *	For performance reasons we use an array instead of
  -     *  returning the vector - the interceptors will not change at
  -     *	runtime and array access is faster and easier than vector
  -     *	access
  -     */
  -    public BaseInterceptor[] getContextInterceptors() {
  -	if( cInterceptors == null ||
  -	    cInterceptors.length != contextInterceptors.size()) {
  -	    cInterceptors=new BaseInterceptor[contextInterceptors.size()];
  -	    for( int i=0; i<cInterceptors.length; i++ ) {
  -		cInterceptors[i]=(BaseInterceptor)contextInterceptors.
  -		    elementAt(i);
  -	    }
  -	}
  -	return cInterceptors;
  -    }
  -
  -    /** Return the context interceptors as an array.
  -	For performance reasons we use an array instead of
  -	returning the vector - the interceptors will not change at
  -	runtime and array access is faster and easier than vector
  -	access
  -    */
  -    public BaseInterceptor[] getRequestInterceptors() {
  -	if( rInterceptors == null ||
  -	    rInterceptors.length != requestInterceptors.size())
  -	{
  -	    rInterceptors=new BaseInterceptor[requestInterceptors.size()];
  -	    for( int i=0; i<rInterceptors.length; i++ ) {
  -		rInterceptors[i]=(BaseInterceptor)requestInterceptors.
  -		    elementAt(i);
  -	    }
  -	}
  -	return rInterceptors;
  -    }
  -
  -    /** Return all interceptors for this container ( local and
  -	global )
  -    */
  -    public BaseInterceptor[] getCachedRequestInterceptors()
  +    public BaseInterceptor[] getInterceptors()
       {
  -	BaseInterceptor[] ari=rCachedRequestInterceptors;
  -	
  -	if (ari.length == 0){
  -            BaseInterceptor[] cri=this.getRequestInterceptors();
  -            BaseInterceptor[] gri=getContextManager()
  -		.getRequestInterceptors();
  -            if  (cri!=null && cri.length > 0) {
  -                int al=cri.length+gri.length;
  -                ari=new BaseInterceptor[al];
  -                int i;
  -                for ( i = 0 ; i < gri.length ; i++ ){
  -                    ari[i]=gri[i];
  -                }
  -                for (int j = 0 ; j < cri.length ; j++ ){
  -                    ari[i+j]=cri[j];
  -                }
  -            } else {
  -                ari=gri;
  -            }
  -            rCachedRequestInterceptors=ari;
  -        }
  -        return rCachedRequestInterceptors;
  +	// We don't check for "hasHook", so all
  +	// interceptors are available here
  +	return getInterceptors( H_engineInit );
       }
   
  -    /** Return all interceptors for this container ( local and
  -	global )
  -    */
  -    public BaseInterceptor[] getCachedContextInterceptors()
  -    {
  -	BaseInterceptor[] aci=rCachedContextInterceptors;
  -	if (aci.length == 0){
  -            BaseInterceptor[] cci=this.getContextInterceptors();
  -            BaseInterceptor[] gci=getContextManager().
  -		getContextInterceptors();
  -            if  (cci!=null && cci.length > 0) {
  -                int al=cci.length+gci.length;
  -                aci=new BaseInterceptor[al];
  -                int i;
  -                for ( i = 0 ; i < gci.length ; i++ ){
  -                    aci[i]=gci[i];
  -                }
  -                for (int j = 0 ; j < cci.length ; j++ ){
  -                    aci[i+j]=cci[j];
  -                }
  -            } else {
  -                aci=gci;
  -            }
  -            rCachedContextInterceptors=aci;
  -        }
  -	return rCachedContextInterceptors;
  -    }
  -
  +    
       // debug
  -    public static final int dL=0;
  +    public static final int dL=4;
       private void debug( String s ) {
   	System.out.println("Container: " + s );
       }
  
  
  
  1.124     +22 -12    jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
  retrieving revision 1.123
  retrieving revision 1.124
  diff -u -r1.123 -r1.124
  --- Context.java	2000/09/30 04:03:39	1.123
  +++ Context.java	2000/10/01 06:37:44	1.124
  @@ -284,15 +284,18 @@
   	map.setHandler( sw );
   	map.setPath( path );
   
  -	// callback - hooks are called. 
  -	contextM.addContainer( map );
  +	// Notify interceptors that a new container is added
  +	BaseInterceptor cI[]=contextM.getInterceptors(map);
  +	for( int i=0; i< cI.length; i++ ) {
  +	    cI[i].addContainer( map );
  +	}
   
   	sw = getServletByName(servletName);
   	
   	
   	if (sw == null) {
   	    // web.xml validation - a mapping with no servlet rollback
  -	    contextM.removeContainer( map );
  +	    removeContainer( map );
    	    throw new TomcatException( "Mapping with invalid servlet  " +
   				       path + " " + servletName );
   	}
  @@ -327,7 +330,12 @@
   	    // XXX check if exists, merge if true.
   	    constraints.put( path[i], ct );
   	    //contextM.addSecurityConstraint( this, path[i], ct);
  -	    contextM.addContainer(  ct );
  +
  +	    // Notify interceptors that a new container is added
  +	    BaseInterceptor cI[]=contextM.getInterceptors(ct);
  +	    for( int j=0; j< cI.length; j++ ) {
  +		cI[j].addContainer( ct );
  +	    }
   	}
       }
   
  @@ -753,8 +761,16 @@
   
       /** Remove a container
        */
  -    public final  void removeContainer( Container ct ) {
  +    public final  void removeContainer( Container ct )
  +	throws TomcatException
  +    {
   	containers.remove(ct.getPath());
  +
  +	// notify modules that a container was removed
  +	BaseInterceptor cI[]=contextM.getInterceptors(ct);
  +	for( int i=0; i< cI.length; i++ ) {
  +	    cI[i].removeContainer( ct );
  +	}
       }
   
       // -------------------- Servlets management --------------------
  @@ -1011,13 +1027,7 @@
        *	known at that time
        */
       public final  void addInterceptor( BaseInterceptor ri ) {
  -        defaultContainer.addRequestInterceptor(ri);
  +        defaultContainer.addInterceptor(ri);
       }
   
  -
  -    // -------------------- Deprecated --------------------
  -    
  -    public final  void addRequestInterceptor( BaseInterceptor ri ) {
  -        addInterceptor( ri );
  -    }
   }
  
  
  
  1.141     +384 -483  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.140
  retrieving revision 1.141
  diff -u -r1.140 -r1.141
  --- ContextManager.java	2000/09/30 04:57:56	1.140
  +++ ContextManager.java	2000/10/01 06:37:45	1.141
  @@ -70,34 +70,105 @@
   import java.util.*;
   
   /**
  - * ContextManager is the entry point and "controler" of the servlet execution.
  - * It maintains a list of WebApplications and a list of global event
  - * interceptors that are set up to handle the actual execution.
  - *
  - * The ContextManager will direct the request processing flow
  - * from its arrival from the server/protocl adapter ( in service() ).
  - * It will do that by calling a number of hooks implemented by Interceptors.
  - *
  - * Hooks are provided for request parsing and mapping, auth, autorization,
  - * pre/post service, actual invocation and logging.
  - *
  - * ContextManager will also store properties that are global to the servlet
  - * container - like root directory, install dir, work dir.
  - *
  - * The extension mechanism for tomcat is the Interceptor.
  - * This class is final - if you need to change certain functionality
  - * you should add a new hook.
  - *
  - * ContextManager is not a singleton - it represent a servlet container
  - * instance ( with all associated ports and configurations ).
  - * One application may try to embed multiple ( distinct ) servlet containers -
  - * this feature hasn't been tested or used
  - *
  - * @author James Duncan Davidson [duncan@eng.sun.com]
  - * @author James Todd [gonzo@eng.sun.com]
  - * @author Harish Prabandham
  - * @author costin@eng.sun.com
  - * @author Hans Bergsten [hans@gefionsoftware.com]
  +  ContextManager is the entry point and "controler" of the servlet execution.
  +  It maintains a list of WebApplications and a list of global event
  +  interceptors that are set up to handle the actual execution.
  + 
  +  The ContextManager will direct the request processing flow
  +  from its arrival from the server/protocl adapter ( in service() ).
  +  It will do that by calling a number of hooks implemented by Interceptors.
  + 
  +  Hooks are provided for request parsing and mapping, auth, autorization,
  +  pre/post service, actual invocation and logging.
  + 
  +  ContextManager will also store properties that are global to the servlet
  +  container - like root directory, install dir, work dir.
  + 
  +  The extension mechanism for tomcat is the Interceptor.
  +  This class is final - if you need to change certain functionality
  +  you should add a new hook.
  + 
  +  ContextManager is not a singleton - it represent a servlet container
  +  instance ( with all associated ports and configurations ).
  +  One application may try to embed multiple ( distinct ) servlet containers -
  +  this feature hasn't been tested or used
  + 
  + 
  +   Expected startup order:
  +
  +  1. Create ContextManager
  +
  +  2. Set settable properties for ContextManager ( home, debug, etc)
  +
  +  3. Add global Interceptors
  +
  +  4. You may create, set and add Contexts. NO HOOKS ARE CALLED.
  +  
  +  5. Call init(). At this stage engineInit() callback will be
  +     called for all global interceptors.
  +     - DefaultCMSetter ( or a replacement ) must be the first in
  +     the chain and will adjust the paths and set defaults for
  +     all unset properties.
  +     - AutoSetup and other interceptors can automatically add/set
  +     more properties and make other calls.
  +
  +     During engineInit() a number of Contexts are created and
  +     added to the server. No addContext() callback is called until
  +     the last engineInit() returns. ( XXX do we need this restriction ?)
  +
  +  XXX I'n not sure about contextInit and about anything below.
  +
  +  x. Server will move to INITIALIZED state. No callback other than engineInit
  +     can be called before the server enters this state.
  +
  +  x. addContext() callbacks will be called for each context.
  +     After init you may add more contexts, and addContext() callback
  +     will be called (since the server is initialized )
  +
  +  x. Call start().
  +
  +  x. All contexts will be initialized ( contextInit()
  +     callback ).
  +
  +  x. Server will move to STARTED state. No servlet should be 
  +     served before this state.
  +
  +     
  +     During normal operation, it is possible to add  Contexts.
  +
  +  1. Create the Context, set properties ( that can be done from servlets
  +     or by interceptors like ~user)
  +
  +  2. call CM.addContext(). This will triger the addContext() callback.
  +     ( if CM is initialized )
  +
  +  3. call CM.initContext( ctx ). This will triger contextInit() callback.
  +     After that the context is initialized and can serve requests.
  +     No request belonging to this context can't be served before this
  +     method returns.
  +
  +     XXX Context state
  +     
  +     It is also possible to remove Contexts.
  +
  +  1. Find the Context ( enumerate all existing contexts and find the one
  +    you need - host and path are most likely keys ).
  +
  +  2. Call removeContext(). This will call removeContext() callbacks.
  +
  +  
  +     To stop the server, you need to:
  +
  +  1. Call shutdown().
  +
  +  2. The server will ...
  +
  + 
  +  @author James Duncan Davidson [duncan@eng.sun.com]
  +  @author James Todd [gonzo@eng.sun.com]
  +  @author Harish Prabandham
  +  @author costin@eng.sun.com
  +  @author Hans Bergsten [hans@gefionsoftware.com]
    */
   public final class ContextManager implements LogAware{
       /** Official name and version
  @@ -105,46 +176,73 @@
       public static final String TOMCAT_VERSION = "3.3 dev";
       public static final String TOMCAT_NAME = "Tomcat Web Server";
       
  +    /** Property used to set the random number generator
  +     */
  +    public static final String RANDOM_CLASS_PROPERTY=
  +	"tomcat.sessionid.randomclass";
  +
  +    /** Property used to set the base directory ( tomcat home )
  +     */
  +    public static final String TOMCAT_HOME=
  +	"tomcat.home";
  +
  +    /** Default work dir, relative to home
  +     */
  +    public static final String DEFAULT_WORK_DIR="work";
  +
  +    // Accounting
  +    /** time when init() started
  +     */
  +    public static final int ACC_INIT_START=0;
  +    /** Time when init() finished()
  +     */
  +    public static final int ACC_INIT_END=1;
  +    public static final int ACCOUNTS=2;
  +
  +    // State
  +    public static final int STATE_INITIAL=0;
  +    public static final int STATE_INITIALIZED=1;
  +    public static final int STATE_STARTED=2;
  +    public static final int STATE_STOPED=3;
  +    
  +    // -------------------- local variables --------------------
  +
  +    private int state=STATE_INITIAL;
  +    
       /** Contexts managed by this server
        */
       private Vector contextsV=new Vector();
   
  -    int debug=0;
  +    private int debug=0;
   
       // Global properties for this tomcat instance:
   
       /** Private workspace for this server
        */
  -    String workDir;
  +    private String workDir;
   
       /** The base directory where this instance runs.
        *  It can be different from the install directory to
        *  allow one install per system and multiple users
        */
  -    String home;
  +    private String home;
   
       /** The directory where tomcat is installed
        */
  -    String installDir;
  +    private String installDir;
   
  -    /** Property used to set the random number generator
  -     */
  -    public static final String RANDOM_CLASS_PROPERTY=
  -	"tomcat.sessionid.randomclass";
       
  -    /** Default work dir, relative to home
  -     */
  -    public static final String DEFAULT_WORK_DIR="work";
  -
  -    Container defaultContainer;
  +    private Container defaultContainer;
   
       // the application loader. ContextManager is loaded with
       // a class loader containing tomcat-specific classes,
       // use parent loader to avoid polution
  -    ClassLoader parentLoader;
  +    private ClassLoader parentLoader;
       // tomcat classes ( used to load tomcat)
  -    URL serverClassPath[];
  +    private URL serverClassPath[];
       
  +    private Counters cntr=new Counters(ACCOUNTS);
  +
       /**
        * Construct a new ContextManager instance with default values.
        */
  @@ -154,135 +252,10 @@
   	defaultContainer.setContextManager( this );
           defaultContainer.setPath( null ); // default container
       }
  -
  -    // -------------------- setable properties: tomcat directories  ---
  -    /**
  -     *  The home of the tomcat instance - you can have multiple
  -     *  users running tomcat, with a shared install directory.
  -     *  Every instance will have its own logs, webapps directory
  -     *  and local config, all relative to this directory.
  -     */
  -    public void setHome(String home) {
  -	this.home=FileUtil.getCanonicalPath( home );
  -	log( "Setting home to " + this.home );
  -    }
  -
  -    /**
  -     *  The home of the tomcat instance - you can have multiple
  -     *  users running tomcat, with a shared install directory.
  -     *  Every instance will have its own logs, webapps directory
  -     *  and local config, all relative to this directory.
  -     *
  -     *  If no home is configured we'll try the install dir
  -     *  XXX clean up the order and process of guessing - maybe we can
  -     *  just throw error instead of guessing wrong.
  -     */
  -    public String getHome() {
  -	if(home!=null) return home;
  -
  -	// If none defined, assume tomcat.home is used as base.
  -	if( installDir != null )
  -	    home=FileUtil.getCanonicalPath( installDir );
  -
  -	if(home!=null) return home;
   
  -	// try at least the system property
  -	home=FileUtil.getCanonicalPath( System.getProperty("tomcat.home") );
  -	if(home!=null) return home;
  +    // -------------------- Server functions --------------------
   
  -	home=FileUtil.getCanonicalPath( "." );
  -	// try current dir - we should throw an exception
  -	return home;
  -    }
  -
  -    /** Get installation directory, where libraries and default files
  -     *	are located.  If path specified is relative,
  -     *  evaluate it relative to the current working directory.
  -     */
  -    public String getInstallDir() {
  -	if(installDir!= null) return installDir;
  -
  -	installDir=System.getProperty("tomcat.home");
  -	if(installDir!= null) return installDir;
  -
  -	// If the property is not set ( for example JNI worker ) assume
  -	// at least home is set up corectly.
  -	installDir=getHome();
  -	return installDir;
  -    }
  -
  -    /** Set installation directory, where libraries and default files
  -     *	are located.  If path specified is relative,
  -     *  evaluate it relative to the current working directory.
  -     */
  -    public void setInstallDir( String tH ) {
  -	installDir=tH;
  -    }
  -
       /**
  -     * WorkDir property - where all working files will be created
  -     */
  -    public void setWorkDir( String wd ) {
  -	if(debug>0) log("set work dir " + wd);
  -	this.workDir=FileUtil.getCanonicalPath( getHome() + File.separator + wd );
  -    }
  -
  -    /**
  -     * WorkDir property - where all working files will be created
  -     */
  -    public String getWorkDir() {
  -	if( workDir==null)
  -	    workDir=FileUtil.getCanonicalPath(getHome() + File.separator + DEFAULT_WORK_DIR);
  -	return workDir;
  -    }
  -
  -    /** Parent loader is the "base" class loader of the
  -     *	application that starts tomcat, and includes no
  -     *	tomcat classes. All servlet loaders will have it as
  -     *  a parent loader, as if the webapps would be loaded
  -     *  by the embeding app ( using parentLoader ).
  -     *
  -     *  Tomcat will add servlet.jar and any other extension
  -     *  it is configured to - for example trusted webapps
  -     *  may have tomcat internal classes in classpath. 
  -     */
  -    public void setParentLoader( ClassLoader cl ) {
  -	parentLoader=cl;
  -    }
  -
  -    public ClassLoader getParentLoader() {
  -	return parentLoader;
  -    }
  -
  -    public URL[] getServerClassPath() {
  -	if( serverClassPath==null ) return new URL[0];
  -	return serverClassPath;
  -    }
  -    
  -    public void setServerClassPath( URL urls[] ) {
  -	serverClassPath=urls;
  -    }
  -
  -    /** Get the name of the class to be used for generating random numbers by
  -     * the session id generator. By default this is
  -     *  <code>java.security.SecureRandom</code>.
  -     **/
  -    public String getRandomClass() {
  -        String randomClass = System.getProperty(RANDOM_CLASS_PROPERTY);
  -        return randomClass == null ? "java.security.SecureRandom" : randomClass;
  -    }
  -    
  -    /** Sets the name of the class used for generating random numbers by the
  -     *  session id generator. 
  -     */
  -    public void setRandomClass(String randomClass) {
  -        System.setProperty(RANDOM_CLASS_PROPERTY, randomClass);
  -    }
  -
  -
  -    // -------------------- Support functions --------------------
  -
  -    /**
        *  Init() is called after the context manager is set up
        *  and configured ( all setFoo methods are called, all initial
        *  interceptors are added and their setters are called ).
  @@ -299,24 +272,23 @@
   
   	cntr.touchCounter( ACC_INIT_START );
   
  -	BaseInterceptor cI[]=getContextInterceptors();
  +	BaseInterceptor cI[]=getInterceptors();
   	for( int i=0; i< cI.length; i++ ) {
   	    cI[i].engineInit( this );
   	}
   
  -    	// init contexts
  -	Enumeration enum = getContexts();
  -	while (enum.hasMoreElements()) {
  -	    Context context = (Context)enum.nextElement();
  -	    try {
  -		initContext( context );
  -	    } catch (TomcatException ex ) {
  -		if( context!=null ) {
  -		    log( "ERROR initializing " + context.toString(), ex );
  -		    removeContext( context  );
  -		}
  +	state=STATE_INITIALIZED;
  +
  +	Enumeration existingCtxE=contextsV.elements();
  +	while( existingCtxE.hasMoreElements() ) {
  +	    Context ctx=(Context)existingCtxE.nextElement();
  +	    
  +	    cI=getInterceptors(ctx.getContainer());
  +	    for( int i=0; i< cI.length; i++ ) {
  +		cI[i].addContext( this, ctx );
   	    }
   	}
  +
   	cntr.touchCounter( ACC_INIT_END);
       }
   
  @@ -329,7 +301,7 @@
   	    removeContext((Context)enum.nextElement());
   	}
   
  -	BaseInterceptor cI[]=getContextInterceptors();
  +	BaseInterceptor cI[]=getInterceptors();
   	for( int i=0; i< cI.length; i++ ) {
   	    cI[i].engineShutdown( this );
   	}
  @@ -346,10 +318,6 @@
        * or after the admin adds a new context.
        */
       public void initContext( Context ctx ) throws TomcatException {
  -	BaseInterceptor cI[]=getContextInterceptors(ctx);
  -	for( int i=0; i< cI.length; i++ ) {
  -	    cI[i].contextInit( ctx );
  -	}
       }
   
       /** Stop the context and release all resources.
  @@ -372,7 +340,7 @@
   	    }
   	}
   
  -	BaseInterceptor cI[]=getContextInterceptors(ctx);
  +	BaseInterceptor cI[]=getInterceptors(ctx.getContainer());
   	for( int i=0; i< cI.length; i++ ) {
   	    cI[i].contextShutdown( ctx );
   	}
  @@ -385,6 +353,25 @@
        *  case we should add a new hook
        */
       public void start() throws Exception {
  +    	// init contexts
  +	Enumeration enum = getContexts();
  +	while (enum.hasMoreElements()) {
  +	    Context ctx = (Context)enum.nextElement();
  +	    try {
  +		BaseInterceptor cI[]=getInterceptors(ctx.getContainer());
  +		for( int i=0; i< cI.length; i++ ) {
  +		    cI[i].contextInit( ctx );
  +		}
  +	    } catch (TomcatException ex ) {
  +		if( ctx!=null ) {
  +		    log( "ERROR initializing " + ctx.toString(), ex );
  +		    removeContext( ctx  );
  +		}
  +	    }
  +	}
  +	// Note that contextInit() will triger other 
  +	
  +	state=STATE_STARTED;
       }
   
       /** Will stop all connectors
  @@ -393,7 +380,125 @@
   	shutdown();
       }
   
  +    // -------------------- setable properties --------------------
  +
  +    /**
  +     *  The home of the tomcat instance - you can have multiple
  +     *  users running tomcat, with a shared install directory.
  +     *  
  +     *  Home is used as a base for logs, webapps, local config.
  +     *  Install dir ( if different ) is used to find lib ( jar
  +     *   files ).
  +     *
  +     *  The "tomcat.home" system property is used if no explicit
  +     *  value is set.
  +     */
  +    public void setHome(String home) {
  +	this.home=home;
  +    }
  +
  +    public String getHome() {
  +	return home;
  +    }
  +
  +    /**
  +     *  Get installation directory. This is used to locate
  +     *  jar files ( lib ). If tomcat instance is shared,
  +     *  home is used for webapps, logs, config.
  +     *  If either home or install is not set, the other
  +     *  is used as default.
  +     * 
  +     */
  +    public String getInstallDir() {
  +	return installDir;
  +    }
  +
  +    public void setInstallDir( String tH ) {
  +	installDir=tH;
  +    }
  +
  +    /**
  +     * WorkDir property - where all working files will be created
  +     */
  +    public void setWorkDir( String wd ) {
  +	if(debug>0) log("set work dir " + wd);
  +	this.workDir=wd;
  +    }
  +
  +    public String getWorkDir() {
  +	return workDir;
  +    }
  +
  +    /** Sets the name of the class used for generating random numbers by the
  +     *  session id generator. By default this is <code>java.security.SecureRandom</code>.
  +     */
  +    public void setRandomClass(String randomClass) {
  +        System.setProperty(RANDOM_CLASS_PROPERTY, randomClass);
  +    }
  +
  +    public String getRandomClass() {
  +        String randomClass = System.getProperty(RANDOM_CLASS_PROPERTY);
  +        return randomClass == null ? "java.security.SecureRandom" : randomClass;
  +    }
  +
  +    /** Debug level
  +     */
  +    public void setDebug( int level ) {
  +	if( level != debug )
  +	    log( "Setting debug level to " + level);
  +	debug=level;
  +    }
  +
  +    public int getDebug() {
  +	return debug;
  +    }
  +
  +    // -------------------- Other properties --------------------
  +
  +    public int getState() {
  +	return state;
  +    }
  +    
  +    /**
  +     *  Parent loader is the "base" class loader of the
  +     *	application that starts tomcat, and includes no
  +     *	tomcat classes. All servlet loaders will have it as
  +     *  a parent loader, as if the webapps would be loaded
  +     *  by the embeding app ( using parentLoader ).
  +     *
  +     *  Tomcat will add servlet.jar and any other extension
  +     *  it is configured to - for example trusted webapps
  +     *  may have tomcat internal classes in classpath. 
  +     */
  +    public void setParentLoader( ClassLoader cl ) {
  +	parentLoader=cl;
  +    }
  +
  +    public ClassLoader getParentLoader() {
  +	return parentLoader;
  +    }
  +
  +    public URL[] getServerClassPath() {
  +	if( serverClassPath==null ) return new URL[0];
  +	return serverClassPath;
  +    }
  +    
  +    public void setServerClassPath( URL urls[] ) {
  +	serverClassPath=urls;
  +    }
  +
  +    /** Default container
  +     */
  +    public Container getContainer() {
  +        return defaultContainer;
  +    }
  +
  +    public void setContainer(Container newDefaultContainer) {
  +        defaultContainer = newDefaultContainer;
  +    }
  +
       // -------------------- Contexts --------------------
  +
       /** Return the list of contexts managed by this server
        */
       public Enumeration getContexts() {
  @@ -407,28 +512,25 @@
        */
       public void addContext( Context ctx ) throws TomcatException {
   	log("Adding context " +  ctx.toString());
  -
   	// Make sure context knows about its manager.
   	ctx.setContextManager( this );
   
   	// If the context already exist - the interceptors need
   	// to deal with that ( either replace or throw an exception ).
  +
  +	contextsV.addElement( ctx );
  +	// XXX temporary workaround for the old SimpleMapper -
   
  -	// The mapping alghoritm may use more than path and host -
  -	// if not now, then in future.
  +	// XXX hack - should be removed
  +	if( ctx.getHost() ==null ) contexts.put( ctx.getPath(), ctx );
   
  -	BaseInterceptor cI[]=getContextInterceptors(ctx);
  +	if( state == STATE_INITIAL )
  +	    return;
  +	
  +	BaseInterceptor cI[]=getInterceptors(ctx.getContainer());
   	for( int i=0; i< cI.length; i++ ) {
   	    cI[i].addContext( this, ctx );
   	}
  -
  -	String vhost=ctx.getHost();
  -
  -	// XXX temporary workaround for the old SimpleMapper -
  -	// This code will be removed as soon as the new mapper is stable.
  -	if( vhost ==null ) // the old mapper will support only "default" server
  -	    contexts.put( ctx.getPath(), ctx );
  -	contextsV.addElement( ctx );
       }
   
       /** Shut down and removes a context from service
  @@ -438,7 +540,7 @@
   
   	log( "Removing context " + context.toString());
   	
  -	BaseInterceptor cI[]=getContextInterceptors(context);
  +	BaseInterceptor cI[]=getInterceptors(context.getContainer());
   	for( int i=0; i< cI.length; i++ ) {
   	    cI[i].removeContext( this, context );
   	}
  @@ -448,79 +550,27 @@
   	contexts.remove(context.getPath());
       }
   
  -    public void doReload( Request req, Context context )
  -	throws TomcatException
  -    {
  -	if( context==null ) return;
   
  -	if( debug>0 ) log( "Reloading context " + context.toString());
  -
  -	BaseInterceptor cI[]=getContextInterceptors(context);
  -	for( int i=0; i< cI.length; i++ ) {
  -	    cI[i].reload(  req, context );
  -	}
  -    }
  -
  -
  -    /** Notify interceptors that a new container was added.
  -     */
  -    public void addContainer( Container container )
  -    	throws TomcatException
  -    {
  -	BaseInterceptor cI[]=getContextInterceptors(container);
  -	for( int i=0; i< cI.length; i++ ) {
  -	    cI[i].addContainer( container);
  -	}
  -    }
  -
  -    /** Notify interceptors that a container was removed.
  -     */
  -    public void removeContainer( Container container )
  -	throws TomcatException
  -    {
  -	BaseInterceptor cI[]=getContextInterceptors(container);
  -	for( int i=0; i< cI.length; i++ ) {
  -	    cI[i].removeContainer( container);
  -	}
  -    }
  -
       // -------------------- Interceptors --------------------
       // The interceptors are handled per/container ( thanks to Nacho
  -    // for this contribution ). We just delegate to the right
  -    // container ( in future we should remove this, and use the
  -    // right objects )
  +    // for this contribution ).
       
  -    public void addRequestInterceptor( BaseInterceptor ri ) {
  -        defaultContainer.addRequestInterceptor(ri);
  +    public void addInterceptor( BaseInterceptor ri ) {
  +        defaultContainer.addInterceptor(ri);
       }
   
  -    /** Return all the interceptors associated with a request.
  -	That includes global ( context manager ) interceptors,
  -	webapp ( Context ) interceptors and possibly interceptors
  -	associated with containers ( urls inside the web app ).
  -
  -	For performance reasons we use arrays and cache the result inside
  -	containers.
  -
  -	XXX Todo: 
  -	Dynamic add of interceptors is not supported.
  -    */
  -    public BaseInterceptor[] getRequestInterceptors( Request req ) {
  -        Context ctx=req.getContext();
  -        // if Bad request (ctx == null) only global interceptors are called
  -        if( ctx == null )
  -           return getRequestInterceptors();
  -        Container ct=ctx.getContainer();
  -        BaseInterceptor[] ari=ct.getCachedRequestInterceptors();
  -
  -	return ari;
  +    public BaseInterceptor[] getInterceptors() {
  +	return defaultContainer.getInterceptors();
       }
  -
  -    public BaseInterceptor[] getRequestInterceptorszz( Request req ,
  -						       int hook_id)
  +    
  +    public BaseInterceptor[] getInterceptors( Container ct ) {
  +	return ct.getInterceptors();
  +    }
  +    
  +    public BaseInterceptor[] getInterceptors( Request req ,
  +					      int hook_id)
       {
           Context ctx=req.getContext();
  -        // if Bad request (ctx == null) only global interceptors are called
           if( ctx == null )
              return defaultContainer.getInterceptors(hook_id);
           Container ct=ctx.getContainer();
  @@ -529,26 +579,6 @@
   	return ari;
       }
   
  -    public BaseInterceptor[] getRequestInterceptors() {
  -	return defaultContainer.getRequestInterceptors();
  -    }
  -
  -    public void addContextInterceptor( BaseInterceptor ci) {
  -        defaultContainer.addContextInterceptor(ci);
  -    }
  -
  -    public BaseInterceptor[] getContextInterceptors() {
  -	return defaultContainer.getContextInterceptors();
  -    }
  -
  -    public BaseInterceptor[] getContextInterceptors(Container ct) {
  -        BaseInterceptor[] aci=ct.getCachedContextInterceptors();
  -	return aci;
  -    }
  -
  -    public BaseInterceptor[] getContextInterceptors(Context ctx) {
  -        return getContextInterceptors(ctx.getContainer());
  -    }
       // -------------------- Request processing / subRequest ------------------
       // -------------------- Main request processing methods ------------------
   
  @@ -580,7 +610,12 @@
   	    handleError( req, res, ex );
   	}
   	finally {
  -	    doPostRequest(req, res);
  +	    BaseInterceptor reqI[]= getInterceptors(req,
  +						    Container.H_postRequest);
  +
  +	    for( int i=0; i< reqI.length; i++ ) {
  +		reqI[i].postRequest( req, res );
  +	    }
   	    req.recycle();
   	    res.recycle();
   	}
  @@ -636,12 +671,6 @@
   	}
       }
   
  -    static int contextMap_ID=Container.getHookId( "contextMap");
  -    static int requestMap_ID=Container.getHookId( "requestMap");
  -    static int authorize_ID=Container.getHookId( "authorize");
  -    static int authenticate_ID=Container.getHookId( "authenticate");
  -
  -
       /** Will find the Handler for a servlet, assuming we already have
        *  the Context. This is also used by Dispatcher and getResource -
        *  where the Context is already known.
  @@ -651,15 +680,17 @@
   
   	int status=0;
           BaseInterceptor ri[];
  -	ri=defaultContainer.getInterceptors(contextMap_ID);
  +	ri=defaultContainer.getInterceptors(Container.H_contextMap);
   	
   	for( int i=0; i< ri.length; i++ ) {
   	    status=ri[i].contextMap( req );
   	    if( status!=0 ) return status;
   	}
   
  -	ri=defaultContainer.getInterceptors( requestMap_ID);
  +	ri=defaultContainer.getInterceptors(Container.H_requestMap);
   	for( int i=0; i< ri.length; i++ ) {
  +	    if( debug > 1 )
  +		log( "RequestMap " + ri[i] );
   	    status=ri[i].requestMap( req );
   	    if( status!=0 ) return status;
   	}
  @@ -669,136 +700,7 @@
   	return 0;
       }
   
  -    /** Call all authentication callbacks. If any of them is able to
  -	identify the user it will set the principal in req.
  -     */
  -    public int doAuthenticate( Request req, Response res ) {
  -	int status=0;
  -//	RequestInterceptor reqI[]= getRequestInterceptors(req);
  -	BaseInterceptor reqI[]= req.getContext().getContainer().getInterceptors(authenticate_ID);
  -	for( int i=0; i< reqI.length; i++ ) {
  -	    status=reqI[i].authenticate( req, res );
  -	    if ( status != 0 ) {
  -		if( debug>0) log( "Authenticate status " + status );
  -		return status;
  -	    }
  -	}
  -	return 0;
  -    }
  -
  -    /** Call all authorization callbacks. The "require valid user" attributes
  -	are probably set during the mapping stage ( for efficiency), but it
  -	can be done here too.
  -     */
  -    public int doAuthorize( Request req, Response res, String roles[] ) {
  -	int status=0;
  -//	RequestInterceptor reqI[]= getRequestInterceptors(req);
  -	BaseInterceptor reqI[]= req.getContext().getContainer().getInterceptors(authorize_ID);
  -
  -	for( int i=0; i< reqI.length; i++ ) {
  -	    status = reqI[i].authorize( req, res, roles );
  -	    if ( status != 0 ) {
  -		if( debug>0) log( "Authorize status " + status );
  -		return status;
  -	    }
  -	}
  -	return 0;
  -    }
  -
  -    /** Call beforeBody callbacks. Before body allows you do do various
  -	actions before the first byte of the response is sent. After all
  -	those callbacks are called tomcat may send the status and headers
  -    */
  -    int doBeforeBody( Request req, Response res ) {
  -	BaseInterceptor reqI[]= getRequestInterceptors(req);
  -
  -	for( int i=0; i< reqI.length; i++ ) {
  -	    reqI[i].beforeBody( req, res );
  -	}
  -	return 0;
  -    }
  -
  -    /** Call beforeCommit callbacks. This allows interceptors to manipulate the
  -	buffer before it gets sent.
  -	XXX Add a standard way to access the body. The method was not used too
  -	much, we need a review and maybe change in parameters.
  -    */
  -    int doBeforeCommit( Request req, Response res ) {
  -	BaseInterceptor reqI[]= getRequestInterceptors(req);
  -
  -	for( int i=0; i< reqI.length; i++ ) {
  -	    reqI[i].beforeCommit( req, res );
  -	}
  -	return 0;
  -    }
  -
  -    /** Implement the write logic, calling the interceptors
  -     * and making sure the headers are sent before. This used to
  -     *	be part of BufferedServletOutputStream, but it's better
  -     *	to have it here for all output streams.
  -     */
  -    public void doWrite(Request req, Response res, byte buf[], int off, int cnt )
  -	throws IOException
  -    {
  -	if (!res.isBufferCommitted()) {
  -	    res.endHeaders();
  -	}
  -	if( cnt>0 ) {
  -	    doBeforeCommit( req, res );
  -
  -	    res.doWrite( buf, off, cnt );
  -	}
  -    }
  -    
  -    int doPreService( Request req, Response res ) {
  -	BaseInterceptor reqI[]= getRequestInterceptors(req);
  -
  -	for( int i=0; i< reqI.length; i++ ) {
  -	    reqI[i].preService( req, res );
  -	}
  -	return 0;
  -    }
  -
  -    int doPostService( Request req, Response res ) {
  -	BaseInterceptor reqI[]= getRequestInterceptors(req);
  -
  -	for( int i=0; i< reqI.length; i++ ) {
  -	    reqI[i].postService( req, res );
  -	}
  -	return 0;
  -    }
  -
  -    int doPostRequest( Request req, Response res ) {
  -	BaseInterceptor reqI[]= getRequestInterceptors(req);
  -
  -	for( int i=0; i< reqI.length; i++ ) {
  -	    reqI[i].postRequest( req, res );
  -	}
  -	return 0;
  -    }
  -
  -    int doNewSessionRequest( Request req, Response res ) {
  -	BaseInterceptor reqI[]= getRequestInterceptors(req);
   
  -	for( int i=0; i< reqI.length; i++ ) {
  -	    reqI[i].newSessionRequest( req, res );
  -	}
  -	return 0;
  -    }
  -
  -    /** Call afterBody callbacks. It is called after the servlet finished
  -	sending the response ( either closeing the stream or ending ). You
  -	can deal with connection reuse or do other actions
  -    */
  -    int doAfterBody( Request req, Response res ) {
  -	BaseInterceptor reqI[]= getRequestInterceptors(req);
  -
  -	for( int i=0; i< reqI.length; i++ ) {
  -	    reqI[i].afterBody( req, res );
  -	}
  -	return 0;
  -    }
  -
       // -------------------- Sub-Request mechanism --------------------
   
       /** Create a new sub-request in a given context, set the context "hint"
  @@ -1105,7 +1007,6 @@
       }
   
       // -------------------- Logging and debug --------------------
  -    boolean firstLog = true;
       Log loghelper = new Log("tc_log", "ContextManager");
   
       /**
  @@ -1134,10 +1035,7 @@
       public void addLogger(Logger l) {
   	if (debug>20)
   	    log("addLogger: " + l, new Throwable("trace"), Logger.DEBUG);
  -	// Will use this later once I feel more sure what I want to do here.
  -	// -akv
  -	// firstLog=false;
  -	//	if("tc_log".equals( logger.getName()) cmLog=logger;
  +
   	String path=l.getPath();
   	if( path!=null ) {
   	    File f=new File( path );
  @@ -1150,16 +1048,6 @@
   	l.open();
       }
   
  -    public void setDebug( int level ) {
  -	if( level != debug )
  -	    log( "Setting debug level to " + level);
  -	debug=level;
  -    }
  -
  -    public int getDebug() {
  -	return debug;
  -    }
  -
       public final void log(String msg) {
   	loghelper.log(msg);
       }
  @@ -1178,12 +1066,7 @@
   
       // -------------------- Accounting --------------------
       // XXX Can be implemented as note !
  -    public static final int ACC_INIT_START=0;
  -    public static final int ACC_INIT_END=0;
  -    public static final int ACCOUNTS=7;
   
  -    Counters cntr=new Counters(ACCOUNTS);
  -
       public Counters getCounters() {
   	return cntr;
       }
  @@ -1251,15 +1134,6 @@
       private Hashtable contexts = new Hashtable();
   
       /**
  -     * Get the names of all the contexts in this server.
  -     * @deprecated Path is not "unique key".
  -     */
  -    public Enumeration getContextNames() {
  -	loghelper.log("getContextNames is deprecated", new Throwable("trace"), Logger.DEBUG);
  -        return contexts.keys();
  -    }
  -
  -    /**
        * Gets a context by it's name, or <code>null</code> if there is
        * no such context.
        *
  @@ -1307,54 +1181,81 @@
   	Context context = (Context)contexts.get(name);
   	removeContext( context);
       }
  +
   
  -    public void doPreServletDestroy(Context ctx, Handler sw)
  +    // -------------------- Hook support --------------------
  +    public void doReload( Request req, Context context )
   	throws TomcatException
       {
  -	BaseInterceptor cI[]=getContextInterceptors(ctx);
  +	if( context==null ) return;
  +
  +	if( debug>0 ) log( "Reloading context " + context.toString());
  +
  +	BaseInterceptor cI[]=getInterceptors(context.getContainer());
   	for( int i=0; i< cI.length; i++ ) {
  -	    try {
  -		cI[i].preServletDestroy( ctx, sw );
  -	    } catch( TomcatException ex) {
  -		log("preServletDestroy", ex);
  -	    }
  +	    cI[i].reload(  req, context );
   	}
       }
   
  -    public void doPostServletDestroy(Context ctx, Handler sw)
  -	throws TomcatException
  -    {
  -	BaseInterceptor cI[]=getContextInterceptors(ctx);
  -	for( int i=0; i< cI.length; i++ ) {
  -	    try {
  -		cI[i].postServletDestroy( ctx, sw );
  -	    } catch( TomcatException ex) {
  -		log("postServletDestroy", ex);
  +
  +    /** Call all authentication callbacks. If any of them is able to
  +	identify the user it will set the principal in req.
  +     */
  +    public int doAuthenticate( Request req, Response res ) {
  +	int status=0;
  +	BaseInterceptor reqI[]= req.getContext().getContainer().
  +	    getInterceptors(Container.H_authenticate);
  +	for( int i=0; i< reqI.length; i++ ) {
  +	    status=reqI[i].authenticate( req, res );
  +	    if ( status != 0 ) {
  +		if( debug>0) log( "Authenticate status " + status );
  +		return status;
   	    }
   	}
  +	return 0;
       }
   
  -    /** @deprecated
  +    /** Call all authorization callbacks. The "require valid user" attributes
  +	are probably set during the mapping stage ( for efficiency), but it
  +	can be done here too.
        */
  -    public void setTomcatHome( String s ) {
  -	log ("setTomcatHome(String) is deprecated", new Throwable("trace"), Logger.DEBUG);
  -	setInstallDir( s );
  -    }
  +    public int doAuthorize( Request req, Response res, String roles[] ) {
  +	int status=0;
  +	BaseInterceptor reqI[]= req.getContext().getContainer().
  +	    getInterceptors(Container.H_authorize);
   
  -    /** @deprecated
  -     */
  -    public String getTomcatHome() {
  -	log ("getTomcatHome() is deprecated", new Throwable("trace"), Logger.DEBUG);
  -	return getInstallDir();
  +	for( int i=0; i< reqI.length; i++ ) {
  +	    status = reqI[i].authorize( req, res, roles );
  +	    if ( status != 0 ) {
  +		if( debug>0) log( "Authorize status " + status );
  +		return status;
  +	    }
  +	}
  +	return 0;
       }
   
  -    /** Default container
  +    
  +    /** Implement the write logic, calling the interceptors
  +     * and making sure the headers are sent before. This used to
  +     *	be part of BufferedServletOutputStream, but it's better
  +     *	to have it here for all output streams.
        */
  -    public Container getContainer() {
  -        return defaultContainer;
  -    }
  +    public void doWrite(Request req, Response res, byte buf[], int off, int cnt )
  +	throws IOException
  +    {
  +	if (!res.isBufferCommitted()) {
  +	    res.endHeaders();
  +	}
  +	if( cnt>0 ) {
  +	    // call the beforeCommit callback
  +	    BaseInterceptor reqI[]= getInterceptors(req,
  +						    Container.H_beforeCommit);
   
  -    public void setContainer(Container newDefaultContainer) {
  -        defaultContainer = newDefaultContainer;
  +	    for( int i=0; i< reqI.length; i++ ) {
  +		reqI[i].beforeCommit( req, res );
  +	    }
  +
  +	    res.doWrite( buf, off, cnt );
  +	}
       }
   }
  
  
  
  1.18      +21 -26    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Handler.java	2000/09/30 05:01:35	1.17
  +++ Handler.java	2000/10/01 06:37:45	1.18
  @@ -121,6 +121,7 @@
       public void setContext( Context context) {
           this.context = context;
   	contextM=context.getContextManager();
  +	loghelper.setLogger(context.getLog().getLogger());
       }
   
       public Context getContext() {
  @@ -290,8 +291,14 @@
   	    }
   	}
   
  -	if( ! internal )
  -	    contextM.doPreService( req, res );
  +	BaseInterceptor reqI[]=
  +	    contextM.getInterceptors(req, Container.H_postService);
  +
  +	if( ! internal ) {
  +	    for( int i=0; i< reqI.length; i++ ) {
  +		reqI[i].preService( req, res );
  +	    }
  +	}
   	
   	Throwable t=null;
   	try {
  @@ -301,23 +308,16 @@
   	}
   	
   	// continue with the postService
  -	if( ! internal )
  -	    contextM.doPostService( req, res );
  +	if( ! internal ) {
  +	    for( int i=0; i< reqI.length; i++ ) {
  +		reqI[i].postService( req, res );
  +	    }
  +	}
   
   	if( t==null ) return;
   	contextM.handleError( req, res, t );
       }
   
  -//     protected void handleError( Request req, Response res, Throwable t) {
  -// 	if( t==null)  return;
  -	
  -// 	contextM.handleError( req, res, t );
  -//     }
  -    
  -    public String toString() {
  -	return name;
  -    }
  -
       // -------------------- Origin 
       /** Who created this servlet definition - default is 0, i.e. the
   	web.xml mapping. It can also be the Invoker, the admin ( by using a
  @@ -336,6 +336,10 @@
   
       // -------------------- Debug --------------------
   
  +    public String toString() {
  +	return name;
  +    }
  +
       Log loghelper = new Log("tc_log", this);
       
       public void setDebug( int d ) {
  @@ -343,14 +347,10 @@
       }
   
       protected void log( String s ) {
  -	if (context != null)
  -	    loghelper.setLogger(context.getLog().getLogger());
   	loghelper.log(s);
       }
   
       protected void log( String s, Throwable t ) {
  -	if (context != null)
  -	    loghelper.setLogger(context.getLog().getLogger());
   	loghelper.log(s, t);
       }
   
  @@ -371,21 +371,16 @@
       public static final int ACC_IN_INCLUDE=5;
       
       public static final int ACCOUNTS=6;
  -    long accTable[]=new long[ACCOUNTS];
   
  -    public void setAccount( int pos, long value ) {
  -	accTable[pos]=value;
  -    }
  +    private Counters cntr=new Counters( ACCOUNTS );
   
  -    public long getAccount( int pos ) {
  -	return accTable[pos];
  +    public final Counters getCounters() {
  +	return cntr;
       }
   
       // -------------------- Notes
       Object notes[]=new Object[ContextManager.MAX_NOTES];
   
  -    /** See ContextManager comments.
  -     */
       public void setNote( int pos, Object value ) {
   	notes[pos]=value;
       }
  
  
  
  1.66      +18 -2     jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
  
  Index: Request.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- Request.java	2000/09/30 04:03:43	1.65
  +++ Request.java	2000/10/01 06:37:45	1.66
  @@ -364,7 +364,18 @@
       public String getRemoteUser() {
   	if( notAuthenticated ) {
   	    notAuthenticated=false;
  -	    contextM.doAuthenticate(this, response);
  +
  +	    int status=0;
  +	    BaseInterceptor reqI[]= context.getContainer().
  +		getInterceptors(Container.H_authenticate);
  +	    for( int i=0; i< reqI.length; i++ ) {
  +		status=reqI[i].authenticate( this, response );
  +		if ( status != 0 ) {
  +		    break;
  +		}
  +	    }
  +
  +	    //contextM.doAuthenticate(this, response);
   	    // 	    context.log("Auth " + remoteUser );
   	}
   	return remoteUser;
  @@ -519,7 +530,12 @@
   
   	if( ! create ) return null;
   
  -	contextM.doNewSessionRequest( this, response );
  +	BaseInterceptor reqI[]= contextM.
  +	    getInterceptors(this, Container.H_newSessionRequest);
  +
  +	for( int i=0; i< reqI.length; i++ ) {
  +	    reqI[i].newSessionRequest( this, response );
  +	}
   
   	if ( serverSession == null ) {
   	    return null;
  
  
  
  1.39      +18 -14    jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- Response.java	2000/09/29 21:09:35	1.38
  +++ Response.java	2000/10/01 06:37:46	1.39
  @@ -194,7 +194,13 @@
   
       public void finish() throws IOException {
           oBuffer.close();
  -	request.getContextManager().doAfterBody(request, this);
  +	ContextManager cm=request.getContextManager();
  +	BaseInterceptor reqI[]= cm.
  +	    getInterceptors(request, Container.H_afterBody);
  +
  +	for( int i=0; i< reqI.length; i++ ) {
  +	    reqI[i].afterBody( request, this );
  +	}
       }
   
       public boolean containsHeader(String name) {
  @@ -369,22 +375,20 @@
   
   	// let CM notify interceptors and give a chance to fix
   	// the headers
  -	if(request.getContext() != null && ! included ) 
  -	    request.getContext().getContextManager().doBeforeBody(request, this);
  +	if(request.getContext() != null && ! included ) {
  +	    // call before body hooks
  +	    ContextManager cm=request.getContext().getContextManager();
  +
  +	    BaseInterceptor reqI[]= cm.
  +		getInterceptors(request, Container.H_beforeBody);
   
  +	    for( int i=0; i< reqI.length; i++ ) {
  +		reqI[i].beforeBody( request, this );
  +	    }
  +	}
  +	
   	// No action.. 
       }
  -
  -//     public void addUserCookie(Object cookie) {
  -// 	if( ! included ) userCookies.addElement(cookie);
  -//     }
  -
  -//     /** All cookies set explicitely by users with addCookie()
  -//      *  - I'm not sure if it's used or needed
  -//      */
  -//     public Enumeration getUserCookies() {
  -// 	return userCookies.elements();
  -//     }
   
       public Locale getLocale() {
           return locale;
  
  
  
  1.6       +4 -4      jakarta-tomcat/src/share/org/apache/tomcat/helper/ServerXmlHelper.java
  
  Index: ServerXmlHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/helper/ServerXmlHelper.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServerXmlHelper.java	2000/09/29 07:01:07	1.5
  +++ ServerXmlHelper.java	2000/10/01 06:37:49	1.6
  @@ -94,7 +94,7 @@
   	xh.addRule( "ContextManager/ContextInterceptor",
   		    xh.setParent("setContextManager") );
   	xh.addRule( "ContextManager/ContextInterceptor",
  -		    xh.addChild( "addContextInterceptor",
  +		    xh.addChild( "addInterceptor",
   				 "org.apache.tomcat.core.BaseInterceptor"));
   
   	xh.addRule( "ContextManager/RequestInterceptor",
  @@ -104,7 +104,7 @@
   	xh.addRule( "ContextManager/RequestInterceptor",
   		    xh.setParent("setContextManager") );
   	xh.addRule( "ContextManager/RequestInterceptor",
  -		    xh.addChild( "addRequestInterceptor",
  +		    xh.addChild( "addInterceptor",
   				 "org.apache.tomcat.core.BaseInterceptor"));
   
   	// Default host
  @@ -123,7 +123,7 @@
   	xh.addRule( "ContextManager/Context/RequestInterceptor",
   		    xh.setParent("setContext") );
   	xh.addRule( "ContextManager/Context/RequestInterceptor",
  -		    xh.addChild( "addRequestInterceptor",
  +		    xh.addChild( "addInterceptor",
   				 "org.apache.tomcat.core.BaseInterceptor"));
   	
   	// Virtual host support.
  @@ -177,7 +177,7 @@
   		    xh.setParent( "setContextManager",
   				  "org.apache.tomcat.core.ContextManager") );
   	xh.addRule( "ContextManager/Connector",
  -		    xh.addChild( "addContextInterceptor",
  +		    xh.addChild( "addInterceptor",
   				 "org.apache.tomcat.core.BaseInterceptor"));
   
   	xh.addRule( "ContextManager/Connector/Parameter",
  
  
  
  1.22      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java
  
  Index: StaticInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- StaticInterceptor.java	2000/09/30 04:03:46	1.21
  +++ StaticInterceptor.java	2000/10/01 06:37:50	1.22
  @@ -108,7 +108,6 @@
   	DirHandler dirHandler=new DirHandler();
   	fileHandler.setNoteId( realFileNote );
   	dirHandler.setNoteId( realFileNote );
  -	debug=0;
   	ctx.addServlet( fileHandler );
   	if (listings)
   	    ctx.addServlet( dirHandler );
  @@ -130,6 +129,7 @@
   	String absPath=FileUtil.safePath( ctx.getAbsolutePath(),
   					  pathInfo);
   
  +	if( debug > -1 ) log( "RequestMap " + req + " " + absPath + " " + ctx.getAbsolutePath() );
   	if( absPath == null ) return 0;
   	String requestURI=req.getRequestURI();
   
  
  
  
  1.28      +20 -32    jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java
  
  Index: EmbededTomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- EmbededTomcat.java	2000/09/29 07:01:38	1.27
  +++ EmbededTomcat.java	2000/10/01 06:37:50	1.28
  @@ -38,7 +38,6 @@
       Object application;
       // null == not set up
       Vector requestInt=null;
  -    Vector contextInt=null;
       /** Right now we assume all web apps use the same
   	servlet API version. This will change after we
   	finish the FacadeManager implementation
  @@ -74,7 +73,7 @@
   
   	// In our case the adapter must be BaseInterceptor.
   	if ( adapter instanceof BaseInterceptor ) {
  -	    addRequestInterceptor( (BaseInterceptor)adapter);
  +	    addInterceptor( (BaseInterceptor)adapter);
   	}
       }
   
  @@ -110,7 +109,7 @@
   	
   	//	sc.setTcpConnectionHandler( new HttpConnectionHandler());
   	
  -	contextM.addRequestInterceptor(  sc );
  +	contextM.addInterceptor(  sc );
       }
   
       /** Add a secure web service.
  @@ -134,7 +133,7 @@
   	// sc.setTcpConnectionHandler( hc );
   	// XXX add the secure socket
   	
  -	contextM.addRequestInterceptor(  sc );
  +	contextM.addInterceptor(  sc );
       }
   
       // -------------------- Context add/remove --------------------
  @@ -289,32 +288,21 @@
       }
       
       // -------------------- Private methods
  -    public void addRequestInterceptor( BaseInterceptor ri ) {
  +    public void addInterceptor( BaseInterceptor ri ) {
   	if( requestInt == null ) requestInt=new Vector();
   	requestInt.addElement( ri );
   	if( ri instanceof BaseInterceptor )
   	    ((BaseInterceptor)ri).setDebug( debug );
       }
  -    public void addContextInterceptor( BaseInterceptor ci ) {
  -	if( contextInt == null ) contextInt=new Vector();
  -	contextInt.addElement( ci );
  -	if( ci instanceof BaseInterceptor )
  -	    ((BaseInterceptor)ci).setDebug( debug );
  -    }
   
       private void initContextManager() {
   	if(requestInt==null)  initDefaultInterceptors();
   	contextM=new ContextManager();
   	contextM.setDebug( debug );
   	
  -	for( int i=0; i< contextInt.size() ; i++ ) {
  -	    contextM.addContextInterceptor( (BaseInterceptor)
  -					    contextInt.elementAt( i ) );
  -	}
  -
   	for( int i=0; i< requestInt.size() ; i++ ) {
  -	    contextM.addRequestInterceptor( (BaseInterceptor)
  -					    requestInt.elementAt( i ) );
  +	    contextM.addInterceptor( (BaseInterceptor)
  +				     requestInt.elementAt( i ) );
   	}
   
   	contextM.setWorkDir( workDir );
  @@ -341,57 +329,57 @@
   	// multiple APIs at the same time in embeded mode )
   	
   	BaseInterceptor webXmlI= (BaseInterceptor)newObject("org.apache.tomcat.facade.WebXmlReader");
  -	addContextInterceptor( webXmlI );
  +	addInterceptor( webXmlI );
   
   	PolicyInterceptor polI=new PolicyInterceptor();
  -	addContextInterceptor( polI );
  +	addInterceptor( polI );
   	polI.setDebug(0);
           
   	LoaderInterceptor12 loadI=new LoaderInterceptor12();
  -	addContextInterceptor( loadI );
  +	addInterceptor( loadI );
   
   	DefaultCMSetter defaultCMI=new DefaultCMSetter();
  -	addContextInterceptor( defaultCMI );
  +	addInterceptor( defaultCMI );
   
   	WorkDirInterceptor wdI=new WorkDirInterceptor();
  -	addContextInterceptor( wdI );
  +	addInterceptor( wdI );
   
   	
   	LoadOnStartupInterceptor loadOnSI=new LoadOnStartupInterceptor();
  -	addContextInterceptor( loadOnSI );
  +	addInterceptor( loadOnSI );
   
   	// Debug
   	// 	LogEvents logEventsI=new LogEvents();
   	// 	addRequestInterceptor( logEventsI );
   
   	SessionInterceptor sessI=new SessionInterceptor();
  -	addRequestInterceptor( sessI );
  +	addInterceptor( sessI );
   
   	SimpleMapper1 mapI=new SimpleMapper1();
  -	addRequestInterceptor( mapI );
  +	addInterceptor( mapI );
   	mapI.setDebug(0);
   
   	InvokerInterceptor invI=new InvokerInterceptor();
  -	addRequestInterceptor( invI );
  +	addInterceptor( invI );
   	invI.setDebug(0);
   	
   	StaticInterceptor staticI=new StaticInterceptor();
  -	addRequestInterceptor( staticI );
  +	addInterceptor( staticI );
   	mapI.setDebug(0);
   
  -	addRequestInterceptor( new StandardSessionInterceptor());
  +	addInterceptor( new StandardSessionInterceptor());
   	
   	// access control ( find if a resource have constraints )
   	AccessInterceptor accessI=new AccessInterceptor();
  -	addRequestInterceptor( accessI );
  +	addInterceptor( accessI );
   	accessI.setDebug(0);
   
   	// set context class loader
   	Jdk12Interceptor jdk12I=new Jdk12Interceptor();
  -	addRequestInterceptor( jdk12I );
  +	addInterceptor( jdk12I );
   
   	// xXXX
  -	//	addRequestInterceptor( new SimpleRealm());
  +	//	addInterceptor( new SimpleRealm());
       }
       
   
  
  
  
  1.20      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/task/ApacheConfig.java
  
  Index: ApacheConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/task/ApacheConfig.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ApacheConfig.java	2000/09/29 07:01:44	1.19
  +++ ApacheConfig.java	2000/10/01 06:37:51	1.20
  @@ -136,7 +136,7 @@
   
   	    // Find Ajp12 connector
   	    int portInt=8007;
  -	    BaseInterceptor ci[]=cm.getContextInterceptors();
  +	    BaseInterceptor ci[]=cm.getInterceptors();
   	    for( int i=0; i<ci.length; i++ ) {
   		Object con=ci[i];
   		if( con instanceof  Ajp12ConnectionHandler ) {
  
  
  
  1.11      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/task/StopTomcat.java
  
  Index: StopTomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/task/StopTomcat.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- StopTomcat.java	2000/09/29 07:01:47	1.10
  +++ StopTomcat.java	2000/10/01 06:37:51	1.11
  @@ -173,7 +173,7 @@
   	// Find Ajp12 connector
   	int portInt=8007;
   	InetAddress address=null;
  -	BaseInterceptor ci[]=cm.getContextInterceptors();
  +	BaseInterceptor ci[]=cm.getInterceptors();
   	for( int i=0; i<ci.length; i++ ) {
   	    Object con=ci[i];
   	    if( con instanceof  Ajp12ConnectionHandler ) {
  
  
  

3.2 Documentation Updated

Posted by "Rob S." <rs...@home.com>.
If anyone would like to dish out some criticism - constructive or otherwise!
=b - to the new(er) documentation, please do.  Prior to Larry's check-in of
the newest apache-howto, I have a copy here:

http://www.sfu.ca/~rslifka/tomcat/tomcat-apache-howto.html

There's no way that I'm dead-on with everything we've been doing to it, so
if there's anything to be said, please do!  Also, there are some comments
and questions I have delimited that could use some answers from anyone who
knows ;)

Thanks a bunch!

- r

> -----Original Message-----
> From: costin@locus.apache.org [mailto:costin@locus.apache.org]
> Sent: September 30, 2000 11:38 PM
> To: jakarta-tomcat-cvs@apache.org
> Subject: cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/task
> ApacheConfig.java StopTomcat.java
>
>
> costin      00/09/30 23:37:53
>
>   Modified:    src/facade22/org/apache/tomcat/facade
>                         Servlet22Interceptor.java ServletWrapper.java
>                src/facade23/org/apache/tomcat/facade23 ServletWrapper.java
>                src/share/org/apache/tomcat/context DefaultCMSetter.java
>                src/share/org/apache/tomcat/core BaseInterceptor.java
>                         Container.java Context.java ContextManager.java
>                         Handler.java Request.java Response.java
>                src/share/org/apache/tomcat/helper ServerXmlHelper.java
>                src/share/org/apache/tomcat/request StaticInterceptor.java
>                src/share/org/apache/tomcat/startup EmbededTomcat.java
>                src/share/org/apache/tomcat/task ApacheConfig.java
>                         StopTomcat.java
>   Log:
>   Few big changes in ContextManager.
>
>   - removed RequestInterceptors and ContextInterceptors. We only have
>   Interceptors ( no need to make distinction )
>
>   - most of the doHOOK moved next to the caller, no need to
>   call context manager to intermediate. That will also help when/if we
>   add some mechanism to define dynamic hooks.
>
>   - IMPORTANT - documented the order of startup ( at least the
> way I understand
>   it), and make sure no hooks are called until CM is initialized.
>   We still need to make sure that
>   1. No request is served until CM is in STARTED state
>   2. A context will not serve requests until it's in ACTIVE state.
>
>   - A lot of cleanup and simplifactions resulting from this ( the state of
>   ContextManager should be consistent now). For example we can move more
>   functionality in interceptors ( fixing the paths is now done in
>   DefaultCMSetter and it's much improved, etc).
>
>   So far I thought MessageBytes and OutputBuffer are the most
> important changes
>   for 3.3. Now I think making sure we have a clear definition of state
>   for CM and interceptors is much more important. Please help and review
>   ( at least the comments at the beginning of ContextManager )
>
>   Revision  Changes    Path
>   1.4       +0 -18
> jakarta-tomcat/src/facade22/org/apache/tomcat/facade/Servlet22Inte
> rceptor.java
>
>   Index: Servlet22Interceptor.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/Ser
vlet22Interceptor.java,v
>   retrieving revision 1.3
>   retrieving revision 1.4
>   diff -u -r1.3 -r1.4
>   --- Servlet22Interceptor.java	2000/09/30 04:03:33	1.3
>   +++ Servlet22Interceptor.java	2000/10/01 06:37:42	1.4
>   @@ -132,24 +132,6 @@
>
>        }
>
>   -    public Object createServletContextFacade(Context ctx) {
>   -	//if( ctx != this.ctx ) return null; // throw
>   -	return new ServletContextFacade(ctx.getContextManager() , ctx);
>   -    }
>   -
>   -
>   -    public Object createHttpServletRequestFacade(Request req) {
>   -	Context reqCtx=req.getContext();
>   -	//	if( reqCtx != ctx && reqCtx != null ) return null; // throw
>   -	return new HttpServletRequestFacade(req);
>   -    }
>   -
>   -    public Object createHttpServletResponseFacade(Response res) {
>   -	Context resCtx=res.getRequest().getContext();
>   -	//if( resCtx != ctx && resCtx != null ) return null; // throw
>   -	return new HttpServletResponseFacade(res);
>   -    }
>   -
>        public int postRequest(Request rreq, Response rres ) {
>    	//if( rreq.getContext() != ctx ) return; // throw
>
>
>
>
>   1.8       +2 -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/Ser
> vletWrapper.java,v
>   retrieving revision 1.7
>   retrieving revision 1.8
>   diff -u -r1.7 -r1.8
>   --- ServletWrapper.java	2000/09/30 04:57:51	1.7
>   +++ ServletWrapper.java	2000/10/01 06:37:42	1.8
>   @@ -252,7 +252,7 @@
>
>    	    try {
>    		if( servlet!=null) {
>   -		    BaseInterceptor
> cI[]=contextM.getContextInterceptors(context);
>   +		    BaseInterceptor
> cI[]=contextM.getInterceptors(context.getContainer());
>    		    for( int i=0; i< cI.length; i++ ) {
>    			try {
>    			    cI[i].preServletDestroy( context, this );
>   @@ -323,7 +323,7 @@
>    	//}
>
>    	// Call pre, doInit and post
>   -	BaseInterceptor cI[]=contextM.getContextInterceptors(context);
>   +	BaseInterceptor
> cI[]=contextM.getInterceptors(context.getContainer());
>    	for( int i=0; i< cI.length; i++ ) {
>    	    try {
>    		cI[i].preServletInit( context, this );
>
>
>
>   1.6       +2 -2
> jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/ServletWrapper.java
>
>   Index: ServletWrapper.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/S
> ervletWrapper.java,v
>   retrieving revision 1.5
>   retrieving revision 1.6
>   diff -u -r1.5 -r1.6
>   --- ServletWrapper.java	2000/09/30 04:57:51	1.5
>   +++ ServletWrapper.java	2000/10/01 06:37:43	1.6
>   @@ -249,7 +249,7 @@
>
>    	    try {
>    		if( servlet!=null) {
>   -		    BaseInterceptor
> cI[]=contextM.getContextInterceptors(context);
>   +		    BaseInterceptor
> cI[]=contextM.getInterceptors(context.getContainer());
>    		    for( int i=0; i< cI.length; i++ ) {
>    			try {
>    			    cI[i].preServletDestroy( context, this );
>   @@ -320,7 +320,7 @@
>    	//}
>
>    	// Call pre, doInit and post
>   -	BaseInterceptor cI[]=contextM.getContextInterceptors(context);
>   +	BaseInterceptor
> cI[]=contextM.getInterceptors(context.getContainer());
>    	for( int i=0; i< cI.length; i++ ) {
>    	    try {
>    		cI[i].preServletInit( context, this );
>
>
>
>   1.54      +68 -2
> 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/Defau
> ltCMSetter.java,v
>   retrieving revision 1.53
>   retrieving revision 1.54
>   diff -u -r1.53 -r1.54
>   --- DefaultCMSetter.java	2000/09/30 04:03:38	1.53
>   +++ DefaultCMSetter.java	2000/10/01 06:37:44	1.54
>   @@ -70,16 +70,80 @@
>
>    import org.apache.tomcat.util.log.*;
>
>   +// don't extend - replace !
>   +
>    /**
>     * Check ContextManager and set defaults for non-set properties
>     *
>     * @author costin@dnt.ro
>     */
>   -public class DefaultCMSetter extends BaseInterceptor {
>   +public final class DefaultCMSetter extends BaseInterceptor {
>
>        public DefaultCMSetter() {
>        }
>
>   +    /** Adjust context manager paths
>   +     */
>   +    public void engineInit( ContextManager cm )
>   +    	throws TomcatException
>   +    {
>   +	// Adjust paths in CM
>   +	String home=cm.getHome();
>   +	if( home==null ) {
>   +	    // try system property
>   +	    home=System.getProperty(ContextManager.TOMCAT_HOME);
>   +	}
>   +
>   +	// Make it absolute
>   +	if( home!= null ) {
>   +	    home=FileUtil.getCanonicalPath( home );
>   +	    cm.setHome( home );
>   +	    log( "Setting server home to " + home );
>   +	}
>   +
>   +
>   +	String installDir=cm.getInstallDir();
>   +	if( installDir!= null ) {
>   +	    installDir=FileUtil.getCanonicalPath( installDir );
>   +	    cm.setInstallDir( installDir );
>   +	    log( "Setting server install dir to " + installDir );
>   +	}
>   +
>   +	// if only one is set home==installDir
>   +
>   +	if( home!=null && installDir == null )
>   +	    cm.setInstallDir( home );
>   +
>   +	if( home==null && installDir != null )
>   +	    cm.setHome( installDir );
>   +
>   +	// if neither home or install is set,
>   +	// and no system property, try "."
>   +	if( home==null && installDir==null ) {
>   +	    home=FileUtil.getCanonicalPath( "." );
>   +	    installDir=home;
>   +
>   +	    cm.setHome( home );
>   +	    cm.setInstallDir( home );
>   +	}
>   +
>   +	// Adjust work dir
>   +	String workDir=cm.getWorkDir();
>   +	if( workDir==null ) {
>   +	    workDir= ContextManager.DEFAULT_WORK_DIR;
>   +	}
>   +
>   +	if( ! FileUtil.isAbsolute( workDir )) {
>   +	    workDir=FileUtil.
>   +		getCanonicalPath(home + File.separator+
>   +				 workDir);
>   +	}
>   +	cm.setWorkDir( workDir );
>   +
>   +    }
>   +
>   +    /** Adjust paths
>   +     */
>        public void addContext( ContextManager cm, Context ctx)
>    	throws TomcatException
>        {
>   @@ -98,7 +162,7 @@
>    	    }
>    	    ctx.setAbsolutePath( absPath );
>    	}
>   -
>   +	log( ctx.getPath() + " " + docBase + " " + absPath + " "
> +cm.getHome());
>
>    	// this would belong to a logger interceptor ?
>    	Log loghelper=ctx.getLog();
>   @@ -111,6 +175,8 @@
>    	    cm.addLogger( loghelperServlet.getLogger() );
>        }
>
>   +    /** Add default error handlers
>   +     */
>        public void contextInit( Context ctx)
>    	throws TomcatException
>        {
>
>
>
>   1.23      +11 -3
> jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java
>
>   Index: BaseInterceptor.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInte
> rceptor.java,v
>   retrieving revision 1.22
>   retrieving revision 1.23
>   diff -u -r1.22 -r1.23
>   --- BaseInterceptor.java	2000/09/30 04:03:39	1.22
>   +++ BaseInterceptor.java	2000/10/01 06:37:44	1.23
>   @@ -208,8 +208,12 @@
>
>        /** Called before the first body write, and before sending
>         *  the headers. The interceptor have a chance to change the
>   -     *  output headers.
>   -     */
>   +     *  output headers.
>   +     *
>   +     *  Before body allows you do do various
>   +     *	actions before the first byte of the response is
> sent. After all
>   +     *  those callbacks are called tomcat may send the status
> and headers
>   +    */
>        public int beforeBody( Request rrequest, Response response ) {
>    	return 0;
>        }
>   @@ -233,7 +237,11 @@
>
>        /** Called after the output stream is closed ( either by servlet
>         *  or automatically at end of service ).
>   -     */
>   +     *
>   +     * It is called after the servlet finished
>   +     * sending the response ( either closeing the stream or
> ending ). You
>   +     * can deal with connection reuse or do other actions
>   +    */
>        public int afterBody( Request request, Response response) {
>    	return 0;
>        }
>
>
>
>   1.36      +18 -136
> jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java
>
>   Index: Container.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Container.java,v
>   retrieving revision 1.35
>   retrieving revision 1.36
>   diff -u -r1.35 -r1.36
>   --- Container.java	2000/09/30 04:57:56	1.35
>   +++ Container.java	2000/10/01 06:37:44	1.36
>   @@ -408,7 +408,7 @@
>        BaseInterceptor hooks[][]=new BaseInterceptor[MAX_HOOKS][];
>
>        // used internally
>   -    Vector getLocalInterceptors(int hookId) {
>   +    private Vector getLocalInterceptors(int hookId) {
>    	if( interceptors[hookId]==null )
>    	    interceptors[hookId]=new Vector();
>    	return interceptors[hookId];
>   @@ -418,7 +418,7 @@
>    	in
>        */
>        public void addInterceptor( BaseInterceptor bi ) {
>   -	for( int i=0; i< PREDEFINED_I.length; i++ ) {
>   +	for( int i=0; i< PREDEFINED_I.length -1 ; i++ ) {
>    	    if( bi.hasHook( PREDEFINED_I[i] )) {
>    		if( interceptors[i]==null )
>    		    interceptors[i]=new Vector();
>   @@ -426,6 +426,12 @@
>    		interceptors[i].addElement( bi );
>    	    }
>    	}
>   +	// last position just gets all interceptors
>   +	// ( to be used for context-level hooks )
>   +	if( interceptors[H_engineInit]==null )
>   +	    interceptors[H_engineInit]=new Vector();
>   +
>   +	interceptors[ H_engineInit ].addElement( bi );
>        }
>
>        // make sure we reset the cache.
>   @@ -450,7 +456,7 @@
>    	if( hooks[type] != null ) {
>    	    return hooks[type];
>    	}
>   -	if( dL>0 )
>   +	if( dL>5 )
>    	    debug("create hooks for " + type + " " + PREDEFINED_I[type]);
>
>    	Container globalIntContainer=getContextManager().getContainer();
>   @@ -466,152 +472,28 @@
>
>    	for ( int i = 0 ; i < gsize ; i++ ){
>    	    hooks[type][i]=(BaseInterceptor)globals.elementAt(i);
>   -	    if( dL > 0 ) debug( "Add " + i + " " + hooks[type][i]);
>   +	    if( dL > 5 ) debug( "Add " + i + " " + hooks[type][i]);
>    	}
>    	for ( int i = 0 ; i < lsize  ; i++ ){
>    	    hooks[type][gsize+i]=(BaseInterceptor)locals.elementAt(i);
>   -	    if( dL > 0 ) debug( "Add " + i + " " + hooks[type][i+gsize]);
>   +	    if( dL > 5 ) debug( "Add " + i + " " + hooks[type][i+gsize]);
>    	}
>
>    	return hooks[type];
>        }
>   -
>   -
>   -    // -------------------- Old code handling interceptors
>   -    // DEPRECATED ( after the new code is tested )
>
>   -    /** Per/container interceptors.
>   +    /** Get all interceptors
>         */
>   -    Vector contextInterceptors=new Vector();
>   -    Vector requestInterceptors=new Vector();
>   -
>   -    // interceptor cache - avoid Vector enumeration
>   -    BaseInterceptor cInterceptors[];
>   -    BaseInterceptor rInterceptors[];
>   -    BaseInterceptor rCachedRequestInterceptors[]={};
>   -    BaseInterceptor rCachedContextInterceptors[]={};
>   -
>   -    /** Add a per/container context interceptor. It will be notified
>   -     *  of all context events happening inside this container.
>   -     *   XXX incomplete implementation
>   -     */
>   -    public void addContextInterceptor( BaseInterceptor ci) {
>   -	addInterceptor( (BaseInterceptor) ci );
>   -        // XXX will be deprecated when hooks end testing
>   -	contextInterceptors.addElement( ci );
>   -    }
>   -
>   -    /** Add a per/container request interceptor. It will be
> called back for
>   -     *  all operations for requests that are mapped to this container.
>   -     *  Note that all global interceptors will be called first.
>   -     *   XXX incomplete implementation.
>   -     */
>   -    public void addRequestInterceptor( BaseInterceptor ri) {
>   -	addInterceptor( (BaseInterceptor) ri );
>   -        // XXX will be deprecated when hooks end testing
>   -	requestInterceptors.addElement( ri );
>   -	if( ri instanceof BaseInterceptor )
>   -	        contextInterceptors.addElement( ri );
>   -    }
>   -
>   -    // -------------------- Getting the active interceptors
>   -
>   -    /** Return the context interceptors as an array.
>   -     *	For performance reasons we use an array instead of
>   -     *  returning the vector - the interceptors will not change at
>   -     *	runtime and array access is faster and easier than vector
>   -     *	access
>   -     */
>   -    public BaseInterceptor[] getContextInterceptors() {
>   -	if( cInterceptors == null ||
>   -	    cInterceptors.length != contextInterceptors.size()) {
>   -	    cInterceptors=new BaseInterceptor[contextInterceptors.size()];
>   -	    for( int i=0; i<cInterceptors.length; i++ ) {
>   -		cInterceptors[i]=(BaseInterceptor)contextInterceptors.
>   -		    elementAt(i);
>   -	    }
>   -	}
>   -	return cInterceptors;
>   -    }
>   -
>   -    /** Return the context interceptors as an array.
>   -	For performance reasons we use an array instead of
>   -	returning the vector - the interceptors will not change at
>   -	runtime and array access is faster and easier than vector
>   -	access
>   -    */
>   -    public BaseInterceptor[] getRequestInterceptors() {
>   -	if( rInterceptors == null ||
>   -	    rInterceptors.length != requestInterceptors.size())
>   -	{
>   -	    rInterceptors=new BaseInterceptor[requestInterceptors.size()];
>   -	    for( int i=0; i<rInterceptors.length; i++ ) {
>   -		rInterceptors[i]=(BaseInterceptor)requestInterceptors.
>   -		    elementAt(i);
>   -	    }
>   -	}
>   -	return rInterceptors;
>   -    }
>   -
>   -    /** Return all interceptors for this container ( local and
>   -	global )
>   -    */
>   -    public BaseInterceptor[] getCachedRequestInterceptors()
>   +    public BaseInterceptor[] getInterceptors()
>        {
>   -	BaseInterceptor[] ari=rCachedRequestInterceptors;
>   -
>   -	if (ari.length == 0){
>   -            BaseInterceptor[] cri=this.getRequestInterceptors();
>   -            BaseInterceptor[] gri=getContextManager()
>   -		.getRequestInterceptors();
>   -            if  (cri!=null && cri.length > 0) {
>   -                int al=cri.length+gri.length;
>   -                ari=new BaseInterceptor[al];
>   -                int i;
>   -                for ( i = 0 ; i < gri.length ; i++ ){
>   -                    ari[i]=gri[i];
>   -                }
>   -                for (int j = 0 ; j < cri.length ; j++ ){
>   -                    ari[i+j]=cri[j];
>   -                }
>   -            } else {
>   -                ari=gri;
>   -            }
>   -            rCachedRequestInterceptors=ari;
>   -        }
>   -        return rCachedRequestInterceptors;
>   +	// We don't check for "hasHook", so all
>   +	// interceptors are available here
>   +	return getInterceptors( H_engineInit );
>        }
>
>   -    /** Return all interceptors for this container ( local and
>   -	global )
>   -    */
>   -    public BaseInterceptor[] getCachedContextInterceptors()
>   -    {
>   -	BaseInterceptor[] aci=rCachedContextInterceptors;
>   -	if (aci.length == 0){
>   -            BaseInterceptor[] cci=this.getContextInterceptors();
>   -            BaseInterceptor[] gci=getContextManager().
>   -		getContextInterceptors();
>   -            if  (cci!=null && cci.length > 0) {
>   -                int al=cci.length+gci.length;
>   -                aci=new BaseInterceptor[al];
>   -                int i;
>   -                for ( i = 0 ; i < gci.length ; i++ ){
>   -                    aci[i]=gci[i];
>   -                }
>   -                for (int j = 0 ; j < cci.length ; j++ ){
>   -                    aci[i+j]=cci[j];
>   -                }
>   -            } else {
>   -                aci=gci;
>   -            }
>   -            rCachedContextInterceptors=aci;
>   -        }
>   -	return rCachedContextInterceptors;
>   -    }
>   -
>   +
>        // debug
>   -    public static final int dL=0;
>   +    public static final int dL=4;
>        private void debug( String s ) {
>    	System.out.println("Container: " + s );
>        }
>
>
>
>   1.124     +22 -12
> jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
>
>   Index: Context.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
>   retrieving revision 1.123
>   retrieving revision 1.124
>   diff -u -r1.123 -r1.124
>   --- Context.java	2000/09/30 04:03:39	1.123
>   +++ Context.java	2000/10/01 06:37:44	1.124
>   @@ -284,15 +284,18 @@
>    	map.setHandler( sw );
>    	map.setPath( path );
>
>   -	// callback - hooks are called.
>   -	contextM.addContainer( map );
>   +	// Notify interceptors that a new container is added
>   +	BaseInterceptor cI[]=contextM.getInterceptors(map);
>   +	for( int i=0; i< cI.length; i++ ) {
>   +	    cI[i].addContainer( map );
>   +	}
>
>    	sw = getServletByName(servletName);
>
>
>    	if (sw == null) {
>    	    // web.xml validation - a mapping with no servlet rollback
>   -	    contextM.removeContainer( map );
>   +	    removeContainer( map );
>     	    throw new TomcatException( "Mapping with invalid servlet  " +
>    				       path + " " + servletName );
>    	}
>   @@ -327,7 +330,12 @@
>    	    // XXX check if exists, merge if true.
>    	    constraints.put( path[i], ct );
>    	    //contextM.addSecurityConstraint( this, path[i], ct);
>   -	    contextM.addContainer(  ct );
>   +
>   +	    // Notify interceptors that a new container is added
>   +	    BaseInterceptor cI[]=contextM.getInterceptors(ct);
>   +	    for( int j=0; j< cI.length; j++ ) {
>   +		cI[j].addContainer( ct );
>   +	    }
>    	}
>        }
>
>   @@ -753,8 +761,16 @@
>
>        /** Remove a container
>         */
>   -    public final  void removeContainer( Container ct ) {
>   +    public final  void removeContainer( Container ct )
>   +	throws TomcatException
>   +    {
>    	containers.remove(ct.getPath());
>   +
>   +	// notify modules that a container was removed
>   +	BaseInterceptor cI[]=contextM.getInterceptors(ct);
>   +	for( int i=0; i< cI.length; i++ ) {
>   +	    cI[i].removeContainer( ct );
>   +	}
>        }
>
>        // -------------------- Servlets management --------------------
>   @@ -1011,13 +1027,7 @@
>         *	known at that time
>         */
>        public final  void addInterceptor( BaseInterceptor ri ) {
>   -        defaultContainer.addRequestInterceptor(ri);
>   +        defaultContainer.addInterceptor(ri);
>        }
>
>   -
>   -    // -------------------- Deprecated --------------------
>   -
>   -    public final  void addRequestInterceptor( BaseInterceptor ri ) {
>   -        addInterceptor( ri );
>   -    }
>    }
>
>
>
>   1.141     +384 -483
> 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/ContextM
> anager.java,v
>   retrieving revision 1.140
>   retrieving revision 1.141
>   diff -u -r1.140 -r1.141
>   --- ContextManager.java	2000/09/30 04:57:56	1.140
>   +++ ContextManager.java	2000/10/01 06:37:45	1.141
>   @@ -70,34 +70,105 @@
>    import java.util.*;
>
>    /**
>   - * ContextManager is the entry point and "controler" of the
> servlet execution.
>   - * It maintains a list of WebApplications and a list of global event
>   - * interceptors that are set up to handle the actual execution.
>   - *
>   - * The ContextManager will direct the request processing flow
>   - * from its arrival from the server/protocl adapter ( in service() ).
>   - * It will do that by calling a number of hooks implemented by
> Interceptors.
>   - *
>   - * Hooks are provided for request parsing and mapping, auth,
> autorization,
>   - * pre/post service, actual invocation and logging.
>   - *
>   - * ContextManager will also store properties that are global
> to the servlet
>   - * container - like root directory, install dir, work dir.
>   - *
>   - * The extension mechanism for tomcat is the Interceptor.
>   - * This class is final - if you need to change certain functionality
>   - * you should add a new hook.
>   - *
>   - * ContextManager is not a singleton - it represent a servlet container
>   - * instance ( with all associated ports and configurations ).
>   - * One application may try to embed multiple ( distinct )
> servlet containers -
>   - * this feature hasn't been tested or used
>   - *
>   - * @author James Duncan Davidson [duncan@eng.sun.com]
>   - * @author James Todd [gonzo@eng.sun.com]
>   - * @author Harish Prabandham
>   - * @author costin@eng.sun.com
>   - * @author Hans Bergsten [hans@gefionsoftware.com]
>   +  ContextManager is the entry point and "controler" of the
> servlet execution.
>   +  It maintains a list of WebApplications and a list of global event
>   +  interceptors that are set up to handle the actual execution.
>   +
>   +  The ContextManager will direct the request processing flow
>   +  from its arrival from the server/protocl adapter ( in service() ).
>   +  It will do that by calling a number of hooks implemented by
> Interceptors.
>   +
>   +  Hooks are provided for request parsing and mapping, auth,
> autorization,
>   +  pre/post service, actual invocation and logging.
>   +
>   +  ContextManager will also store properties that are global to
> the servlet
>   +  container - like root directory, install dir, work dir.
>   +
>   +  The extension mechanism for tomcat is the Interceptor.
>   +  This class is final - if you need to change certain functionality
>   +  you should add a new hook.
>   +
>   +  ContextManager is not a singleton - it represent a servlet container
>   +  instance ( with all associated ports and configurations ).
>   +  One application may try to embed multiple ( distinct )
> servlet containers -
>   +  this feature hasn't been tested or used
>   +
>   +
>   +   Expected startup order:
>   +
>   +  1. Create ContextManager
>   +
>   +  2. Set settable properties for ContextManager ( home, debug, etc)
>   +
>   +  3. Add global Interceptors
>   +
>   +  4. You may create, set and add Contexts. NO HOOKS ARE CALLED.
>   +
>   +  5. Call init(). At this stage engineInit() callback will be
>   +     called for all global interceptors.
>   +     - DefaultCMSetter ( or a replacement ) must be the first in
>   +     the chain and will adjust the paths and set defaults for
>   +     all unset properties.
>   +     - AutoSetup and other interceptors can automatically add/set
>   +     more properties and make other calls.
>   +
>   +     During engineInit() a number of Contexts are created and
>   +     added to the server. No addContext() callback is called until
>   +     the last engineInit() returns. ( XXX do we need this
> restriction ?)
>   +
>   +  XXX I'n not sure about contextInit and about anything below.
>   +
>   +  x. Server will move to INITIALIZED state. No callback other
> than engineInit
>   +     can be called before the server enters this state.
>   +
>   +  x. addContext() callbacks will be called for each context.
>   +     After init you may add more contexts, and addContext() callback
>   +     will be called (since the server is initialized )
>   +
>   +  x. Call start().
>   +
>   +  x. All contexts will be initialized ( contextInit()
>   +     callback ).
>   +
>   +  x. Server will move to STARTED state. No servlet should be
>   +     served before this state.
>   +
>   +
>   +     During normal operation, it is possible to add  Contexts.
>   +
>   +  1. Create the Context, set properties ( that can be done
> from servlets
>   +     or by interceptors like ~user)
>   +
>   +  2. call CM.addContext(). This will triger the addContext() callback.
>   +     ( if CM is initialized )
>   +
>   +  3. call CM.initContext( ctx ). This will triger
> contextInit() callback.
>   +     After that the context is initialized and can serve requests.
>   +     No request belonging to this context can't be served before this
>   +     method returns.
>   +
>   +     XXX Context state
>   +
>   +     It is also possible to remove Contexts.
>   +
>   +  1. Find the Context ( enumerate all existing contexts and
> find the one
>   +    you need - host and path are most likely keys ).
>   +
>   +  2. Call removeContext(). This will call removeContext() callbacks.
>   +
>   +
>   +     To stop the server, you need to:
>   +
>   +  1. Call shutdown().
>   +
>   +  2. The server will ...
>   +
>   +
>   +  @author James Duncan Davidson [duncan@eng.sun.com]
>   +  @author James Todd [gonzo@eng.sun.com]
>   +  @author Harish Prabandham
>   +  @author costin@eng.sun.com
>   +  @author Hans Bergsten [hans@gefionsoftware.com]
>     */
>    public final class ContextManager implements LogAware{
>        /** Official name and version
>   @@ -105,46 +176,73 @@
>        public static final String TOMCAT_VERSION = "3.3 dev";
>        public static final String TOMCAT_NAME = "Tomcat Web Server";
>
>   +    /** Property used to set the random number generator
>   +     */
>   +    public static final String RANDOM_CLASS_PROPERTY=
>   +	"tomcat.sessionid.randomclass";
>   +
>   +    /** Property used to set the base directory ( tomcat home )
>   +     */
>   +    public static final String TOMCAT_HOME=
>   +	"tomcat.home";
>   +
>   +    /** Default work dir, relative to home
>   +     */
>   +    public static final String DEFAULT_WORK_DIR="work";
>   +
>   +    // Accounting
>   +    /** time when init() started
>   +     */
>   +    public static final int ACC_INIT_START=0;
>   +    /** Time when init() finished()
>   +     */
>   +    public static final int ACC_INIT_END=1;
>   +    public static final int ACCOUNTS=2;
>   +
>   +    // State
>   +    public static final int STATE_INITIAL=0;
>   +    public static final int STATE_INITIALIZED=1;
>   +    public static final int STATE_STARTED=2;
>   +    public static final int STATE_STOPED=3;
>   +
>   +    // -------------------- local variables --------------------
>   +
>   +    private int state=STATE_INITIAL;
>   +
>        /** Contexts managed by this server
>         */
>        private Vector contextsV=new Vector();
>
>   -    int debug=0;
>   +    private int debug=0;
>
>        // Global properties for this tomcat instance:
>
>        /** Private workspace for this server
>         */
>   -    String workDir;
>   +    private String workDir;
>
>        /** The base directory where this instance runs.
>         *  It can be different from the install directory to
>         *  allow one install per system and multiple users
>         */
>   -    String home;
>   +    private String home;
>
>        /** The directory where tomcat is installed
>         */
>   -    String installDir;
>   +    private String installDir;
>
>   -    /** Property used to set the random number generator
>   -     */
>   -    public static final String RANDOM_CLASS_PROPERTY=
>   -	"tomcat.sessionid.randomclass";
>
>   -    /** Default work dir, relative to home
>   -     */
>   -    public static final String DEFAULT_WORK_DIR="work";
>   -
>   -    Container defaultContainer;
>   +    private Container defaultContainer;
>
>        // the application loader. ContextManager is loaded with
>        // a class loader containing tomcat-specific classes,
>        // use parent loader to avoid polution
>   -    ClassLoader parentLoader;
>   +    private ClassLoader parentLoader;
>        // tomcat classes ( used to load tomcat)
>   -    URL serverClassPath[];
>   +    private URL serverClassPath[];
>
>   +    private Counters cntr=new Counters(ACCOUNTS);
>   +
>        /**
>         * Construct a new ContextManager instance with default values.
>         */
>   @@ -154,135 +252,10 @@
>    	defaultContainer.setContextManager( this );
>            defaultContainer.setPath( null ); // default container
>        }
>   -
>   -    // -------------------- setable properties: tomcat directories  ---
>   -    /**
>   -     *  The home of the tomcat instance - you can have multiple
>   -     *  users running tomcat, with a shared install directory.
>   -     *  Every instance will have its own logs, webapps directory
>   -     *  and local config, all relative to this directory.
>   -     */
>   -    public void setHome(String home) {
>   -	this.home=FileUtil.getCanonicalPath( home );
>   -	log( "Setting home to " + this.home );
>   -    }
>   -
>   -    /**
>   -     *  The home of the tomcat instance - you can have multiple
>   -     *  users running tomcat, with a shared install directory.
>   -     *  Every instance will have its own logs, webapps directory
>   -     *  and local config, all relative to this directory.
>   -     *
>   -     *  If no home is configured we'll try the install dir
>   -     *  XXX clean up the order and process of guessing - maybe we can
>   -     *  just throw error instead of guessing wrong.
>   -     */
>   -    public String getHome() {
>   -	if(home!=null) return home;
>   -
>   -	// If none defined, assume tomcat.home is used as base.
>   -	if( installDir != null )
>   -	    home=FileUtil.getCanonicalPath( installDir );
>   -
>   -	if(home!=null) return home;
>
>   -	// try at least the system property
>   -	home=FileUtil.getCanonicalPath( System.getProperty("tomcat.home") );
>   -	if(home!=null) return home;
>   +    // -------------------- Server functions --------------------
>
>   -	home=FileUtil.getCanonicalPath( "." );
>   -	// try current dir - we should throw an exception
>   -	return home;
>   -    }
>   -
>   -    /** Get installation directory, where libraries and default files
>   -     *	are located.  If path specified is relative,
>   -     *  evaluate it relative to the current working directory.
>   -     */
>   -    public String getInstallDir() {
>   -	if(installDir!= null) return installDir;
>   -
>   -	installDir=System.getProperty("tomcat.home");
>   -	if(installDir!= null) return installDir;
>   -
>   -	// If the property is not set ( for example JNI worker ) assume
>   -	// at least home is set up corectly.
>   -	installDir=getHome();
>   -	return installDir;
>   -    }
>   -
>   -    /** Set installation directory, where libraries and default files
>   -     *	are located.  If path specified is relative,
>   -     *  evaluate it relative to the current working directory.
>   -     */
>   -    public void setInstallDir( String tH ) {
>   -	installDir=tH;
>   -    }
>   -
>        /**
>   -     * WorkDir property - where all working files will be created
>   -     */
>   -    public void setWorkDir( String wd ) {
>   -	if(debug>0) log("set work dir " + wd);
>   -	this.workDir=FileUtil.getCanonicalPath( getHome() +
> File.separator + wd );
>   -    }
>   -
>   -    /**
>   -     * WorkDir property - where all working files will be created
>   -     */
>   -    public String getWorkDir() {
>   -	if( workDir==null)
>   -	    workDir=FileUtil.getCanonicalPath(getHome() +
> File.separator + DEFAULT_WORK_DIR);
>   -	return workDir;
>   -    }
>   -
>   -    /** Parent loader is the "base" class loader of the
>   -     *	application that starts tomcat, and includes no
>   -     *	tomcat classes. All servlet loaders will have it as
>   -     *  a parent loader, as if the webapps would be loaded
>   -     *  by the embeding app ( using parentLoader ).
>   -     *
>   -     *  Tomcat will add servlet.jar and any other extension
>   -     *  it is configured to - for example trusted webapps
>   -     *  may have tomcat internal classes in classpath.
>   -     */
>   -    public void setParentLoader( ClassLoader cl ) {
>   -	parentLoader=cl;
>   -    }
>   -
>   -    public ClassLoader getParentLoader() {
>   -	return parentLoader;
>   -    }
>   -
>   -    public URL[] getServerClassPath() {
>   -	if( serverClassPath==null ) return new URL[0];
>   -	return serverClassPath;
>   -    }
>   -
>   -    public void setServerClassPath( URL urls[] ) {
>   -	serverClassPath=urls;
>   -    }
>   -
>   -    /** Get the name of the class to be used for generating
> random numbers by
>   -     * the session id generator. By default this is
>   -     *  <code>java.security.SecureRandom</code>.
>   -     **/
>   -    public String getRandomClass() {
>   -        String randomClass = System.getProperty(RANDOM_CLASS_PROPERTY);
>   -        return randomClass == null ?
> "java.security.SecureRandom" : randomClass;
>   -    }
>   -
>   -    /** Sets the name of the class used for generating random
> numbers by the
>   -     *  session id generator.
>   -     */
>   -    public void setRandomClass(String randomClass) {
>   -        System.setProperty(RANDOM_CLASS_PROPERTY, randomClass);
>   -    }
>   -
>   -
>   -    // -------------------- Support functions --------------------
>   -
>   -    /**
>         *  Init() is called after the context manager is set up
>         *  and configured ( all setFoo methods are called, all initial
>         *  interceptors are added and their setters are called ).
>   @@ -299,24 +272,23 @@
>
>    	cntr.touchCounter( ACC_INIT_START );
>
>   -	BaseInterceptor cI[]=getContextInterceptors();
>   +	BaseInterceptor cI[]=getInterceptors();
>    	for( int i=0; i< cI.length; i++ ) {
>    	    cI[i].engineInit( this );
>    	}
>
>   -    	// init contexts
>   -	Enumeration enum = getContexts();
>   -	while (enum.hasMoreElements()) {
>   -	    Context context = (Context)enum.nextElement();
>   -	    try {
>   -		initContext( context );
>   -	    } catch (TomcatException ex ) {
>   -		if( context!=null ) {
>   -		    log( "ERROR initializing " + context.toString(), ex );
>   -		    removeContext( context  );
>   -		}
>   +	state=STATE_INITIALIZED;
>   +
>   +	Enumeration existingCtxE=contextsV.elements();
>   +	while( existingCtxE.hasMoreElements() ) {
>   +	    Context ctx=(Context)existingCtxE.nextElement();
>   +
>   +	    cI=getInterceptors(ctx.getContainer());
>   +	    for( int i=0; i< cI.length; i++ ) {
>   +		cI[i].addContext( this, ctx );
>    	    }
>    	}
>   +
>    	cntr.touchCounter( ACC_INIT_END);
>        }
>
>   @@ -329,7 +301,7 @@
>    	    removeContext((Context)enum.nextElement());
>    	}
>
>   -	BaseInterceptor cI[]=getContextInterceptors();
>   +	BaseInterceptor cI[]=getInterceptors();
>    	for( int i=0; i< cI.length; i++ ) {
>    	    cI[i].engineShutdown( this );
>    	}
>   @@ -346,10 +318,6 @@
>         * or after the admin adds a new context.
>         */
>        public void initContext( Context ctx ) throws TomcatException {
>   -	BaseInterceptor cI[]=getContextInterceptors(ctx);
>   -	for( int i=0; i< cI.length; i++ ) {
>   -	    cI[i].contextInit( ctx );
>   -	}
>        }
>
>        /** Stop the context and release all resources.
>   @@ -372,7 +340,7 @@
>    	    }
>    	}
>
>   -	BaseInterceptor cI[]=getContextInterceptors(ctx);
>   +	BaseInterceptor cI[]=getInterceptors(ctx.getContainer());
>    	for( int i=0; i< cI.length; i++ ) {
>    	    cI[i].contextShutdown( ctx );
>    	}
>   @@ -385,6 +353,25 @@
>         *  case we should add a new hook
>         */
>        public void start() throws Exception {
>   +    	// init contexts
>   +	Enumeration enum = getContexts();
>   +	while (enum.hasMoreElements()) {
>   +	    Context ctx = (Context)enum.nextElement();
>   +	    try {
>   +		BaseInterceptor cI[]=getInterceptors(ctx.getContainer());
>   +		for( int i=0; i< cI.length; i++ ) {
>   +		    cI[i].contextInit( ctx );
>   +		}
>   +	    } catch (TomcatException ex ) {
>   +		if( ctx!=null ) {
>   +		    log( "ERROR initializing " + ctx.toString(), ex );
>   +		    removeContext( ctx  );
>   +		}
>   +	    }
>   +	}
>   +	// Note that contextInit() will triger other
>   +
>   +	state=STATE_STARTED;
>        }
>
>        /** Will stop all connectors
>   @@ -393,7 +380,125 @@
>    	shutdown();
>        }
>
>   +    // -------------------- setable properties --------------------
>   +
>   +    /**
>   +     *  The home of the tomcat instance - you can have multiple
>   +     *  users running tomcat, with a shared install directory.
>   +     *
>   +     *  Home is used as a base for logs, webapps, local config.
>   +     *  Install dir ( if different ) is used to find lib ( jar
>   +     *   files ).
>   +     *
>   +     *  The "tomcat.home" system property is used if no explicit
>   +     *  value is set.
>   +     */
>   +    public void setHome(String home) {
>   +	this.home=home;
>   +    }
>   +
>   +    public String getHome() {
>   +	return home;
>   +    }
>   +
>   +    /**
>   +     *  Get installation directory. This is used to locate
>   +     *  jar files ( lib ). If tomcat instance is shared,
>   +     *  home is used for webapps, logs, config.
>   +     *  If either home or install is not set, the other
>   +     *  is used as default.
>   +     *
>   +     */
>   +    public String getInstallDir() {
>   +	return installDir;
>   +    }
>   +
>   +    public void setInstallDir( String tH ) {
>   +	installDir=tH;
>   +    }
>   +
>   +    /**
>   +     * WorkDir property - where all working files will be created
>   +     */
>   +    public void setWorkDir( String wd ) {
>   +	if(debug>0) log("set work dir " + wd);
>   +	this.workDir=wd;
>   +    }
>   +
>   +    public String getWorkDir() {
>   +	return workDir;
>   +    }
>   +
>   +    /** Sets the name of the class used for generating random
> numbers by the
>   +     *  session id generator. By default this is
> <code>java.security.SecureRandom</code>.
>   +     */
>   +    public void setRandomClass(String randomClass) {
>   +        System.setProperty(RANDOM_CLASS_PROPERTY, randomClass);
>   +    }
>   +
>   +    public String getRandomClass() {
>   +        String randomClass = System.getProperty(RANDOM_CLASS_PROPERTY);
>   +        return randomClass == null ?
> "java.security.SecureRandom" : randomClass;
>   +    }
>   +
>   +    /** Debug level
>   +     */
>   +    public void setDebug( int level ) {
>   +	if( level != debug )
>   +	    log( "Setting debug level to " + level);
>   +	debug=level;
>   +    }
>   +
>   +    public int getDebug() {
>   +	return debug;
>   +    }
>   +
>   +    // -------------------- Other properties --------------------
>   +
>   +    public int getState() {
>   +	return state;
>   +    }
>   +
>   +    /**
>   +     *  Parent loader is the "base" class loader of the
>   +     *	application that starts tomcat, and includes no
>   +     *	tomcat classes. All servlet loaders will have it as
>   +     *  a parent loader, as if the webapps would be loaded
>   +     *  by the embeding app ( using parentLoader ).
>   +     *
>   +     *  Tomcat will add servlet.jar and any other extension
>   +     *  it is configured to - for example trusted webapps
>   +     *  may have tomcat internal classes in classpath.
>   +     */
>   +    public void setParentLoader( ClassLoader cl ) {
>   +	parentLoader=cl;
>   +    }
>   +
>   +    public ClassLoader getParentLoader() {
>   +	return parentLoader;
>   +    }
>   +
>   +    public URL[] getServerClassPath() {
>   +	if( serverClassPath==null ) return new URL[0];
>   +	return serverClassPath;
>   +    }
>   +
>   +    public void setServerClassPath( URL urls[] ) {
>   +	serverClassPath=urls;
>   +    }
>   +
>   +    /** Default container
>   +     */
>   +    public Container getContainer() {
>   +        return defaultContainer;
>   +    }
>   +
>   +    public void setContainer(Container newDefaultContainer) {
>   +        defaultContainer = newDefaultContainer;
>   +    }
>   +
>        // -------------------- Contexts --------------------
>   +
>        /** Return the list of contexts managed by this server
>         */
>        public Enumeration getContexts() {
>   @@ -407,28 +512,25 @@
>         */
>        public void addContext( Context ctx ) throws TomcatException {
>    	log("Adding context " +  ctx.toString());
>   -
>    	// Make sure context knows about its manager.
>    	ctx.setContextManager( this );
>
>    	// If the context already exist - the interceptors need
>    	// to deal with that ( either replace or throw an exception ).
>   +
>   +	contextsV.addElement( ctx );
>   +	// XXX temporary workaround for the old SimpleMapper -
>
>   -	// The mapping alghoritm may use more than path and host -
>   -	// if not now, then in future.
>   +	// XXX hack - should be removed
>   +	if( ctx.getHost() ==null ) contexts.put( ctx.getPath(), ctx );
>
>   -	BaseInterceptor cI[]=getContextInterceptors(ctx);
>   +	if( state == STATE_INITIAL )
>   +	    return;
>   +
>   +	BaseInterceptor cI[]=getInterceptors(ctx.getContainer());
>    	for( int i=0; i< cI.length; i++ ) {
>    	    cI[i].addContext( this, ctx );
>    	}
>   -
>   -	String vhost=ctx.getHost();
>   -
>   -	// XXX temporary workaround for the old SimpleMapper -
>   -	// This code will be removed as soon as the new mapper is stable.
>   -	if( vhost ==null ) // the old mapper will support only
> "default" server
>   -	    contexts.put( ctx.getPath(), ctx );
>   -	contextsV.addElement( ctx );
>        }
>
>        /** Shut down and removes a context from service
>   @@ -438,7 +540,7 @@
>
>    	log( "Removing context " + context.toString());
>
>   -	BaseInterceptor cI[]=getContextInterceptors(context);
>   +	BaseInterceptor cI[]=getInterceptors(context.getContainer());
>    	for( int i=0; i< cI.length; i++ ) {
>    	    cI[i].removeContext( this, context );
>    	}
>   @@ -448,79 +550,27 @@
>    	contexts.remove(context.getPath());
>        }
>
>   -    public void doReload( Request req, Context context )
>   -	throws TomcatException
>   -    {
>   -	if( context==null ) return;
>
>   -	if( debug>0 ) log( "Reloading context " + context.toString());
>   -
>   -	BaseInterceptor cI[]=getContextInterceptors(context);
>   -	for( int i=0; i< cI.length; i++ ) {
>   -	    cI[i].reload(  req, context );
>   -	}
>   -    }
>   -
>   -
>   -    /** Notify interceptors that a new container was added.
>   -     */
>   -    public void addContainer( Container container )
>   -    	throws TomcatException
>   -    {
>   -	BaseInterceptor cI[]=getContextInterceptors(container);
>   -	for( int i=0; i< cI.length; i++ ) {
>   -	    cI[i].addContainer( container);
>   -	}
>   -    }
>   -
>   -    /** Notify interceptors that a container was removed.
>   -     */
>   -    public void removeContainer( Container container )
>   -	throws TomcatException
>   -    {
>   -	BaseInterceptor cI[]=getContextInterceptors(container);
>   -	for( int i=0; i< cI.length; i++ ) {
>   -	    cI[i].removeContainer( container);
>   -	}
>   -    }
>   -
>        // -------------------- Interceptors --------------------
>        // The interceptors are handled per/container ( thanks to Nacho
>   -    // for this contribution ). We just delegate to the right
>   -    // container ( in future we should remove this, and use the
>   -    // right objects )
>   +    // for this contribution ).
>
>   -    public void addRequestInterceptor( BaseInterceptor ri ) {
>   -        defaultContainer.addRequestInterceptor(ri);
>   +    public void addInterceptor( BaseInterceptor ri ) {
>   +        defaultContainer.addInterceptor(ri);
>        }
>
>   -    /** Return all the interceptors associated with a request.
>   -	That includes global ( context manager ) interceptors,
>   -	webapp ( Context ) interceptors and possibly interceptors
>   -	associated with containers ( urls inside the web app ).
>   -
>   -	For performance reasons we use arrays and cache the result inside
>   -	containers.
>   -
>   -	XXX Todo:
>   -	Dynamic add of interceptors is not supported.
>   -    */
>   -    public BaseInterceptor[] getRequestInterceptors( Request req ) {
>   -        Context ctx=req.getContext();
>   -        // if Bad request (ctx == null) only global
> interceptors are called
>   -        if( ctx == null )
>   -           return getRequestInterceptors();
>   -        Container ct=ctx.getContainer();
>   -        BaseInterceptor[] ari=ct.getCachedRequestInterceptors();
>   -
>   -	return ari;
>   +    public BaseInterceptor[] getInterceptors() {
>   +	return defaultContainer.getInterceptors();
>        }
>   -
>   -    public BaseInterceptor[] getRequestInterceptorszz( Request req ,
>   -						       int hook_id)
>   +
>   +    public BaseInterceptor[] getInterceptors( Container ct ) {
>   +	return ct.getInterceptors();
>   +    }
>   +
>   +    public BaseInterceptor[] getInterceptors( Request req ,
>   +					      int hook_id)
>        {
>            Context ctx=req.getContext();
>   -        // if Bad request (ctx == null) only global
> interceptors are called
>            if( ctx == null )
>               return defaultContainer.getInterceptors(hook_id);
>            Container ct=ctx.getContainer();
>   @@ -529,26 +579,6 @@
>    	return ari;
>        }
>
>   -    public BaseInterceptor[] getRequestInterceptors() {
>   -	return defaultContainer.getRequestInterceptors();
>   -    }
>   -
>   -    public void addContextInterceptor( BaseInterceptor ci) {
>   -        defaultContainer.addContextInterceptor(ci);
>   -    }
>   -
>   -    public BaseInterceptor[] getContextInterceptors() {
>   -	return defaultContainer.getContextInterceptors();
>   -    }
>   -
>   -    public BaseInterceptor[] getContextInterceptors(Container ct) {
>   -        BaseInterceptor[] aci=ct.getCachedContextInterceptors();
>   -	return aci;
>   -    }
>   -
>   -    public BaseInterceptor[] getContextInterceptors(Context ctx) {
>   -        return getContextInterceptors(ctx.getContainer());
>   -    }
>        // -------------------- Request processing / subRequest
> ------------------
>        // -------------------- Main request processing methods
> ------------------
>
>   @@ -580,7 +610,12 @@
>    	    handleError( req, res, ex );
>    	}
>    	finally {
>   -	    doPostRequest(req, res);
>   +	    BaseInterceptor reqI[]= getInterceptors(req,
>   +
> Container.H_postRequest);
>   +
>   +	    for( int i=0; i< reqI.length; i++ ) {
>   +		reqI[i].postRequest( req, res );
>   +	    }
>    	    req.recycle();
>    	    res.recycle();
>    	}
>   @@ -636,12 +671,6 @@
>    	}
>        }
>
>   -    static int contextMap_ID=Container.getHookId( "contextMap");
>   -    static int requestMap_ID=Container.getHookId( "requestMap");
>   -    static int authorize_ID=Container.getHookId( "authorize");
>   -    static int authenticate_ID=Container.getHookId( "authenticate");
>   -
>   -
>        /** Will find the Handler for a servlet, assuming we already have
>         *  the Context. This is also used by Dispatcher and getResource -
>         *  where the Context is already known.
>   @@ -651,15 +680,17 @@
>
>    	int status=0;
>            BaseInterceptor ri[];
>   -	ri=defaultContainer.getInterceptors(contextMap_ID);
>   +	ri=defaultContainer.getInterceptors(Container.H_contextMap);
>
>    	for( int i=0; i< ri.length; i++ ) {
>    	    status=ri[i].contextMap( req );
>    	    if( status!=0 ) return status;
>    	}
>
>   -	ri=defaultContainer.getInterceptors( requestMap_ID);
>   +	ri=defaultContainer.getInterceptors(Container.H_requestMap);
>    	for( int i=0; i< ri.length; i++ ) {
>   +	    if( debug > 1 )
>   +		log( "RequestMap " + ri[i] );
>    	    status=ri[i].requestMap( req );
>    	    if( status!=0 ) return status;
>    	}
>   @@ -669,136 +700,7 @@
>    	return 0;
>        }
>
>   -    /** Call all authentication callbacks. If any of them is able to
>   -	identify the user it will set the principal in req.
>   -     */
>   -    public int doAuthenticate( Request req, Response res ) {
>   -	int status=0;
>   -//	RequestInterceptor reqI[]= getRequestInterceptors(req);
>   -	BaseInterceptor reqI[]=
> req.getContext().getContainer().getInterceptors(authenticate_ID);
>   -	for( int i=0; i< reqI.length; i++ ) {
>   -	    status=reqI[i].authenticate( req, res );
>   -	    if ( status != 0 ) {
>   -		if( debug>0) log( "Authenticate status " + status );
>   -		return status;
>   -	    }
>   -	}
>   -	return 0;
>   -    }
>   -
>   -    /** Call all authorization callbacks. The "require valid
> user" attributes
>   -	are probably set during the mapping stage ( for efficiency), but it
>   -	can be done here too.
>   -     */
>   -    public int doAuthorize( Request req, Response res, String
> roles[] ) {
>   -	int status=0;
>   -//	RequestInterceptor reqI[]= getRequestInterceptors(req);
>   -	BaseInterceptor reqI[]=
> req.getContext().getContainer().getInterceptors(authorize_ID);
>   -
>   -	for( int i=0; i< reqI.length; i++ ) {
>   -	    status = reqI[i].authorize( req, res, roles );
>   -	    if ( status != 0 ) {
>   -		if( debug>0) log( "Authorize status " + status );
>   -		return status;
>   -	    }
>   -	}
>   -	return 0;
>   -    }
>   -
>   -    /** Call beforeBody callbacks. Before body allows you do do various
>   -	actions before the first byte of the response is sent. After all
>   -	those callbacks are called tomcat may send the status and headers
>   -    */
>   -    int doBeforeBody( Request req, Response res ) {
>   -	BaseInterceptor reqI[]= getRequestInterceptors(req);
>   -
>   -	for( int i=0; i< reqI.length; i++ ) {
>   -	    reqI[i].beforeBody( req, res );
>   -	}
>   -	return 0;
>   -    }
>   -
>   -    /** Call beforeCommit callbacks. This allows interceptors
> to manipulate the
>   -	buffer before it gets sent.
>   -	XXX Add a standard way to access the body. The method was
> not used too
>   -	much, we need a review and maybe change in parameters.
>   -    */
>   -    int doBeforeCommit( Request req, Response res ) {
>   -	BaseInterceptor reqI[]= getRequestInterceptors(req);
>   -
>   -	for( int i=0; i< reqI.length; i++ ) {
>   -	    reqI[i].beforeCommit( req, res );
>   -	}
>   -	return 0;
>   -    }
>   -
>   -    /** Implement the write logic, calling the interceptors
>   -     * and making sure the headers are sent before. This used to
>   -     *	be part of BufferedServletOutputStream, but it's better
>   -     *	to have it here for all output streams.
>   -     */
>   -    public void doWrite(Request req, Response res, byte buf[],
> int off, int cnt )
>   -	throws IOException
>   -    {
>   -	if (!res.isBufferCommitted()) {
>   -	    res.endHeaders();
>   -	}
>   -	if( cnt>0 ) {
>   -	    doBeforeCommit( req, res );
>   -
>   -	    res.doWrite( buf, off, cnt );
>   -	}
>   -    }
>   -
>   -    int doPreService( Request req, Response res ) {
>   -	BaseInterceptor reqI[]= getRequestInterceptors(req);
>   -
>   -	for( int i=0; i< reqI.length; i++ ) {
>   -	    reqI[i].preService( req, res );
>   -	}
>   -	return 0;
>   -    }
>   -
>   -    int doPostService( Request req, Response res ) {
>   -	BaseInterceptor reqI[]= getRequestInterceptors(req);
>   -
>   -	for( int i=0; i< reqI.length; i++ ) {
>   -	    reqI[i].postService( req, res );
>   -	}
>   -	return 0;
>   -    }
>   -
>   -    int doPostRequest( Request req, Response res ) {
>   -	BaseInterceptor reqI[]= getRequestInterceptors(req);
>   -
>   -	for( int i=0; i< reqI.length; i++ ) {
>   -	    reqI[i].postRequest( req, res );
>   -	}
>   -	return 0;
>   -    }
>   -
>   -    int doNewSessionRequest( Request req, Response res ) {
>   -	BaseInterceptor reqI[]= getRequestInterceptors(req);
>
>   -	for( int i=0; i< reqI.length; i++ ) {
>   -	    reqI[i].newSessionRequest( req, res );
>   -	}
>   -	return 0;
>   -    }
>   -
>   -    /** Call afterBody callbacks. It is called after the
> servlet finished
>   -	sending the response ( either closeing the stream or ending ). You
>   -	can deal with connection reuse or do other actions
>   -    */
>   -    int doAfterBody( Request req, Response res ) {
>   -	BaseInterceptor reqI[]= getRequestInterceptors(req);
>   -
>   -	for( int i=0; i< reqI.length; i++ ) {
>   -	    reqI[i].afterBody( req, res );
>   -	}
>   -	return 0;
>   -    }
>   -
>        // -------------------- Sub-Request mechanism --------------------
>
>        /** Create a new sub-request in a given context, set the
> context "hint"
>   @@ -1105,7 +1007,6 @@
>        }
>
>        // -------------------- Logging and debug --------------------
>   -    boolean firstLog = true;
>        Log loghelper = new Log("tc_log", "ContextManager");
>
>        /**
>   @@ -1134,10 +1035,7 @@
>        public void addLogger(Logger l) {
>    	if (debug>20)
>    	    log("addLogger: " + l, new Throwable("trace"), Logger.DEBUG);
>   -	// Will use this later once I feel more sure what I want to do here.
>   -	// -akv
>   -	// firstLog=false;
>   -	//	if("tc_log".equals( logger.getName()) cmLog=logger;
>   +
>    	String path=l.getPath();
>    	if( path!=null ) {
>    	    File f=new File( path );
>   @@ -1150,16 +1048,6 @@
>    	l.open();
>        }
>
>   -    public void setDebug( int level ) {
>   -	if( level != debug )
>   -	    log( "Setting debug level to " + level);
>   -	debug=level;
>   -    }
>   -
>   -    public int getDebug() {
>   -	return debug;
>   -    }
>   -
>        public final void log(String msg) {
>    	loghelper.log(msg);
>        }
>   @@ -1178,12 +1066,7 @@
>
>        // -------------------- Accounting --------------------
>        // XXX Can be implemented as note !
>   -    public static final int ACC_INIT_START=0;
>   -    public static final int ACC_INIT_END=0;
>   -    public static final int ACCOUNTS=7;
>
>   -    Counters cntr=new Counters(ACCOUNTS);
>   -
>        public Counters getCounters() {
>    	return cntr;
>        }
>   @@ -1251,15 +1134,6 @@
>        private Hashtable contexts = new Hashtable();
>
>        /**
>   -     * Get the names of all the contexts in this server.
>   -     * @deprecated Path is not "unique key".
>   -     */
>   -    public Enumeration getContextNames() {
>   -	loghelper.log("getContextNames is deprecated", new
> Throwable("trace"), Logger.DEBUG);
>   -        return contexts.keys();
>   -    }
>   -
>   -    /**
>         * Gets a context by it's name, or <code>null</code> if there is
>         * no such context.
>         *
>   @@ -1307,54 +1181,81 @@
>    	Context context = (Context)contexts.get(name);
>    	removeContext( context);
>        }
>   +
>
>   -    public void doPreServletDestroy(Context ctx, Handler sw)
>   +    // -------------------- Hook support --------------------
>   +    public void doReload( Request req, Context context )
>    	throws TomcatException
>        {
>   -	BaseInterceptor cI[]=getContextInterceptors(ctx);
>   +	if( context==null ) return;
>   +
>   +	if( debug>0 ) log( "Reloading context " + context.toString());
>   +
>   +	BaseInterceptor cI[]=getInterceptors(context.getContainer());
>    	for( int i=0; i< cI.length; i++ ) {
>   -	    try {
>   -		cI[i].preServletDestroy( ctx, sw );
>   -	    } catch( TomcatException ex) {
>   -		log("preServletDestroy", ex);
>   -	    }
>   +	    cI[i].reload(  req, context );
>    	}
>        }
>
>   -    public void doPostServletDestroy(Context ctx, Handler sw)
>   -	throws TomcatException
>   -    {
>   -	BaseInterceptor cI[]=getContextInterceptors(ctx);
>   -	for( int i=0; i< cI.length; i++ ) {
>   -	    try {
>   -		cI[i].postServletDestroy( ctx, sw );
>   -	    } catch( TomcatException ex) {
>   -		log("postServletDestroy", ex);
>   +
>   +    /** Call all authentication callbacks. If any of them is able to
>   +	identify the user it will set the principal in req.
>   +     */
>   +    public int doAuthenticate( Request req, Response res ) {
>   +	int status=0;
>   +	BaseInterceptor reqI[]= req.getContext().getContainer().
>   +	    getInterceptors(Container.H_authenticate);
>   +	for( int i=0; i< reqI.length; i++ ) {
>   +	    status=reqI[i].authenticate( req, res );
>   +	    if ( status != 0 ) {
>   +		if( debug>0) log( "Authenticate status " + status );
>   +		return status;
>    	    }
>    	}
>   +	return 0;
>        }
>
>   -    /** @deprecated
>   +    /** Call all authorization callbacks. The "require valid
> user" attributes
>   +	are probably set during the mapping stage ( for efficiency), but it
>   +	can be done here too.
>         */
>   -    public void setTomcatHome( String s ) {
>   -	log ("setTomcatHome(String) is deprecated", new
> Throwable("trace"), Logger.DEBUG);
>   -	setInstallDir( s );
>   -    }
>   +    public int doAuthorize( Request req, Response res, String
> roles[] ) {
>   +	int status=0;
>   +	BaseInterceptor reqI[]= req.getContext().getContainer().
>   +	    getInterceptors(Container.H_authorize);
>
>   -    /** @deprecated
>   -     */
>   -    public String getTomcatHome() {
>   -	log ("getTomcatHome() is deprecated", new
> Throwable("trace"), Logger.DEBUG);
>   -	return getInstallDir();
>   +	for( int i=0; i< reqI.length; i++ ) {
>   +	    status = reqI[i].authorize( req, res, roles );
>   +	    if ( status != 0 ) {
>   +		if( debug>0) log( "Authorize status " + status );
>   +		return status;
>   +	    }
>   +	}
>   +	return 0;
>        }
>
>   -    /** Default container
>   +
>   +    /** Implement the write logic, calling the interceptors
>   +     * and making sure the headers are sent before. This used to
>   +     *	be part of BufferedServletOutputStream, but it's better
>   +     *	to have it here for all output streams.
>         */
>   -    public Container getContainer() {
>   -        return defaultContainer;
>   -    }
>   +    public void doWrite(Request req, Response res, byte buf[],
> int off, int cnt )
>   +	throws IOException
>   +    {
>   +	if (!res.isBufferCommitted()) {
>   +	    res.endHeaders();
>   +	}
>   +	if( cnt>0 ) {
>   +	    // call the beforeCommit callback
>   +	    BaseInterceptor reqI[]= getInterceptors(req,
>   +
> Container.H_beforeCommit);
>
>   -    public void setContainer(Container newDefaultContainer) {
>   -        defaultContainer = newDefaultContainer;
>   +	    for( int i=0; i< reqI.length; i++ ) {
>   +		reqI[i].beforeCommit( req, res );
>   +	    }
>   +
>   +	    res.doWrite( buf, off, cnt );
>   +	}
>        }
>    }
>
>
>
>   1.18      +21 -26
> 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.17
>   retrieving revision 1.18
>   diff -u -r1.17 -r1.18
>   --- Handler.java	2000/09/30 05:01:35	1.17
>   +++ Handler.java	2000/10/01 06:37:45	1.18
>   @@ -121,6 +121,7 @@
>        public void setContext( Context context) {
>            this.context = context;
>    	contextM=context.getContextManager();
>   +	loghelper.setLogger(context.getLog().getLogger());
>        }
>
>        public Context getContext() {
>   @@ -290,8 +291,14 @@
>    	    }
>    	}
>
>   -	if( ! internal )
>   -	    contextM.doPreService( req, res );
>   +	BaseInterceptor reqI[]=
>   +	    contextM.getInterceptors(req, Container.H_postService);
>   +
>   +	if( ! internal ) {
>   +	    for( int i=0; i< reqI.length; i++ ) {
>   +		reqI[i].preService( req, res );
>   +	    }
>   +	}
>
>    	Throwable t=null;
>    	try {
>   @@ -301,23 +308,16 @@
>    	}
>
>    	// continue with the postService
>   -	if( ! internal )
>   -	    contextM.doPostService( req, res );
>   +	if( ! internal ) {
>   +	    for( int i=0; i< reqI.length; i++ ) {
>   +		reqI[i].postService( req, res );
>   +	    }
>   +	}
>
>    	if( t==null ) return;
>    	contextM.handleError( req, res, t );
>        }
>
>   -//     protected void handleError( Request req, Response res,
> Throwable t) {
>   -// 	if( t==null)  return;
>   -
>   -// 	contextM.handleError( req, res, t );
>   -//     }
>   -
>   -    public String toString() {
>   -	return name;
>   -    }
>   -
>        // -------------------- Origin
>        /** Who created this servlet definition - default is 0, i.e. the
>    	web.xml mapping. It can also be the Invoker, the admin ( by using a
>   @@ -336,6 +336,10 @@
>
>        // -------------------- Debug --------------------
>
>   +    public String toString() {
>   +	return name;
>   +    }
>   +
>        Log loghelper = new Log("tc_log", this);
>
>        public void setDebug( int d ) {
>   @@ -343,14 +347,10 @@
>        }
>
>        protected void log( String s ) {
>   -	if (context != null)
>   -	    loghelper.setLogger(context.getLog().getLogger());
>    	loghelper.log(s);
>        }
>
>        protected void log( String s, Throwable t ) {
>   -	if (context != null)
>   -	    loghelper.setLogger(context.getLog().getLogger());
>    	loghelper.log(s, t);
>        }
>
>   @@ -371,21 +371,16 @@
>        public static final int ACC_IN_INCLUDE=5;
>
>        public static final int ACCOUNTS=6;
>   -    long accTable[]=new long[ACCOUNTS];
>
>   -    public void setAccount( int pos, long value ) {
>   -	accTable[pos]=value;
>   -    }
>   +    private Counters cntr=new Counters( ACCOUNTS );
>
>   -    public long getAccount( int pos ) {
>   -	return accTable[pos];
>   +    public final Counters getCounters() {
>   +	return cntr;
>        }
>
>        // -------------------- Notes
>        Object notes[]=new Object[ContextManager.MAX_NOTES];
>
>   -    /** See ContextManager comments.
>   -     */
>        public void setNote( int pos, Object value ) {
>    	notes[pos]=value;
>        }
>
>
>
>   1.66      +18 -2
> jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
>
>   Index: Request.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
>   retrieving revision 1.65
>   retrieving revision 1.66
>   diff -u -r1.65 -r1.66
>   --- Request.java	2000/09/30 04:03:43	1.65
>   +++ Request.java	2000/10/01 06:37:45	1.66
>   @@ -364,7 +364,18 @@
>        public String getRemoteUser() {
>    	if( notAuthenticated ) {
>    	    notAuthenticated=false;
>   -	    contextM.doAuthenticate(this, response);
>   +
>   +	    int status=0;
>   +	    BaseInterceptor reqI[]= context.getContainer().
>   +		getInterceptors(Container.H_authenticate);
>   +	    for( int i=0; i< reqI.length; i++ ) {
>   +		status=reqI[i].authenticate( this, response );
>   +		if ( status != 0 ) {
>   +		    break;
>   +		}
>   +	    }
>   +
>   +	    //contextM.doAuthenticate(this, response);
>    	    // 	    context.log("Auth " + remoteUser );
>    	}
>    	return remoteUser;
>   @@ -519,7 +530,12 @@
>
>    	if( ! create ) return null;
>
>   -	contextM.doNewSessionRequest( this, response );
>   +	BaseInterceptor reqI[]= contextM.
>   +	    getInterceptors(this, Container.H_newSessionRequest);
>   +
>   +	for( int i=0; i< reqI.length; i++ ) {
>   +	    reqI[i].newSessionRequest( this, response );
>   +	}
>
>    	if ( serverSession == null ) {
>    	    return null;
>
>
>
>   1.39      +18 -14
> jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
>
>   Index: Response.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
>   retrieving revision 1.38
>   retrieving revision 1.39
>   diff -u -r1.38 -r1.39
>   --- Response.java	2000/09/29 21:09:35	1.38
>   +++ Response.java	2000/10/01 06:37:46	1.39
>   @@ -194,7 +194,13 @@
>
>        public void finish() throws IOException {
>            oBuffer.close();
>   -	request.getContextManager().doAfterBody(request, this);
>   +	ContextManager cm=request.getContextManager();
>   +	BaseInterceptor reqI[]= cm.
>   +	    getInterceptors(request, Container.H_afterBody);
>   +
>   +	for( int i=0; i< reqI.length; i++ ) {
>   +	    reqI[i].afterBody( request, this );
>   +	}
>        }
>
>        public boolean containsHeader(String name) {
>   @@ -369,22 +375,20 @@
>
>    	// let CM notify interceptors and give a chance to fix
>    	// the headers
>   -	if(request.getContext() != null && ! included )
>   -
> request.getContext().getContextManager().doBeforeBody(request, this);
>   +	if(request.getContext() != null && ! included ) {
>   +	    // call before body hooks
>   +	    ContextManager cm=request.getContext().getContextManager();
>   +
>   +	    BaseInterceptor reqI[]= cm.
>   +		getInterceptors(request, Container.H_beforeBody);
>
>   +	    for( int i=0; i< reqI.length; i++ ) {
>   +		reqI[i].beforeBody( request, this );
>   +	    }
>   +	}
>   +
>    	// No action..
>        }
>   -
>   -//     public void addUserCookie(Object cookie) {
>   -// 	if( ! included ) userCookies.addElement(cookie);
>   -//     }
>   -
>   -//     /** All cookies set explicitely by users with addCookie()
>   -//      *  - I'm not sure if it's used or needed
>   -//      */
>   -//     public Enumeration getUserCookies() {
>   -// 	return userCookies.elements();
>   -//     }
>
>        public Locale getLocale() {
>            return locale;
>
>
>
>   1.6       +4 -4
> jakarta-tomcat/src/share/org/apache/tomcat/helper/ServerXmlHelper.java
>
>   Index: ServerXmlHelper.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/helper/Server
> XmlHelper.java,v
>   retrieving revision 1.5
>   retrieving revision 1.6
>   diff -u -r1.5 -r1.6
>   --- ServerXmlHelper.java	2000/09/29 07:01:07	1.5
>   +++ ServerXmlHelper.java	2000/10/01 06:37:49	1.6
>   @@ -94,7 +94,7 @@
>    	xh.addRule( "ContextManager/ContextInterceptor",
>    		    xh.setParent("setContextManager") );
>    	xh.addRule( "ContextManager/ContextInterceptor",
>   -		    xh.addChild( "addContextInterceptor",
>   +		    xh.addChild( "addInterceptor",
>    				 "org.apache.tomcat.core.BaseInterceptor"));
>
>    	xh.addRule( "ContextManager/RequestInterceptor",
>   @@ -104,7 +104,7 @@
>    	xh.addRule( "ContextManager/RequestInterceptor",
>    		    xh.setParent("setContextManager") );
>    	xh.addRule( "ContextManager/RequestInterceptor",
>   -		    xh.addChild( "addRequestInterceptor",
>   +		    xh.addChild( "addInterceptor",
>    				 "org.apache.tomcat.core.BaseInterceptor"));
>
>    	// Default host
>   @@ -123,7 +123,7 @@
>    	xh.addRule( "ContextManager/Context/RequestInterceptor",
>    		    xh.setParent("setContext") );
>    	xh.addRule( "ContextManager/Context/RequestInterceptor",
>   -		    xh.addChild( "addRequestInterceptor",
>   +		    xh.addChild( "addInterceptor",
>    				 "org.apache.tomcat.core.BaseInterceptor"));
>
>    	// Virtual host support.
>   @@ -177,7 +177,7 @@
>    		    xh.setParent( "setContextManager",
>
> "org.apache.tomcat.core.ContextManager") );
>    	xh.addRule( "ContextManager/Connector",
>   -		    xh.addChild( "addContextInterceptor",
>   +		    xh.addChild( "addInterceptor",
>    				 "org.apache.tomcat.core.BaseInterceptor"));
>
>    	xh.addRule( "ContextManager/Connector/Parameter",
>
>
>
>   1.22      +1 -1
> jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java
>
>   Index: StaticInterceptor.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/Stati
> cInterceptor.java,v
>   retrieving revision 1.21
>   retrieving revision 1.22
>   diff -u -r1.21 -r1.22
>   --- StaticInterceptor.java	2000/09/30 04:03:46	1.21
>   +++ StaticInterceptor.java	2000/10/01 06:37:50	1.22
>   @@ -108,7 +108,6 @@
>    	DirHandler dirHandler=new DirHandler();
>    	fileHandler.setNoteId( realFileNote );
>    	dirHandler.setNoteId( realFileNote );
>   -	debug=0;
>    	ctx.addServlet( fileHandler );
>    	if (listings)
>    	    ctx.addServlet( dirHandler );
>   @@ -130,6 +129,7 @@
>    	String absPath=FileUtil.safePath( ctx.getAbsolutePath(),
>    					  pathInfo);
>
>   +	if( debug > -1 ) log( "RequestMap " + req + " " + absPath +
> " " + ctx.getAbsolutePath() );
>    	if( absPath == null ) return 0;
>    	String requestURI=req.getRequestURI();
>
>
>
>
>   1.28      +20 -32
> jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java
>
>   Index: EmbededTomcat.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Embed
> edTomcat.java,v
>   retrieving revision 1.27
>   retrieving revision 1.28
>   diff -u -r1.27 -r1.28
>   --- EmbededTomcat.java	2000/09/29 07:01:38	1.27
>   +++ EmbededTomcat.java	2000/10/01 06:37:50	1.28
>   @@ -38,7 +38,6 @@
>        Object application;
>        // null == not set up
>        Vector requestInt=null;
>   -    Vector contextInt=null;
>        /** Right now we assume all web apps use the same
>    	servlet API version. This will change after we
>    	finish the FacadeManager implementation
>   @@ -74,7 +73,7 @@
>
>    	// In our case the adapter must be BaseInterceptor.
>    	if ( adapter instanceof BaseInterceptor ) {
>   -	    addRequestInterceptor( (BaseInterceptor)adapter);
>   +	    addInterceptor( (BaseInterceptor)adapter);
>    	}
>        }
>
>   @@ -110,7 +109,7 @@
>
>    	//	sc.setTcpConnectionHandler( new HttpConnectionHandler());
>
>   -	contextM.addRequestInterceptor(  sc );
>   +	contextM.addInterceptor(  sc );
>        }
>
>        /** Add a secure web service.
>   @@ -134,7 +133,7 @@
>    	// sc.setTcpConnectionHandler( hc );
>    	// XXX add the secure socket
>
>   -	contextM.addRequestInterceptor(  sc );
>   +	contextM.addInterceptor(  sc );
>        }
>
>        // -------------------- Context add/remove --------------------
>   @@ -289,32 +288,21 @@
>        }
>
>        // -------------------- Private methods
>   -    public void addRequestInterceptor( BaseInterceptor ri ) {
>   +    public void addInterceptor( BaseInterceptor ri ) {
>    	if( requestInt == null ) requestInt=new Vector();
>    	requestInt.addElement( ri );
>    	if( ri instanceof BaseInterceptor )
>    	    ((BaseInterceptor)ri).setDebug( debug );
>        }
>   -    public void addContextInterceptor( BaseInterceptor ci ) {
>   -	if( contextInt == null ) contextInt=new Vector();
>   -	contextInt.addElement( ci );
>   -	if( ci instanceof BaseInterceptor )
>   -	    ((BaseInterceptor)ci).setDebug( debug );
>   -    }
>
>        private void initContextManager() {
>    	if(requestInt==null)  initDefaultInterceptors();
>    	contextM=new ContextManager();
>    	contextM.setDebug( debug );
>
>   -	for( int i=0; i< contextInt.size() ; i++ ) {
>   -	    contextM.addContextInterceptor( (BaseInterceptor)
>   -					    contextInt.elementAt( i ) );
>   -	}
>   -
>    	for( int i=0; i< requestInt.size() ; i++ ) {
>   -	    contextM.addRequestInterceptor( (BaseInterceptor)
>   -					    requestInt.elementAt( i ) );
>   +	    contextM.addInterceptor( (BaseInterceptor)
>   +				     requestInt.elementAt( i ) );
>    	}
>
>    	contextM.setWorkDir( workDir );
>   @@ -341,57 +329,57 @@
>    	// multiple APIs at the same time in embeded mode )
>
>    	BaseInterceptor webXmlI=
> (BaseInterceptor)newObject("org.apache.tomcat.facade.WebXmlReader");
>   -	addContextInterceptor( webXmlI );
>   +	addInterceptor( webXmlI );
>
>    	PolicyInterceptor polI=new PolicyInterceptor();
>   -	addContextInterceptor( polI );
>   +	addInterceptor( polI );
>    	polI.setDebug(0);
>
>    	LoaderInterceptor12 loadI=new LoaderInterceptor12();
>   -	addContextInterceptor( loadI );
>   +	addInterceptor( loadI );
>
>    	DefaultCMSetter defaultCMI=new DefaultCMSetter();
>   -	addContextInterceptor( defaultCMI );
>   +	addInterceptor( defaultCMI );
>
>    	WorkDirInterceptor wdI=new WorkDirInterceptor();
>   -	addContextInterceptor( wdI );
>   +	addInterceptor( wdI );
>
>
>    	LoadOnStartupInterceptor loadOnSI=new LoadOnStartupInterceptor();
>   -	addContextInterceptor( loadOnSI );
>   +	addInterceptor( loadOnSI );
>
>    	// Debug
>    	// 	LogEvents logEventsI=new LogEvents();
>    	// 	addRequestInterceptor( logEventsI );
>
>    	SessionInterceptor sessI=new SessionInterceptor();
>   -	addRequestInterceptor( sessI );
>   +	addInterceptor( sessI );
>
>    	SimpleMapper1 mapI=new SimpleMapper1();
>   -	addRequestInterceptor( mapI );
>   +	addInterceptor( mapI );
>    	mapI.setDebug(0);
>
>    	InvokerInterceptor invI=new InvokerInterceptor();
>   -	addRequestInterceptor( invI );
>   +	addInterceptor( invI );
>    	invI.setDebug(0);
>
>    	StaticInterceptor staticI=new StaticInterceptor();
>   -	addRequestInterceptor( staticI );
>   +	addInterceptor( staticI );
>    	mapI.setDebug(0);
>
>   -	addRequestInterceptor( new StandardSessionInterceptor());
>   +	addInterceptor( new StandardSessionInterceptor());
>
>    	// access control ( find if a resource have constraints )
>    	AccessInterceptor accessI=new AccessInterceptor();
>   -	addRequestInterceptor( accessI );
>   +	addInterceptor( accessI );
>    	accessI.setDebug(0);
>
>    	// set context class loader
>    	Jdk12Interceptor jdk12I=new Jdk12Interceptor();
>   -	addRequestInterceptor( jdk12I );
>   +	addInterceptor( jdk12I );
>
>    	// xXXX
>   -	//	addRequestInterceptor( new SimpleRealm());
>   +	//	addInterceptor( new SimpleRealm());
>        }
>
>
>
>
>
>   1.20      +1 -1
> jakarta-tomcat/src/share/org/apache/tomcat/task/ApacheConfig.java
>
>   Index: ApacheConfig.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/task/ApacheCo
> nfig.java,v
>   retrieving revision 1.19
>   retrieving revision 1.20
>   diff -u -r1.19 -r1.20
>   --- ApacheConfig.java	2000/09/29 07:01:44	1.19
>   +++ ApacheConfig.java	2000/10/01 06:37:51	1.20
>   @@ -136,7 +136,7 @@
>
>    	    // Find Ajp12 connector
>    	    int portInt=8007;
>   -	    BaseInterceptor ci[]=cm.getContextInterceptors();
>   +	    BaseInterceptor ci[]=cm.getInterceptors();
>    	    for( int i=0; i<ci.length; i++ ) {
>    		Object con=ci[i];
>    		if( con instanceof  Ajp12ConnectionHandler ) {
>
>
>
>   1.11      +1 -1
> jakarta-tomcat/src/share/org/apache/tomcat/task/StopTomcat.java
>
>   Index: StopTomcat.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/task/StopTomc
> at.java,v
>   retrieving revision 1.10
>   retrieving revision 1.11
>   diff -u -r1.10 -r1.11
>   --- StopTomcat.java	2000/09/29 07:01:47	1.10
>   +++ StopTomcat.java	2000/10/01 06:37:51	1.11
>   @@ -173,7 +173,7 @@
>    	// Find Ajp12 connector
>    	int portInt=8007;
>    	InetAddress address=null;
>   -	BaseInterceptor ci[]=cm.getContextInterceptors();
>   +	BaseInterceptor ci[]=cm.getInterceptors();
>    	for( int i=0; i<ci.length; i++ ) {
>    	    Object con=ci[i];
>    	    if( con instanceof  Ajp12ConnectionHandler ) {
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
>