tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util SecurityTools.java
Date Fri, 16 Jun 2000 21:03:42 GMT
costin      00/06/16 14:03:41

  Modified:    src/share/org/apache/tomcat/context AutoSetup.java
                        DefaultCMSetter.java LoadOnStartupInterceptor.java
               src/share/org/apache/tomcat/core BaseInterceptor.java
                        Context.java ContextManager.java Handler.java
                        ServletWrapper.java
               src/share/org/apache/tomcat/facade
                        RequestDispatcherImpl.java
               src/share/org/apache/tomcat/request AccessInterceptor.java
               src/share/org/apache/tomcat/servlets InvokerServlet.java
               src/share/org/apache/tomcat/util SecurityTools.java
  Log:
  - another step in ServletWrapper cleanup
  
  - added few more debug statements, show the "required" roles
  
  Important: I tested and most of the "normal" code works, but ( as with any change)
  it may introduce bugs or regressions. Don't panic :-), the code is ( I hope ) easier to
  fix now.
  
  Revision  Changes    Path
  1.12      +7 -2      jakarta-tomcat/src/share/org/apache/tomcat/context/AutoSetup.java
  
  Index: AutoSetup.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/AutoSetup.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AutoSetup.java	2000/04/25 17:54:09	1.11
  +++ AutoSetup.java	2000/06/16 21:02:19	1.12
  @@ -98,6 +98,7 @@
   	    // we care only about the root context for autosetup
   	    // until we define a pattern for automatic vhost setup.
   	    definedContexts.put( ctx.getPath(), ctx );
  +	    if(debug>0) log("Register explicit context " + ctx.getPath());
   	}
       }
       
  @@ -106,6 +107,7 @@
        *  virtual hosts too
        */
       public void engineInit(ContextManager cm) throws TomcatException {
  +	super.engineInit( cm );
   	String home=cm.getHome();
   	File webappD=new File(home + "/webapps");
   	if (! webappD.exists() || ! webappD.isDirectory()) {
  @@ -165,10 +167,10 @@
   		// don't assume HOME==TOMCAT_HOME
   		File f=new File( webappD, name);
   		ctx.setDocBase( f.getAbsolutePath() );
  -		if( debug > 0 ) cm.log("AutoSetup " + ctx.toString());
  +		if( debug > 0 ) log("automatic add " + ctx.toString() + " " + path);
   		cm.addContext(ctx);
   	    } else {
  -		//System.out.println("Already set up: " + path + " " + definedContexts.get(path));
  +		if( debug>0) log("Already set up: " + path + " " + definedContexts.get(path));
   	    }
   	}
       }
  @@ -177,4 +179,7 @@
   	debug=i;
       }
   
  +    public void log(String s ) {
  +	cm.log("AutoSetup: " + s );
  +    }
   }
  
  
  
  1.40      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java
  
  Index: DefaultCMSetter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- DefaultCMSetter.java	2000/06/16 17:08:08	1.39
  +++ DefaultCMSetter.java	2000/06/16 21:02:38	1.40
  @@ -99,7 +99,7 @@
   	// Validation for error  servlet
    	try {
   	    ServletWrapper errorWrapper1=ctx.getServletByName( "tomcat.errorPage");
  -	    errorWrapper1.initServlet();
  +	    errorWrapper1.init();
   	} catch( Exception ex ) {
   	    System.out.println("Error loading default servlet ");
               ex.printStackTrace();
  
  
  
  1.13      +1 -2      jakarta-tomcat/src/share/org/apache/tomcat/context/LoadOnStartupInterceptor.java
  
  Index: LoadOnStartupInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/LoadOnStartupInterceptor.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- LoadOnStartupInterceptor.java	2000/06/13 00:32:34	1.12
  +++ LoadOnStartupInterceptor.java	2000/06/16 21:02:39	1.13
  @@ -129,8 +129,7 @@
   			if( result.getPath() != null )
   			    loadJsp( ctx, result );
   			else {
  -			    result.loadServlet();
  -			    result.initServlet();
  +			    result.init();
   			}
   		    } catch (Exception ee) {
   			String msg = sm.getString("context.loadServlet.e",
  
  
  
  1.11      +4 -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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BaseInterceptor.java	2000/06/15 19:34:26	1.10
  +++ BaseInterceptor.java	2000/06/16 21:03:19	1.11
  @@ -70,9 +70,9 @@
   /**
    */
   public class BaseInterceptor implements RequestInterceptor, ContextInterceptor {
  -    ContextManager cm; 
  +    protected ContextManager cm; 
       protected String methods[]=new String[0];
  -    int debug=0;
  +    protected int debug=0;
       
       public BaseInterceptor() {
       }
  @@ -80,7 +80,7 @@
       public void setDebug( int d ) {
   	debug=d;
       }
  -    
  +
       public void setContextManager( ContextManager cm ) {
   	this.cm=cm;
       }
  @@ -153,6 +153,7 @@
       /** Called when the ContextManger is started
        */
       public void engineInit(ContextManager cm) throws TomcatException {
  +	this.cm=cm;
       }
   
       /** Called before the ContextManager is stoped.
  
  
  
  1.95      +2 -1      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.94
  retrieving revision 1.95
  diff -u -r1.94 -r1.95
  --- Context.java	2000/06/15 18:50:18	1.94
  +++ Context.java	2000/06/16 21:03:20	1.95
  @@ -517,7 +517,8 @@
   	    // Declare a mapping for a JSP or servlet that is not
   	    // declared as servlet.
   
  -	    sw = new ServletWrapper(this);
  +	    sw = new ServletWrapper();
  +	    sw.setContext(this);
   
   	    sw.setServletName(servletName);
   	    if ( servletName.startsWith("/")) {
  
  
  
  1.92      +34 -26    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.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- ContextManager.java	2000/06/16 17:08:08	1.91
  +++ ContextManager.java	2000/06/16 21:03:21	1.92
  @@ -182,7 +182,7 @@
        */
       public void setHome(String home) {
   	this.home=FileUtil.getCanonicalPath( home ); 
  -	log( "Setting home to " + this.home );
  +	logInt( "Setting home to " + this.home );
       }
       
       /** 
  @@ -199,7 +199,7 @@
   	if( debug > 20 ) {
   	    // we want to know all places that need this property
   	    // and find how it's computed - for embeding tc.
  -	    log( "getHome " + home + " " + installDir + " " +
  +	    logInt( "getHome " + home + " " + installDir + " " +
   		 System.getProperty("tomcat.home") + " " +
   		 FileUtil.getCanonicalPath( "." ));
   	    /*DEBUG*/ try {throw new Exception(); } catch(Exception ex) {ex.printStackTrace();}
  @@ -229,7 +229,7 @@
   	if( debug > 20 ) {
   	    // we want to know all places that need this property
   	    // and find how it's computed - for embeding tc.
  -	    log( "getInstallDir " + installDir + " " +
  +	    logInt( "getInstallDir " + installDir + " " +
   		 System.getProperty("tomcat.home"));
   	    /*DEBUG*/ try {throw new Exception(); } catch(Exception ex) {ex.printStackTrace();}
   	}
  @@ -257,7 +257,7 @@
        * WorkDir property - where all working files will be created
        */ 
       public void setWorkDir( String wd ) {
  -	if(debug>0) log("set work dir " + wd);
  +	if(debug>0) logInt("set work dir " + wd);
   	// make it absolute
   	File f=new File( wd );
   	if( ! f.isAbsolute() ) {
  @@ -308,14 +308,14 @@
        */
       public void setDefaults() {
   	if(connectors.size()==0) {
  -	    if(debug>5) log("Setting default adapter");
  +	    if(debug>5) logInt("Setting default adapter");
   	    org.apache.tomcat.service.PoolTcpConnector sc=new org.apache.tomcat.service.PoolTcpConnector();
   	    sc.setTcpConnectionHandler( new org.apache.tomcat.service.http.HttpConnectionHandler());
   	    addServerConnector(  sc );
   	}
   	
   	if( contextInterceptors.size()==0) {
  -	    if(debug>5) log("Setting default context interceptors");
  +	    if(debug>5) logInt("Setting default context interceptors");
   	    addContextInterceptor(new LogEvents());
   	    addContextInterceptor(new AutoSetup());
   	    //	    addContextInterceptor(new PolicyInterceptor());
  @@ -327,7 +327,7 @@
   	}
   	
   	if( requestInterceptors.size()==0) {
  -	    if(debug>5) log("Setting default request interceptors");
  +	    if(debug>5) logInt("Setting default request interceptors");
   	    addRequestInterceptor(new SessionInterceptor());
   	    SimpleMapper1 smap=new SimpleMapper1();
   	    smap.setContextManager( this );
  @@ -346,9 +346,9 @@
        *  may be a better name ? ). ( Initializing is different from starting.)
        */
       public void init()  throws TomcatException {
  -	//	log( "Tomcat install = " + getInstallDir());
  -	// log( "Tomcat home = " + home);
  -	if(debug>0 ) log( "Tomcat classpath = " +  System.getProperty( "java.class.path" ));
  +	//	logInt( "Tomcat install = " + getInstallDir());
  +	// logInt( "Tomcat home = " + home);
  +	if(debug>0 ) logInt( "Tomcat classpath = " +  System.getProperty( "java.class.path" ));
   
   	setAccount( ACC_INIT_START, System.currentTimeMillis());
   	
  @@ -366,7 +366,7 @@
   		initContext( context );
   	    } catch (TomcatException ex ) {
   		if( context!=null ) {
  -		    log( "ERROR initializing " + context.toString() );
  +		    logInt( "ERROR initializing " + context.toString() );
   		    removeContext( context  );	    
   		    Throwable ex1=ex.getRootCause();
   		    if( ex1!=null ) ex.printStackTrace();
  @@ -420,7 +420,11 @@
   	    String key = (String)enum.nextElement();
   	    ServletWrapper wrapper = ctx.getServletByName( key );
   	    ctx.removeServletByName( key );
  -	    wrapper.destroy();
  +	    try {
  +		wrapper.destroy();
  +	    } catch(Exception ex ) {
  +		ctx.log( "Error in destroy ", ex);
  +	    }
   	}
   	
   	ContextInterceptor cI[]=getContextInterceptors();
  @@ -442,7 +446,7 @@
       /** Will stop all connectors
        */
       public void stop() throws Exception {// XXX TomcatException {
  -	if(debug>0) log("Stopping context manager ");
  +	if(debug>0) logInt("Stopping context manager ");
   	Enumeration connE=getConnectors();
   	while( connE.hasMoreElements() ) {
   	    ((ServerConnector)connE.nextElement()).stop();
  @@ -478,7 +482,7 @@
   	}
   
   	String vhost=ctx.getHost();
  -	log("Adding context " +  ctx.toString());
  +	logInt("Adding context " +  ctx.toString());
   
   	// XXX temporary workaround for the old SimpleMapper -
   	// This code will be removed as soon as the new mapper is stable.
  @@ -492,7 +496,7 @@
       public void removeContext( Context context ) throws TomcatException {
   	if( context==null ) return;
   	
  -	log( "Removing context " + context.toString());
  +	logInt( "Removing context " + context.toString());
   
   	ContextInterceptor cI[]=getContextInterceptors();
   	for( int i=0; i< cI.length; i++ ) {
  @@ -506,7 +510,7 @@
       void doReload( Request req, Context context ) throws TomcatException {
   	if( context==null ) return;
   	
  -	if( debug>0 ) log( "Reloading context " + context.toString());
  +	if( debug>0 ) logInt( "Reloading context " + context.toString());
   
   	ContextInterceptor cI[]=getContextInterceptors();
   	for( int i=0; i< cI.length; i++ ) {
  @@ -545,7 +549,7 @@
        * @param con The new server connector
        */
       public synchronized void addServerConnector( ServerConnector con ) {
  -	if(debug>0) log("Add connector javaClass=\"" + con.getClass().getName() + "\"");
  +	if(debug>0) logInt("Add connector javaClass=\"" + con.getClass().getName() + "\"");
   	con.setServer( this );
   	connectors.addElement( con );
       }
  @@ -555,7 +559,7 @@
       }
       
       public void addRequestInterceptor( RequestInterceptor ri ) {
  -	if(debug>0) log("Add requestInterceptor javaClass=\"" + ri.getClass().getName() + "\" ");
  +	if(debug>0) logInt("Add requestInterceptor javaClass=\"" + ri.getClass().getName() + "\" ");
   	// XXX for programatic access, it'll go away after the interceptor is fixed.
   	if( ri instanceof BaseInterceptor ) ((BaseInterceptor)ri).setContextManager( this );
   	requestInterceptors.addElement( ri );
  @@ -583,7 +587,7 @@
       }
   
       public void addContextInterceptor( ContextInterceptor ci) {
  -	if(debug>0) log("Add contextInterceptor javaClass=\"" + ci.getClass().getName() + "\" ");
  +	if(debug>0) logInt("Add contextInterceptor javaClass=\"" + ci.getClass().getName() + "\" ");
   	if( ci instanceof BaseInterceptor ) ((BaseInterceptor)ci).setContextManager( this );
   	contextInterceptors.addElement( ci );
       }
  @@ -644,7 +648,7 @@
   	    if(status == 0)
   		status=authorize( rrequest, rresponse );
   	    if( status == 0 ) {
  -		rrequest.getWrapper().handleRequest(rrequest, rresponse);
  +		rrequest.getWrapper().service(rrequest, rresponse);
   	    } else {
   		// something went wrong
   		handleError( rrequest, rresponse, null, status );
  @@ -657,7 +661,7 @@
   	    rrequest.recycle();
   	    rresponse.recycle();
   	} catch( Throwable ex ) {
  -	    if(debug>0) log( "Error closing request " + ex);
  +	    if(debug>0) logInt( "Error closing request " + ex);
   	}
   	return;
       }
  @@ -667,7 +671,7 @@
        *  is already known. 
        */
       public int processRequest( Request req ) {
  -	if(debug>9) log("ProcessRequest: "+req.toString());
  +	if(debug>9) logInt("ProcessRequest: "+req.toString());
   
   	for( int i=0; i< requestInterceptors.size(); i++ ) {
   	    ((RequestInterceptor)requestInterceptors.elementAt(i)).contextMap( req );
  @@ -677,7 +681,7 @@
   	    ((RequestInterceptor)requestInterceptors.elementAt(i)).requestMap( req );
   	}
   
  -	if(debug>9) log("After processing: "+req.toString());
  +	if(debug>9) logInt("After processing: "+req.toString());
   	
   	return 0;
       }
  @@ -701,7 +705,7 @@
   	    int err = ((RequestInterceptor)requestInterceptors.elementAt(i)
   		       ).authorize( req, res );
   	    if ( err != 0 ) {
  -		if( debug>0) log( "Authorize result " + err );
  +		if( debug>0) logInt( "Authorize result " + err );
   		return err;
   	    }
   	}
  @@ -777,7 +781,7 @@
   		urlPath= "/" + urlPath;
   	}
   
  -	if( debug >4 ) log("createRequest " + origPath + " " + urlPath  );
  +	if( debug >4 ) logInt("createRequest " + origPath + " " + urlPath  );
   	Request req= createRequest( urlPath );
   	String host=ctx.getHost();
   	if( host != null) req.setServerName( host );
  @@ -935,7 +939,7 @@
   
   	if( ctx.getDebug() > 0 ) ctx.log( "Error: Calling servlet " + errorServlet );
   	req.setAttribute("tomcat.servlet.error.handler", errorServlet);
  -	errorServlet.handleRequest(req,res);
  +	errorServlet.service(req,res);
   
   	return;
       }
  @@ -1072,6 +1076,10 @@
       }
       
       public final void log(String msg) {
  +	doLog( msg );
  +    }
  +
  +    private final void logInt(String msg) {
   	doLog( "CM: " + msg );
       }
   
  
  
  
  1.2       +64 -57    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Handler.java	2000/06/16 17:58:56	1.1
  +++ Handler.java	2000/06/16 21:03:21	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v 1.1 2000/06/16 17:58:56 costin Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/06/16 17:58:56 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v 1.2 2000/06/16 21:03:21 costin Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/16 21:03:21 $
    *
    * ====================================================================
    *
  @@ -109,7 +109,7 @@
       public static final int ORIGIN_ADMIN=4;
       
       // who creates the servlet definition
  -    int origin;
  +    protected int origin;
   
       public Handler() {
       }
  @@ -159,13 +159,14 @@
   	can implement this, but it can't be called from outside.
   	( the "guarded" doDestroy is public )
       */
  -    protected void destroy() throws TomcatException {
  +    protected void doDestroy() throws Exception {
   
       }
   
       /** Destroy a handler, and notify all the interested interceptors
        */
  -    public void doDestroy() throws TomcatException {
  +    public void destroy() throws Exception {
  +	if ( ! initialized ) return;// already destroyed or not init.
   	initialized=false;
   
   	ContextInterceptor cI[]=context.getContextInterceptors();
  @@ -180,7 +181,7 @@
   	
   	// XXX post will not be called if any error happens in destroy.
   	// That's how tomcat worked before - I think it's a bug !
  -	destroy();
  +	doDestroy();
   	
   	for( int i=cI.length-1; i>=0; i-- ) {
   	    try {
  @@ -189,22 +190,22 @@
   	    } catch( TomcatException ex) {
   		context.log( "Error in postServletDestroy " + cI, ex );
   	    }
  -	    
   	}
       }
   
       /** Initialize the handler. Handler can override this
   	method to initialize themself.
  +	The method must set initialised=true if successfull.
        */
  -    protected void init() throws TomcatException
  +    protected void doInit() throws Exception
       {
   
       }
   
       /** Call the init method, and notify all interested listeners.
        */
  -    public void doInit()
  -	throws TomcatException
  +    public void init()
  +	throws Exception
       {
   	try {
   	    if( initialized ) return;
  @@ -219,7 +220,7 @@
   		}
   	    }
   
  -	    init();
  +	    doInit();
   
   	    // if an exception is thrown in init, no end interceptors will
   	    // be called. that was in the origianl code J2EE used
  @@ -233,7 +234,6 @@
   		}
   	    }
   
  -	    initialized=true;
   	} catch( Exception ex ) {
   	    initialized=false;
   	}
  @@ -242,7 +242,9 @@
       /** This is the actual content generator. Can't be called
   	from outside.
        */
  -    protected void doService(Request req, Response res) {
  +    protected void doService(Request req, Response res)
  +	throws Exception
  +    {
   
       }
   
  @@ -251,56 +253,61 @@
       public void service(Request req, Response res) 
       {
   	if( ! initialized ) {
  -	    // if multiple threads will call the same servlet at once,
  -	    // we should have only one init 
  -	    synchronized( this ) {
  -		try {
  -		    init();
  -		} catch( Exception ex ) {
  -		    context.log("Exception in init  " + ex.getMessage(), ex );
  -		    contextM.handleError( req, res, ex );
  -		    return;
  -		}
  +	    try {
  +		init();
  +	    } catch( Exception ex ) {
  +		initialized=false;
  +		context.log("Exception in init  " + ex.getMessage(), ex );
  +		contextM.handleError( req, res, ex );
  +		return;
   	    }
   	}
   	
   	// We are initialized and fine
  -	try {
  -	    RequestInterceptor cI[]=context.getRequestInterceptors();
  -	    for( int i=0; i<cI.length; i++ ) {
  -		cI[i].preService( req, res );
  -		// ignore the error - like in the original code
  -	    }
  +	RequestInterceptor cI[]=context.getRequestInterceptors();
  +	for( int i=0; i<cI.length; i++ ) {
  +	    cI[i].preService( req, res );
  +	    // ignore the error - like in the original code
  +	}
   
  +	Throwable t=null;
  +	try {
   	    doService( req, res );
  -	    
  -	    for( int i=cI.length-1; i>=0; i-- ) {
  -		cI[i].postService( req , res );
  -		// ignore the error - like in the original code
  -	    }
  -	}  catch( Throwable t ) {
  -	    if( t instanceof IOException ) {
  -		if( ((IOException)t).getMessage().equals("Broken pipe"))
  -		    return;
  -		System.out.println("XXX XXX " + t.getMessage());
  -	    }
  +	} catch( Throwable t1 ) {
  +	    t=t1;
  +	}
  +	
  +	// continue with the postService
  +
  +	for( int i=cI.length-1; i>=0; i-- ) {
  +	    cI[i].postService( req , res );
  +	    // ignore the error - like in the original code
  +	}
  +
  +	if( t==null)
  +	    return;
  +	
  +	if( t instanceof IOException ) {
  +	    if( ((IOException)t).getMessage().equals("Broken pipe"))
  +		return;
  +	    System.out.println("XXX XXX " + t.getMessage());
  +	}
   	    
  -	    if(null!=req.getAttribute("tomcat.servlet.error.defaultHandler")){
  -		// we are in handleRequest for the "default" error handler
  -		System.out.println("ERROR: can't find default error handler "+
  -				   "or error in default error page");
  -		t.printStackTrace();
  -	    } else {
  -		String msg=t.getMessage();
  -		context.log( "Error in " + getName() +
  -			     " service() : " + msg, t);
  -		// XXX XXX Security - we should log the message, but nothing
  -		// should show up  to the user - it gives up information
  -		// about the internal system !
  -		// Developers can/should use the logs !!!
  -		contextM.handleError( req, res, t );
  -	    }
  -	} 
  +	if(null!=req.getAttribute("tomcat.servlet.error.defaultHandler")){
  +	    // we are in handleRequest for the "default" error handler
  +	    System.out.println("ERROR: can't find default error handler "+
  +			       "or error in default error page");
  +	    t.printStackTrace();
  +	} else {
  +	    String msg=t.getMessage();
  +	    context.log( "Error in " + getName() +
  +			 " service() : " + msg, t);
  +	    // XXX XXX Security - we should log the message, but nothing
  +	    // should show up  to the user - it gives up information
  +	    // about the internal system !
  +	    // Developers can/should use the logs !!!
  +	    contextM.handleError( req, res, t );
  +	}
       }
       
       public String toString() {
  
  
  
  1.54      +218 -368  jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- ServletWrapper.java	2000/06/16 17:58:56	1.53
  +++ ServletWrapper.java	2000/06/16 21:03:22	1.54
  @@ -1,8 +1,4 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.53 2000/06/16 17:58:56 costin Exp $
  - * $Revision: 1.53 $
  - * $Date: 2000/06/16 17:58:56 $
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -80,18 +76,16 @@
    * @author Harish Prabandham
    * @author costin@dnt.ro
    */
  -public class ServletWrapper {
  -    protected StringManager sm = StringManager.getManager("org.apache.tomcat.core");
  -
  -    protected Context context;
  -    protected ContextManager contextM;
  +public class ServletWrapper extends Handler {
   
       // servletName is stored in config!
       protected String servletName;
       protected String servletClassName; // required
  -    protected Servlet servlet;
       protected Class servletClass;
   
  +    protected Servlet servlet;
  +
  +    // facade
       protected ServletConfig configF;
   
       // Jsp pages
  @@ -100,7 +94,6 @@
       // optional informations
       protected String description = null;
   
  -    boolean initialized=false;
       // If init() fails, this will keep the reason.
       // init may be called when the servlet starts, but we need to
       // report the error later, to the client
  @@ -116,47 +109,18 @@
   
       int loadOnStartup=0;
   
  -    Hashtable initArgs=null;
       Hashtable securityRoleRefs=new Hashtable();
   
  -    /** The servlet was declared in web.xml
  -     */
  -    public static final int ORIGIN_WEB_XML=0;
  -    public static final int ORIGIN_INVOKER=1;
  -    public static final int ORIGIN_JSP=2;
  -    /** any tomcat-specific component that can
  -	register mappings that are "re-generable",
  -	i.e. can be recreated - the mapping can
  -	safely be removed. Jsp and invoker are particular
  -	cases
  -    */
  -    public static final int ORIGIN_DYNAMIC=3;
  -    /** The servlet was added by the admin, it should be safed
  -	preferably in web.xml
  -    */
  -    public static final int ORIGIN_ADMIN=4;
  -    
  -    // who creates the servlet definition
  -    int origin;
  -
       public ServletWrapper() {
       }
   
  -    ServletWrapper(Context context) {
  -	setContext( context );
  -    }
  -
       public void setContext( Context context) {
  -        this.context = context;
  -	contextM=context.getContextManager();
  +	super.setContext( context );
   	isReloadable=context.getReloadable();
           configF = context.getFacadeManager().createServletConfig( this );
       }
   
  -    public Context getContext() {
  -	return context;
  -    }
  -
  +    // -------------------- Servlet specific properties 
       public void setLoadOnStartUp( int level ) {
   	loadOnStartup=level;
       }
  @@ -181,20 +145,17 @@
   
       public void setServletName(String servletName) {
           this.servletName=servletName;
  -    }
  -    
  -    public String getPath() {
  -        return this.path;
  +	name=servletName;
       }
   
  -    public void setPath(String path) {
  -        this.path = path;
  -    }
  -
       public String getServletDescription() {
           return this.description;
       }
   
  +//     public void setDescription( String d ) {
  +// 	description=d;
  +//     }
  +    
       public void setServletDescription(String description) {
           this.description = description;
       }
  @@ -204,13 +165,15 @@
       }
   
       public void setServletClass(String servletClassName) {
  -        this.servletClassName = servletClassName;
  +	if( name==null ) name=servletClassName;
  +	this.servletClassName = servletClassName;
       }
   
       /** Security Role Ref represent a mapping between servlet role names and
        *  server roles
        */
  -    public void addSecurityMapping( String name, String role, String description ) {
  +    public void addSecurityMapping( String name, String role,
  +				    String description ) {
   	securityRoleRefs.put( name, role );
       }
   
  @@ -218,6 +181,19 @@
   	return (String)securityRoleRefs.get( name );
       }
   
  +    // -------------------- Jsp specific code
  +    // Will go in JspHandler
  +    
  +    public String getPath() {
  +        return this.path;
  +    }
  +
  +    public void setPath(String path) {
  +        this.path = path;
  +    }
  +
  +    // -------------------- 
  +
       // XXX Doesn't seem to be used, shouldn't be part of interface -
       // use init and service !!! 
       public Servlet getServlet() {
  @@ -231,215 +207,224 @@
   	return servlet;
       }
   
  -    public void addInitParam( String name, String value ) {
  -	if( initArgs==null) {
  -	    initArgs=new Hashtable();
  -	}
  -	initArgs.put( name, value );
  -    }
  -
  -    public String getInitParameter(String name) {
  -	if (initArgs != null) {
  -            return (String)initArgs.get(name);
  -        } else {
  -            return null;
  -        }
  -    }
  -
  -    public Enumeration getInitParameterNames() {
  -        if (initArgs != null) {
  -            return initArgs.keys();
  -        } else {
  -            // dirty hack to return an empty enumeration
  -            Vector v = new Vector();
  -            return v.elements();
  -        }
  -    }
  -    
  -    void destroy() {
  -	initialized=false;
  -	if (servlet != null) {
  -	    synchronized (this) {
  -		// Fancy sync logic is to make sure that no threads are in the
  -		// handlerequest when this is called and, furthermore, that
  -		// no threads go through handle request after this method starts!
  -		// Wait until there are no outstanding service calls,
  -		// or until 30 seconds have passed (to avoid a hang)
  +    protected void doDestroy() throws TomcatException {
  +	synchronized (this) {
  +	    // Fancy sync logic is to make sure that no threads are in the
  +	    // handlerequest when this is called and, furthermore, that
  +	    // no threads go through handle request after this method starts!
  +	    // Wait until there are no outstanding service calls,
  +	    // or until 30 seconds have passed (to avoid a hang)
   		
  -		//XXX I don't think it works ( costin )
  -
  -		// XXX Move it to an interceptor!!!!
  -		while (serviceCount > 0) {
  -		    try {
  -			wait(30000);
  -			
  -			break;
  -		    } catch (InterruptedException e) { }
  -		}
  -
  +	    //XXX I don't think it works ( costin )
  +	    
  +	    // XXX Move it to an interceptor!!!!
  +	    while (serviceCount > 0) {
   		try {
  -		    ContextInterceptor cI[]=context.getContextInterceptors();
  -		    for( int i=0; i<cI.length; i++ ) {
  -			try {
  -			    cI[i].preServletDestroy( context, this ); // ignore the error - like in the original code
  -			} catch( TomcatException ex) {
  -			    context.log( "Error in preServletDestroy " + cI, ex );
  -			}
  -		    }
  -		    // XXX post will not be called if any error happens in destroy. That's
  -		    // how tomcat worked before - I think it's a bug !
  -		    servlet.destroy();
  -		    for( int i=cI.length-1; i>=0; i-- ) {
  -			try {
  -			    cI[i].postServletDestroy( context, this ); // ignore the error - like in the original code
  -			} catch( TomcatException ex) {
  -			    context.log( "Error in postServletDestroy " + cI, ex );
  -			}
  -			
  -		    }
  -		} catch(Exception ex) {
  -		    // Should never come here...
  -		    context.log( "Error in destroy ", ex );
  -		}
  +		    wait(30000);
  +		    break;
  +		} catch (InterruptedException e) { }
  +	    }
  +
  +	    try {
  +		servlet.destroy();
  +	    } catch(Exception ex) {
  +		// Should never come here...
  +		context.log( "Error in destroy ", ex );
   	    }
   	}
       }
   
       /** Load and init a the servlet pointed by this wrapper
        */
  -    public void loadServlet()
  +    private void loadServlet()
   	throws ClassNotFoundException, InstantiationException,
  -	IllegalAccessException, ServletException
  +	IllegalAccessException
       {
  -	// Jsp case - maybe another Jsp engine is used
  -	if( servlet==null && path != null ) {
  -	    handleJspInit();
  -	}
   	// XXX Move this to an interceptor, so it will be configurable.
   	// ( and easier to read )
   	if (servletClass == null) {
   	    if (servletClassName == null) {
  -		context.log( "Invalid servlet - class and class name are null " + servletName);
  -		throw new IllegalStateException(sm.getString("wrapper.load.noclassname"));
  +		throw new IllegalStateException("Can't happen - classname "
  +						+ "is null, who added this ?");
   	    }
  -	    
  -	    servletClass=context.getServletLoader().loadClass( servletClassName);
  +	    ServletLoader loader=context.getServletLoader();
  +	    servletClass=loader.loadClass(servletClassName);
   	}
   	
  -	if( servletClass==null ) throw new ServletException("Error loading servlet " + servletClassName );
   	servlet = (Servlet)servletClass.newInstance();
  -	if( servlet==null ) throw new ServletException("Error insantiating servlet "  + servletClassName );
  -	//	System.out.println("Loading " + servletClassName + " " + servlet );
  +
  +	// hack for internal servlets
  +	if( ! servletClassName.startsWith("org.apache.tomcat") ) return;
  +	if( servlet instanceof TomcatInternalServlet ) {
  +	    ((TomcatInternalServlet)servlet).setFacadeManager( context.
  +							 getFacadeManager());
  +	}
       }
  -    
  -    public void initServlet()
  -	throws ClassNotFoundException, InstantiationException,
  -	IllegalAccessException, ServletException
  +
  +    /** Override Handler's init - load the servlet before calling
  +	and interceptor
  +    */
  +    public void init()
  +    	throws Exception
       {
  +	// make sure the servlet in loaded before calling preInit
  +	// Jsp case - maybe another Jsp engine is used
  +	if( servlet==null && path != null ) {
  +	    handleJspInit();
  +	}
  +	// Will throw exception if it can't load, let upper
  +	// levels handle this
  +	//	try {
   	if( servlet==null ) loadServlet();
  -
  -	    checkInternal(servlet, servletClassName);
  +	//	} catch( ClassNotFoundException ex ) {
  +	//	} catch( InstantiationException ex ) {
  +	//} catch( IllegalStateException ex ) {
  +	//}
  +	
  +	// Call pre, doInit and post
  +	super.init();
  +    }
   
  -	    try {
  -		if( initialized ) return;
  -		
  +    protected void doInit()
  +	throws Exception
  +    {
  +	// The servlet is loaded and not null - otherwise init()
  +	// throws exception
  +	try {
  +	    // if multiple threads will call the same servlet at once,
  +	    // we should have only one init 
  +	    synchronized( this ) {
  +		// we may have 2 threads entering doInit,
  +		// the first one may init the servlet
  +		if( initialized )
  +		    return;
   		final Servlet sinstance = servlet;
   		final ServletConfig servletConfig = configF;
  -		ContextInterceptor cI[]=context.getContextInterceptors();
  -		for( int i=0; i<cI.length; i++ ) {
  -		    try {
  -			cI[i].preServletInit( context, this ); // ignore the error - like in the original code
  -		    } catch( TomcatException ex) {
  -			ex.printStackTrace();
  -		    }
  -		}
  -		servlet.init(servletConfig);
  -		// if an exception is thrown in init, no end interceptors will be called.
  -		// that was in the origianl code
  -		// XXX I think it's a bug ( costin )
   		
  -		for( int i=cI.length-1; i>=0; i-- ) {
  -		    try {
  -			cI[i].postServletInit( context, this ); // ignore the error - like in the original code
  -		    } catch( TomcatException ex) {
  -			    ex.printStackTrace();
  -		    }
  -		    
  -		}
  +		// init - only if unavailable was null or
  +		// unavailable period expired
  +		servlet.init(servletConfig);
   		initialized=true;
  -		// successfull initialization
  -		unavailable=null;
  -	    } catch( UnavailableException ex ) {
  -		unavailable=ex;
  -		unavailableTime=System.currentTimeMillis();
  -		unavailableTime += ex.getUnavailableSeconds() * 1000;
  -	    } catch( Exception ex ) {
  -		unavailable=ex;
   	    }
  +	} catch( UnavailableException ex ) {
  +	    unavailable=ex;
  +	    unavailableTime=System.currentTimeMillis();
  +	    unavailableTime += ex.getUnavailableSeconds() * 1000;
  +	} catch( Exception ex ) {
  +	    unavailable=ex;
  +	}
       }
   
  -    private void checkInternal( Servlet s, String servletClassName ) {
  -	if( ! servletClassName.startsWith("org.apache.tomcat") ) return;
  -	if( s instanceof TomcatInternalServlet ) {
  -	    ((TomcatInternalServlet)s).setFacadeManager( context.getFacadeManager());
  +    /** Override service to hook reloading - it can be done in a clean
  +	interceptor. It also hooks jsp - we should have a separate
  +	JspHandler
  +    */
  +    public void service(Request req, Response res) 
  +    {
  +	try {
  +	    handleReload(req);
  +	} catch( TomcatException ex ) {
  +	    ex.printStackTrace();// what to do ?
  +	}
  +
  +	// <servlet><jsp-file> case
  +	if( path!=null ) {
  +	    req.setAttribute( "javax.servlet.include.request_uri", path );
   	}
  +
  +	if( unavailable!=null  ) {
  +	    // Don't load if Unavailable timer is in place
  +	    if(  stillUnavailable() ) {
  +		handleUnavailable( req, res );
  +		initialized=false;
  +		return;
  +	    }
  +	    unavailable=null;// timer expired
  +	}
  +
  +	// called only if unavailable==null or timer expired.
  +	// will do an init
  +	super.service( req, res );
       }
  -    
  +
  +    protected void doService(Request req, Response res)
  +	throws Exception
  +    {
  +	// We are initialized and fine
  +	if (servlet instanceof SingleThreadModel) {
  +	    synchronized(servlet) {
  +		servlet.service(req.getFacade(), res.getFacade());
  +	    }
  +	} else {
  +	    servlet.service(req.getFacade(), res.getFacade());
  +	}
  +    }
  +
  +    // -------------------- Reloading --------------------
  +
       // XXX Move it to interceptor - so it can be customized
       // Reloading
       // XXX ugly - should find a better way to deal with invoker
       // The problem is that we are just clearing up invoker, not
       // the class loaded by invoker.
       void handleReload(Request req) throws TomcatException {
  -		// That will be reolved after we reset the context - and many
  -		// other conflicts.
  -		if( isReloadable && ! "invoker".equals( getServletName())) {
  -			ServletLoader loader=context.getServletLoader();
  -			if( loader!=null) {
  -				// XXX no need to check after we remove the old loader
  -				if( loader.shouldReload() ) {
  -					// workaround for destroy 
  -					destroy();
  -					initialized=false;
  -					loader.reload();
  -					
  -					ContextManager cm=context.getContextManager();
  -					cm.doReload( req, context );
  -					
  -					servlet=null;
  -					servletClass=null;
  -					/* Initial attempt to shut down the context and sessions.
  -
  -					String path=context.getPath();
  -					String docBase=context.getDocBase();
  -					// XXX all other properties need to be saved or something else
  -					ContextManager cm=context.getContextManager();
  -					cm.removeContext(path);
  -					Context ctx=new Context();
  -					ctx.setPath( path );
  -					ctx.setDocBase( docBase );
  -					cm.addContext( ctx );
  -					context=ctx;
  -					// XXX shut down context, remove sessions, etc
  -					*/
  -				}
  -			}
  +	// That will be reolved after we reset the context - and many
  +	// other conflicts.
  +	if( isReloadable && ! "invoker".equals( getServletName())) {
  +	    ServletLoader loader=context.getServletLoader();
  +	    if( loader!=null) {
  +		// XXX no need to check after we remove the old loader
  +		if( loader.shouldReload() ) {
  +		    // workaround for destroy 
  +		    try {
  +			destroy();
  +		    } catch(Exception ex ) {
  +			context.log( "Error in destroy ", ex );
  +		    }
  +		    initialized=false;
  +		    loader.reload();
  +		    
  +		    ContextManager cm=context.getContextManager();
  +		    cm.doReload( req, context );
  +		    
  +		    servlet=null;
  +		    servletClass=null;
  +		    /* Initial attempt to shut down the context and sessions.
  +		       
  +		       String path=context.getPath();
  +		       String docBase=context.getDocBase();
  +		       // XXX all other properties need to be saved
  +		       // or something else
  +		       ContextManager cm=context.getContextManager();
  +		       cm.removeContext(path);
  +		       Context ctx=new Context();
  +		       ctx.setPath( path );
  +		       ctx.setDocBase( docBase );
  +		       cm.addContext( ctx );
  +		       context=ctx;
  +		       // XXX shut down context, remove sessions, etc
  +		    */
   		}
  +	    }
  +	}
       }
  -    
  -    // <servlet><jsp-file> case - we know it's a jsp
  -    void handleJspInit() {
   
  -	// XXX Jsp Servlet is initialized, the servlet is not generated - we can't hook in!
  -	// It's jspServet that has to pass the config - but it can't so easily, plus
  -	// it'll have to hook in.
  -	// I don't think that ever worked anyway - and I don't think it can work without
  -	// integrating Jsp handling into tomcat ( using interceptor )
  -	
  +
  +    // -------------------- Jsp hooks
  +        // <servlet><jsp-file> case - we know it's a jsp
  +    void handleJspInit() {
  +	// XXX Jsp Servlet is initialized, the servlet is not generated -
  +	// we can't hook in! It's jspServet that has to pass the config -
  +	// but it can't so easily, plus  it'll have to hook in.
  +	// I don't think that ever worked anyway - and I don't think
  +	// it can work without integrating Jsp handling into tomcat
  +	// ( using interceptor )
   	ServletWrapper jspServletW = context.getServletByName("jsp");
   	servletClassName = jspServletW.getServletClass();
       }
       
  +
  +    // -------------------- Unavailable --------------------
       /** Check if we can try again an init
        */
       private boolean stillUnavailable() {
  @@ -450,7 +435,8 @@
   	    // we can try again
   	    unavailable=null;
   	    unavailableTime=-1;
  -	    context.log(getServletName() + " unavailable time expired, try again ");
  +	    context.log(getServletName() + " unavailable time expired," +
  +			" try again ");
   	    return false;
   	} else {
   	    return true;
  @@ -461,171 +447,35 @@
        */
       private void handleUnavailable( Request req, Response res ) {
   	if( unavailable instanceof UnavailableException ) {
  -	    int unavailableTime = ((UnavailableException)unavailable).getUnavailableSeconds();
  +	    int unavailableTime = ((UnavailableException)unavailable).
  +		getUnavailableSeconds();
   	    if( unavailableTime > 0 ) {
  -		res.setHeader("Retry-After", Integer.toString(unavailableTime));
  +		res.setHeader("Retry-After",
  +			      Integer.toString(unavailableTime));
   	    }
   	}
   
   	String msg=unavailable.getMessage();
   	long moreWaitTime=unavailableTime - System.currentTimeMillis();
  -	context.log( "Error in " + getServletName() + "init(), error happened at " +
  -		     unavailableTime + " wait " + moreWaitTime + " : " + msg, unavailable);
  +	context.log( "Error in " + getServletName() +
  +		     "init(), error happened at " +
  +		     unavailableTime + " wait " + moreWaitTime +
  +		     " : " + msg, unavailable);
   	req.setAttribute("javax.servlet.error.message", msg );
   	res.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); // 503
  -	contextM.handleStatus( req, res,  HttpServletResponse.SC_SERVICE_UNAVAILABLE );
  +	contextM.handleStatus( req, res,
  +			       HttpServletResponse.SC_SERVICE_UNAVAILABLE );
   	return;
       }
   
  +
  +    // -------------------- Not found
       private void handleNotFound( Request req, Response res) {
  -	context.log( "Can't find servet " + getServletName() + " " + getServletClass() );
  +	context.log( "Can't find servet " + getServletName() + " " +
  +		     getServletClass() );
   	res.setStatus( 404 );
   	contextM.handleStatus( req, res,  404 );
       }
   
  -    public void handleRequest(Request req, Response res) 
  -    {
  -	try {
  -	    handleReload(req);
  -	} catch( TomcatException ex ) {
  -	    ex.printStackTrace();// what to do ?
  -	}
  -
  -	// <servlet><jsp-file> case
  -	if( path!=null ) {
  -	    req.setAttribute( "javax.servlet.include.request_uri", path );
  -	}
  -	
  -	// Jsp case - if servlet == null init will take care 
  -	// Special case - we're not ready to run
  -	if( ! initialized || servlet == null || unavailable!=null  ) {
  -	    // Don't load if Unavailable timer is in place
  -	    if(  unavailable != null && stillUnavailable() ) {
  -		handleUnavailable( req, res );
  -		return;
  -	    }
  -	    
  -	    // if multiple threads will call the same servlet at once,
  -	    // we should have only one init 
  -	    synchronized( this ) {
  -		// init - only if unavailable was null or unavailable period expired
  -		try {
  -		    initServlet();
  -		} catch(ClassNotFoundException ex ) {
  -		    handleNotFound( req, res );
  -		    return;
  -		} catch( Exception ex ) {
  -		    context.log("Exception in init servlet " + ex.getMessage(), ex );
  -		    // any other exception will be set in unavailable - no need to do anything
  -		}
  -	    }
  -
  -	    if( servlet == null ) {
  -		handleNotFound( req, res );
  -		return;
  -	    }
  -
  -	    // If servlet was not initialized
  -	    if( unavailable!=null ) {
  -		handleUnavailable(req, res);
  -		return;
  -	    }
  -	}
  -	    
  -	// We are initialized and fine
  -	try {
  -	    RequestInterceptor cI[]=context.getRequestInterceptors();
  -	    for( int i=0; i<cI.length; i++ ) {
  -		cI[i].preService( req, res ); // ignore the error - like in the original code
  -	    }
  -
  -	    if (servlet instanceof SingleThreadModel) {
  -		synchronized(servlet) {
  -		    servlet.service(req.getFacade(), res.getFacade());
  -		}
  -	    } else {
  -		servlet.service(req.getFacade(), res.getFacade());
  -	    }
  -	    
  -	    for( int i=cI.length-1; i>=0; i-- ) {
  -		cI[i].postService( req , res ); // ignore the error - like in the original code
  -	    }
  -	}  catch( Throwable t ) {
  -	    if( t instanceof IOException ) {
  -		if( ((IOException)t).getMessage().equals("Broken pipe"))
  -		    return;
  -		System.out.println("XXX XXX " + t.getMessage());
  -	    }
  -	    
  -	    if( null!=req.getAttribute("tomcat.servlet.error.defaultHandler")) {
  -		// we are in handleRequest for the "default" error handler
  -		System.out.println("ERROR: can't find default error handler "+
  -				   "or error in default error page");
  -		t.printStackTrace();
  -	    } else {
  -		String msg=t.getMessage();
  -		context.log( "Error in " + getServletName() +
  -			     " service() : " + msg, t);
  -		// XXX XXX Security - we should log the message, but nothing
  -		// should show up  to the user - it gives up information
  -		// about the internal system !
  -		// Developers can/should use the logs !!!
  -		contextM.handleError( req, res, t );
  -	    }
  -	} 
  -    }
  -    
  -    public String toString() {
  -	StringBuffer sb=new StringBuffer();
  -	sb.append("<servlet n=").append( getServletName());
  -	if( servlet!=null ) sb.append( " sc=").append(servlet.getClass().getName());
  -	else  sb.append(" c=").append(servletClassName);
  -	sb.append(">");
  -	return sb.toString();
  -    }
  -
  -    /** 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
  -	web interface), JSP engine or something else.
  -	
  -	Tomcat can do special actions - for example remove non-used
  -	mappings if the source is the invoker or a similar component
  -    */
  -    public void setOrigin( int origin ) {
  -	this.origin=origin;
  -    }
  -
  -    public int getOrigin() {
  -	return origin;
  -    }
  -
  -    public void setDescription( String d ) {
  -	description=d;
  -    }
  -    
  -    // -------------------- Accounting --------------------
  -
  -    /** ServletWrapper counts. The accounting desing is not
  -	final, but all this is needed to tune up tomcat
  -	( and to understand and be able to implement a good
  -	solution )
  -    */
  -    public static final int ACC_LAST_ACCESSED=0;
  -    public static final int ACC_INVOCATION_COUNT=1;
  -    public static final int ACC_SERVICE_TIME=2;
  -    public static final int ACC_ERRORS=3;
  -    public static final int ACC_OVERHEAD=4;
  -    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;
  -    }
  -
  -    public long getAccount( int pos ) {
  -	return accTable[pos];
  -    }
   
   }
  
  
  
  1.3       +5 -5      jakarta-tomcat/src/share/org/apache/tomcat/facade/RequestDispatcherImpl.java
  
  Index: RequestDispatcherImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/facade/RequestDispatcherImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RequestDispatcherImpl.java	2000/06/10 17:54:27	1.2
  +++ RequestDispatcherImpl.java	2000/06/16 21:03:31	1.3
  @@ -183,8 +183,8 @@
   
   
   	// CM should have set the wrapper - call it
  -	realRequest.getWrapper().handleRequest(realRequest,
  -						realResponse);
  +	realRequest.getWrapper().service(realRequest,
  +					 realResponse);
       }
   
       public void include(ServletRequest request, ServletResponse response)
  @@ -282,7 +282,7 @@
    	// now it's really strange: we call the wrapper on the subrequest
   	// for the realRequest ( since the real request will still have the
   	// original handler/wrapper )
  -	subRequest.getWrapper().handleRequest(realRequest , realResponse);
  +	subRequest.getWrapper().service(realRequest , realResponse);
   
   	// After request, we want to restore the include attributes - for
   	// chained includes.
  @@ -318,7 +318,7 @@
   	ServletWrapper wrapper = context.getServletByName( name );
   	Request realR=((HttpServletRequestFacade)request).getRealRequest();
   	
  -	wrapper.handleRequest( realR, realR.getResponse());
  +	wrapper.service( realR, realR.getResponse());
       }
   
       /** Named forward
  @@ -329,7 +329,7 @@
   	ServletWrapper wrapper = context.getServletByName( name );
   	Request realR=((HttpServletRequestFacade)request).getRealRequest();
   	
  -	wrapper.handleRequest( realR, realR.getResponse());
  +	wrapper.service( realR, realR.getResponse());
       }    
   
       /**
  
  
  
  1.7       +13 -8     jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java
  
  Index: AccessInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AccessInterceptor.java	2000/06/16 17:08:38	1.6
  +++ AccessInterceptor.java	2000/06/16 21:03:33	1.7
  @@ -161,8 +161,6 @@
       public void addContext( ContextManager cm, Context ctx )
   	throws TomcatException
       {
  -	Container ct=ctx.getContainer();
  -	ct.setNote( secMapNote, new SecurityConstraints() );
       }
   
       /** Called when a context is removed from a CM - we must ask the mapper to
  @@ -190,10 +188,12 @@
   	Container ctxCt=ctx.getContainer();
   	SecurityConstraints ctxSecurityC=(SecurityConstraints)ctxCt.
   	    getNote( secMapNote );
  +	if( ctxSecurityC==null)
  +	    ctxCt.setNote( secMapNote, new SecurityConstraints() );
   	
   	if( ct.getRoles()!=null || ct.getTransport()!=null ) {
   	    if( debug > 0 )
  -		log( "ACCESS: Adding " + ctx.getHost() + " " +
  +		log( "addContainer() " + ctx.getHost() + " " +
   		     ctx.getPath() + " " +
   		     ct.getPath() );
   	    ctxSecurityC.addContainer( ct );
  @@ -209,7 +209,6 @@
   	Context ctx=req.getContext();
   	SecurityConstraints ctxSec=(SecurityConstraints)ctx.getContainer().
   	    getNote( secMapNote );
  -	log("XXX1 " + ctxSec + " " + debug);
   	if( ctxSec.patterns==0 ) return 0; // fast exit
   	
   	String reqURI = req.getRequestURI();
  @@ -222,12 +221,18 @@
   	for( int i=0; i< ctxSec.patterns ; i++ ) {
   	    Container ct=ctxSec.securityPatterns[i];
   	    if( match( ct, path, method ) ) {
  -		if( debug>0) log( "ACCESS: matched " + ct.getPath() + " " +
  -				  ct.getMethods() + " " +
  -				  ct.getTransport() + " " + ct.getRoles());
   		String roles[]=ct.getRoles();
   		String transport=ct.getTransport();
  -
  +		if( debug>0) {
  +		    StringBuffer sb=new StringBuffer("ACCESS: matched ");
  +		    sb.append(ct.getPath()).append(" ").
  +			append(ct.getMethods()).append(" ").
  +			append(transport).append(" ");
  +		    if( roles!=null)
  +			for( int j=0; j< roles.length; j++ )
  +			    sb.append( roles[j]).append(" ");
  +		    log( sb.toString());
  +		}
   		if( transport != null &&
   		    ! "NONE".equals( transport )) {
   		    req.setNote( reqTransportNote, transport );
  
  
  
  1.13      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/servlets/InvokerServlet.java
  
  Index: InvokerServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/servlets/InvokerServlet.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- InvokerServlet.java	2000/05/30 15:40:12	1.12
  +++ InvokerServlet.java	2000/06/16 21:03:37	1.13
  @@ -210,7 +210,7 @@
   	    }
   	}
   
  -        wrapper.handleRequest(realRequest, realResponse);
  +        wrapper.service(realRequest, realResponse);
   
   	// restore servletPath and pathInfo.
   	// Usefull because we may include with the same request multiple times.
  
  
  
  1.4       +4 -2      jakarta-tomcat/src/share/org/apache/tomcat/util/SecurityTools.java
  
  Index: SecurityTools.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SecurityTools.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SecurityTools.java	2000/05/09 17:56:42	1.3
  +++ SecurityTools.java	2000/06/16 21:03:39	1.4
  @@ -184,8 +184,10 @@
   	    // are in the same domain.
   	    String username=(String)session.getAttribute("j_username");
   	    String password=(String)session.getAttribute("j_password");
  -	    credentials.put( "username" , username );
  -	    credentials.put( "password", password);
  +	    if( username!=null && password!=null) {
  +		credentials.put( "username" , username );
  +		credentials.put( "password", password);
  +	    }
   	}
       }
   
  
  
  

Mime
View raw message