tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/startup EmbededTomcat.java
Date Thu, 28 Sep 2000 03:25:48 GMT
costin      00/09/27 20:25:48

  Modified:    src/admin/WEB-INF/classes ContextAdmin.java
               src/admin/WEB-INF/classes/tadm TomcatAdmin.java
                        TomcatAdminTEI.java TomcatIterate.java
                        TomcatIterateTEI.java
               src/etc  server.xml
               src/facade22/org/apache/tomcat/facade
                        RequestDispatcherImpl.java ServletWrapper.java
               src/facade22/org/apache/tomcat/modules/facade22
                        JspInterceptor.java
               src/share/org/apache/tomcat/core BaseInterceptor.java
                        Container.java Context.java ContextManager.java
                        Request.java Response.java
               src/share/org/apache/tomcat/request InvokerInterceptor.java
               src/share/org/apache/tomcat/startup EmbededTomcat.java
  Added:       src/facade22/org/apache/tomcat/facade
                        Servlet22Interceptor.java WebXmlReader.java
  Removed:     src/facade22/org/apache/tomcat/facade Servlet22Manager.java
               src/share/org/apache/tomcat/context WebXmlReader.java
               src/share/org/apache/tomcat/core FacadeManager.java
  Log:
  Removed FacadeManager.
  
  FacadeManager was used to allow the separation of core and facade, and
  also as a mechanism to access the real Request from a facade.
  
  The first use is replaed by normal interceptors - there is no need to use
  a special mechanism and interceptors provide much more control and power.
  
  For the second use we don't actually need the FacadeManager - instead of
  calling getAttribute() to get FM and then getRealRequest(), we can just
  get the Request directly from getAttribute() ( and same checking are done)
  
  The change also moves WebXmlReader to facade ( since it's specific to
  servlet2.2 and 2.3 will have a different version )
  We add the Servlet22Interceptor - still need to add code to support
  multiple facades at the same time.
  
  During this change I also fixed a bug in JspInterceptor and added a number
  of debug statements.
  
  Another related change ( needed to support recycle() of facades ) is
  the postRequest() callback. postService is called after all servlets, including
  included - postRequest is a better place to log and clean up after
  a client transaction ends.
  
  Expect a bit of instability after this change - will be fixed during next
  few days ( and weekend ) . The code is still the same :-)
  
  Revision  Changes    Path
  1.7       +5 -3      jakarta-tomcat/src/admin/WEB-INF/classes/ContextAdmin.java
  
  Index: ContextAdmin.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/admin/WEB-INF/classes/ContextAdmin.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ContextAdmin.java	2000/08/22 18:29:01	1.6
  +++ ContextAdmin.java	2000/09/28 03:25:41	1.7
  @@ -5,7 +5,6 @@
   import javax.servlet.http.*;
   
   import org.apache.tomcat.core.Request;
  -import org.apache.tomcat.core.FacadeManager;
   import org.apache.tomcat.core.Context;
   import org.apache.tomcat.core.ContextManager;
   import org.apache.tomcat.helper.RequestUtil;
  @@ -42,8 +41,11 @@
       }
   
       public void init(HttpServletRequest request) {
  -	FacadeManager facadeM=(FacadeManager)request.getAttribute( FacadeManager.FACADE_ATTRIBUTE);
  -	realRequest = facadeM.getRealRequest(request);
  +	//FacadeManager facadeM=(FacadeManager)request.getAttribute(
  +	// FacadeManager.FACADE_ATTRIBUTE);
  +	realRequest = (Request)request.
  +	    getAttribute( Request.ATTRIB_REAL_REQUEST );
  +
   	cm = realRequest.getContext().getContextManager();
       }
   
  
  
  
  1.3       +3 -6      jakarta-tomcat/src/admin/WEB-INF/classes/tadm/TomcatAdmin.java
  
  Index: TomcatAdmin.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/admin/WEB-INF/classes/tadm/TomcatAdmin.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TomcatAdmin.java	2000/08/22 18:29:05	1.2
  +++ TomcatAdmin.java	2000/09/28 03:25:41	1.3
  @@ -8,7 +8,6 @@
   import javax.servlet.jsp.*;
   import javax.servlet.jsp.tagext.*;
   import org.apache.tomcat.core.Request;
  -import org.apache.tomcat.core.FacadeManager;
   import org.apache.tomcat.core.Context;
   import org.apache.tomcat.core.ContextManager;
   import org.apache.tomcat.helper.RequestUtil;
  @@ -22,7 +21,6 @@
       private ContextManager cm;
       String ctxPathParam;
       String ctxPath;
  -    FacadeManager facadeM;
       PageContext pageContext;
       
       public TomcatAdmin() {}
  @@ -62,14 +60,13 @@
       }
   
       private void init(HttpServletRequest request) {
  -	facadeM=(FacadeManager)request.
  -	    getAttribute( FacadeManager.FACADE_ATTRIBUTE);
  -	Request realRequest = facadeM.getRealRequest(request);
  +	Request realRequest = (Request)
  +	    request.getAttribute( Request.ATTRIB_REAL_REQUEST);
   	cm = realRequest.getContext().getContextManager();
       }
   
       public ContextManager getContextManager(HttpServletRequest request ) {
  -	if( facadeM==null ) init( request );
  +	if( cm==null ) init( request );
           return cm;
       }
   
  
  
  
  1.3       +0 -1      jakarta-tomcat/src/admin/WEB-INF/classes/tadm/TomcatAdminTEI.java
  
  Index: TomcatAdminTEI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/admin/WEB-INF/classes/tadm/TomcatAdminTEI.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TomcatAdminTEI.java	2000/08/22 18:29:07	1.2
  +++ TomcatAdminTEI.java	2000/09/28 03:25:41	1.3
  @@ -8,7 +8,6 @@
   import javax.servlet.jsp.*;
   import javax.servlet.jsp.tagext.*;
   import org.apache.tomcat.core.Request;
  -import org.apache.tomcat.core.FacadeManager;
   import org.apache.tomcat.core.Context;
   import org.apache.tomcat.core.ContextManager;
   import org.apache.tomcat.helper.RequestUtil;
  
  
  
  1.3       +0 -1      jakarta-tomcat/src/admin/WEB-INF/classes/tadm/TomcatIterate.java
  
  Index: TomcatIterate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/admin/WEB-INF/classes/tadm/TomcatIterate.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TomcatIterate.java	2000/08/22 18:29:07	1.2
  +++ TomcatIterate.java	2000/09/28 03:25:41	1.3
  @@ -8,7 +8,6 @@
   import javax.servlet.jsp.*;
   import javax.servlet.jsp.tagext.*;
   import org.apache.tomcat.core.Request;
  -import org.apache.tomcat.core.FacadeManager;
   import org.apache.tomcat.core.Context;
   import org.apache.tomcat.core.ContextManager;
   import org.apache.tomcat.helper.RequestUtil;
  
  
  
  1.3       +0 -1      jakarta-tomcat/src/admin/WEB-INF/classes/tadm/TomcatIterateTEI.java
  
  Index: TomcatIterateTEI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/admin/WEB-INF/classes/tadm/TomcatIterateTEI.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TomcatIterateTEI.java	2000/08/22 18:29:08	1.2
  +++ TomcatIterateTEI.java	2000/09/28 03:25:41	1.3
  @@ -8,7 +8,6 @@
   import javax.servlet.jsp.*;
   import javax.servlet.jsp.tagext.*;
   import org.apache.tomcat.core.Request;
  -import org.apache.tomcat.core.FacadeManager;
   import org.apache.tomcat.core.Context;
   import org.apache.tomcat.core.ContextManager;
   import org.apache.tomcat.helper.RequestUtil;
  
  
  
  1.46      +5 -1      jakarta-tomcat/src/etc/server.xml
  
  Index: server.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/etc/server.xml,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- server.xml	2000/09/26 03:49:52	1.45
  +++ server.xml	2000/09/28 03:25:42	1.46
  @@ -105,7 +105,7 @@
           <ContextInterceptor className="org.apache.tomcat.context.AutoSetup" />
   
           <ContextInterceptor 
  -            className="org.apache.tomcat.context.WebXmlReader" />
  +            className="org.apache.tomcat.facade.WebXmlReader" />
   
           <!-- Uncomment out if you have JDK1.2 and want to implement
   	     the Java SecurityManager
  @@ -216,6 +216,10 @@
           <!-- Loaded last since JSP's that load-on-startup use request handling -->
           <ContextInterceptor 
               className="org.apache.tomcat.context.LoadOnStartupInterceptor" />
  +
  +        <!-- Loaded last since JSP's that load-on-startup use request handling -->
  +        <RequestInterceptor 
  +            className="org.apache.tomcat.facade.Servlet22Interceptor" />
   
         <!-- ==================== Connectors ==================== -->
   
  
  
  
  1.3       +8 -0      jakarta-tomcat/src/facade22/org/apache/tomcat/facade/RequestDispatcherImpl.java
  
  Index: RequestDispatcherImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/RequestDispatcherImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RequestDispatcherImpl.java	2000/08/25 18:04:34	1.2
  +++ RequestDispatcherImpl.java	2000/09/28 03:25:44	1.3
  @@ -280,6 +280,14 @@
   	realRequest.setAttribute("javax.servlet.include.query_string",
   				 queryString);
   	
  +	if( false ) {
  +	    System.out.println("RD: " + old_request_uri + " " +
  +			       old_context_path + " " + old_servlet_path +
  +			       " " + old_path_info + " " + old_query_string);
  +	    System.out.println("NEW: " + context.getPath() + " " + path + " "
  +			       + subRequest.getServletPath() + " " +
  +			       subRequest.getPathInfo() + " " + queryString);
  +	}
   	
   	// Not explicitely stated, but we need to save the old parameters
   	// before adding the new ones
  
  
  
  1.5       +8 -1      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ServletWrapper.java	2000/09/24 18:10:58	1.4
  +++ ServletWrapper.java	2000/09/28 03:25:45	1.5
  @@ -398,8 +398,15 @@
   	// XXX
   	HttpServletRequest reqF= (HttpServletRequest)req.getFacade();
   	HttpServletResponse resF= (HttpServletResponse)res.getFacade();
  +	if( reqF == null || resF == null ||
  +	    ! (reqF instanceof HttpServletRequestFacade) ) {
  +	    reqF=new HttpServletRequestFacade(req);
  +	    resF=new HttpServletResponseFacade(res);
  +	    req.setFacade( reqF );
  +	    res.setFacade( resF );
  +	}
  +	
   	doService( reqF, resF );
  -
       }
   
       protected void doService(HttpServletRequest req, HttpServletResponse res)
  
  
  
  1.1                  jakarta-tomcat/src/facade22/org/apache/tomcat/facade/Servlet22Interceptor.java
  
  Index: Servlet22Interceptor.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat.facade;
  
  import org.apache.tomcat.util.*;
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.logging.*;
  import java.io.*;
  import java.net.*;
  import java.security.*;
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   *   Control class for facades - this is the only "gate" between servlets
   *   and tomcat.
   *
   *   This is an important security component, shouldn't be used for
   *   anything else. Please keep all the code short and clean - and review
   *   everything very often.
   *  
   */
  public final class Servlet22Interceptor
      extends BaseInterceptor
  {
      public static final String SERVLET_STAMP = " ( JSP 1.1; Servlet 2.2 )";
  	
      public Servlet22Interceptor() {
      }
  
      public Servlet22Interceptor(Context ctx) {
      }
  
      // -------------------- implementation
      private void setEngineHeader(Context ctx) {
          String engineHeader=ctx.getEngineHeader();
  
  	// EngineHeader can be set as a Context Property!
  	if( engineHeader==null) {
  	    StringBuffer sb=new StringBuffer();
  	    sb.append(ContextManager.TOMCAT_NAME);
  	    sb.append("/");
  	    sb.append(ContextManager.TOMCAT_VERSION );
  	    sb.append(SERVLET_STAMP);
  	    engineHeader=sb.toString();
  	}
  	ctx.setEngineHeader( engineHeader );
      }
  
  
      public void addContext( ContextManager cm, Context ctx )
  	throws TomcatException
      {
  	ctx.setFacade(new ServletContextFacade(cm , ctx));
  	setEngineHeader( ctx );
      }
  
      public void addContainer( Container ct )
      	throws TomcatException
      {
  	String hN=ct.getHandlerName();
  	if( hN == null ) return;
  			     
  	if( ct.getHandler() == null ) {
  	    // we have a container with a valid handler name but without
  	    // a Handler. Create a ServletWrapper
  	    ServletWrapper sw=new ServletWrapper();
  	    sw.setName( hN );
  	    sw.setContext( ct.getContext() );
  	    log( "Create handler ");
  	    ct.setHandler(sw);
  	    ct.getContext().addServlet(  sw );
  	}
  	    
      }
      
      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
  
  	log( "Recycling " + rreq );
  	HttpServletRequest req=(HttpServletRequest)rreq.getFacade();
  	if( ! (req instanceof HttpServletRequestFacade))
  	    return 0;
  	
  	((HttpServletRequestFacade)req).recycle();
  
  	// recycle response
  	//	Response rres=rreq.getResponse();
  	if( rres== null )
  	    return 0;
  	
  	HttpServletResponse res=(HttpServletResponse)rres.getFacade();
  	if( res!=null) ((HttpServletResponseFacade)res).recycle();
  
  	// recycle output stream
  	// XXX XXX implement it
  
  	return 0;
      }
  }
      
  
  
  
  1.1                  jakarta-tomcat/src/facade22/org/apache/tomcat/facade/WebXmlReader.java
  
  Index: WebXmlReader.java
  ===================================================================
  package org.apache.tomcat.facade;
  
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.util.*;
  import org.apache.tomcat.util.xml.*;
  import org.apache.tomcat.logging.*;
  import java.beans.*;
  import java.io.*;
  import java.io.IOException;
  import java.lang.reflect.*;
  import java.util.*;
  import java.util.StringTokenizer;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.xml.sax.*;
  import org.xml.sax.helpers.*;
  import org.w3c.dom.*;
  
  // XXX XXX Specific to servlet 2.2 
  
  /**
   * Read a servlet2.2 web.xml file and call the apropriate internal API
   * to set up the configuration.
   * 
   * @author costin@dnt.ro
   */
  public class WebXmlReader extends BaseInterceptor {
      public static final String defaultWelcomeList[]={"index.jsp", "index.html", "index.htm"};
      public static final int DEFAULT_SESSION_TIMEOUT=30;
  
      private static StringManager sm =StringManager.getManager("org.apache.tomcat.resources");
      boolean validate=true;
  
      public WebXmlReader() {
      }
  
      public void setValidate( boolean b ) {
  	validate=b;
      }
  
      private Handler addServlet( Context ctx, String name, String classN )
  	throws TomcatException
      {
  	Handler sw=new ServletWrapper(); // ctx.createHandler();
  	sw.setContext(ctx);
  	sw.setServletName( name );
  	sw.setServletClass( classN);
  	ctx.addServlet( sw );
  	sw.setLoadOnStartUp( -2147483646 );
  	return sw;
      }
      
      private void setDefaults( Context ctx )
  	throws TomcatException
      {
  	//	addServlet( ctx, "default", "org.apache.tomcat.servlets.DefaultServlet");
  // 	addServlet( ctx, "invoker", "org.apache.tomcat.servlets.InvokerServlet");
  	Handler sw=addServlet( ctx, "jsp", "org.apache.jasper.servlet.JspServlet");
  	//	sw.addInitParam("jspCompilerPlugin", "org.apache.jasper.compiler.JikesJavaCompiler");
  
  // 	ctx.addServletMapping( "/servlet/*", "invoker");
  	ctx.addServletMapping( "*.jsp", "jsp");
  	
  	ctx.setSessionTimeOut( 30 );
  
  	// mime-mapping - are build into MimeMap.
  	// Note that default mappings are based on existing registered types.
  
  	// index pages - still use the hack, but it'll go away soon
  	for( int i=0; i< defaultWelcomeList.length; i++ )
  	    ctx.addWelcomeFile( defaultWelcomeList[i]);
  	ctx.expectUserWelcomeFiles();
      }
  
  
      private void readDefaultWebXml( Context ctx ) throws TomcatException {
  	ContextManager cm=ctx.getContextManager();
  	String home = cm.getHome();
  	
  	File default_xml=new File( home + "/conf/web.xml" );
  	
  	// try the default ( installation )
  	if( ! default_xml.exists() ) {
  	    String tchome=ctx.getContextManager().getInstallDir();
  	    if( tchome != null )
  		default_xml=new File( tchome + "/conf/web.xml");
  	}
  	
  	if( ! default_xml.exists() )
  	    return;
  	
  	processWebXmlFile(ctx , default_xml.getPath());
  	ctx.expectUserWelcomeFiles();
      }
      
      public void contextInit(Context ctx) throws TomcatException {
  	if( ctx.getDebug() > 0 ) ctx.log("XmlReader - init  " + ctx.getPath() + " " + ctx.getDocBase() );
  	ContextManager cm=ctx.getContextManager();
  	
  	try {
  	    // Default init
  	    setDefaults( ctx );
  
  	    // We may read a "default" web.xml from INSTALL/conf/web.xml -
  	    // the code is commented out right now because we want to
  	    // consolidate the config in server.xml ( or API calls ),
  	    // we may put it back for 3.2 if needed.
  	    // note that web.xml have to be cleaned up - only diff from
  	    // default should be inside
  	    // readDefaultWebXml( ctx );
  	    
  	    File inf_xml = cm.getAbsolute( new File(ctx.getDocBase() +
  						    "/WEB-INF/web.xml"));
  	    if( inf_xml.exists() )
  		processWebXmlFile(ctx, inf_xml.getPath() );
  
  	} catch (Exception e) {
  	    String msg = sm.getString("context.getConfig.e",ctx.getPath() + " " + ctx.getDocBase());
  	    log(msg, e);
  	}
  
      }
  
      void processWebXmlFile( Context ctx, String file) {
  	try {
  	    File f=new File(FileUtil.patch(file));
  	    if( ! f.exists() ) {
  		ctx.log( "File not found " + f + ", using only defaults" );
  		return;
  	    }
  	    if( ctx.getDebug() > 0 ) ctx.log("Reading " + file );
  	    XmlMapper xh=new XmlMapper();
  	    if( validate ) {
  		xh.setValidating(true);
  		//	    if( ctx.getDebug() > 5 ) xh.setDebug( 3 );
  	    }
  
  	    // By using dtdURL you brake most parsers ( at least xerces )
  	    xh.registerDTDRes("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
  			      "/org/apache/tomcat/resources/web.dtd");
  
  	    xh.addRule("web-app/context-param", xh.methodSetter("addInitParameter", 2) );
  	    xh.addRule("web-app/context-param/param-name", xh.methodParam(0) );
  	    xh.addRule("web-app/context-param/param-value", xh.methodParam(1) );
  
  	    xh.addRule("web-app/description", xh.methodSetter("setDescription", 0) );
  	    xh.addRule("web-app/icon/small-icon", xh.methodSetter("setIcon", 0) );
  	    xh.addRule("web-app/distributable", xh.methodSetter("setDistributable", 0) );
  
  	    xh.addRule("web-app/servlet-mapping", xh.methodSetter("addServletMapping", 2) );
  	    xh.addRule("web-app/servlet-mapping/servlet-name", xh.methodParam(1) );
  	    xh.addRule("web-app/servlet-mapping/url-pattern", xh.methodParam(0) );
  
  	    xh.addRule("web-app/taglib", xh.methodSetter("addTaglib", 2) );
  	    xh.addRule("web-app/taglib/taglib-uri", xh.methodParam(0) );
  	    xh.addRule("web-app/taglib/taglib-location", xh.methodParam(1) );
  
  	    xh.addRule("web-app/env-entry", xh.methodSetter("addEnvEntry", 4) );
  	    xh.addRule("web-app/env-entry/env-entry-name", xh.methodParam(0) );
  	    xh.addRule("web-app/env-entry/env-entry-type", xh.methodParam(1) );
  	    xh.addRule("web-app/env-entry/env-entry-value", xh.methodParam(2) );
  	    xh.addRule("web-app/env-entry/description", xh.methodParam(3) );
  
  	    xh.addRule("web-app/login-config", xh.methodSetter("setLoginConfig", 4) );
  	    xh.addRule("web-app/login-config/auth-method", xh.methodParam(0) );
  	    xh.addRule("web-app/login-config/realm-name", xh.methodParam(1) );
  	    xh.addRule("web-app/login-config/form-login-config/form-login-page", xh.methodParam(2) );
  	    xh.addRule("web-app/login-config/form-login-config/form-error-page", xh.methodParam(3) );
  
  	    xh.addRule("web-app/mime-mapping", xh.methodSetter("addContentType", 2) );
  	    xh.addRule("web-app/mime-mapping/extension", xh.methodParam(0) );
  	    xh.addRule("web-app/mime-mapping/mime-type", xh.methodParam(1) );
  
  	    xh.addRule("web-app/welcome-file-list/welcome-file", xh.methodSetter("addWelcomeFile", 0) );
  
  	    xh.addRule("web-app/error-page", xh.methodSetter("addErrorPage",2) );
  	    xh.addRule("web-app/error-page/error-code", xh.methodParam(0) );
  	    xh.addRule("web-app/error-page/exception-type", xh.methodParam(0) );
  	    xh.addRule("web-app/error-page/location", xh.methodParam(1) );
  
  	    xh.addRule("web-app/session-config", xh.methodSetter("setSessionTimeOut", 1, new String[]{"int"}));
  	    xh.addRule("web-app/session-config/session-timeout", xh.methodParam(0));
  
  	    // Servlet
  	    xh.addRule("web-app/servlet", xh.objectCreate("org.apache.tomcat.facade.ServletWrapper") ); // servlet-wrapper
  	    xh.addRule("web-app/servlet", xh.setParent( "setContext") ); // remove it from stack when done
  	    xh.addRule("web-app/servlet", xh.addChild("addServlet", "org.apache.tomcat.core.Handler") );
  	    // remove it from stack when done
  	    xh.addRule("web-app/servlet/servlet-name", xh.methodSetter("setServletName",0) );
  	    xh.addRule("web-app/servlet/servlet-class", xh.methodSetter("setServletClass",0));
  	    xh.addRule("web-app/servlet/jsp-file",xh.methodSetter("setPath",0));
  
  	    xh.addRule("web-app/servlet/security-role-ref", xh.methodSetter("addSecurityMapping", 3) );
  	    xh.addRule("web-app/servlet/security-role-ref/role-name", xh.methodParam(0) );
  	    xh.addRule("web-app/servlet/security-role-ref/role-link", xh.methodParam(1) );
  	    xh.addRule("web-app/servlet/security-role-ref/description", xh.methodParam(2) );
  
  	    xh.addRule("web-app/servlet/init-param", xh.methodSetter("addInitParam", 2) ); // addXXX
  	    xh.addRule("web-app/servlet/init-param/param-name", xh.methodParam(0) );
  	    xh.addRule("web-app/servlet/init-param/param-value", xh.methodParam(1) );
  
  	    xh.addRule("web-app/servlet/icon/small-icon", xh.methodSetter("setIcon",0 )); // icon, body
  	    xh.addRule("web-app/servlet/description", xh.methodSetter("setDescription", 0) ); // description, body
  	    xh.addRule("web-app/servlet/load-on-startup", xh.methodSetter("setLoadOnStartUp", 0 ));
  
  
  	    addSecurity( xh );
  
  	    Object ctx1=xh.readXml(f, ctx);
  	} catch(Exception ex ) {
  	    log("ERROR reading " + file, ex);
  	    // XXX we should invalidate the context and un-load it !!!
  	}
      }
  
      // Add security rules - complex code
      void addSecurity( XmlMapper xh ) {
  	xh.addRule("web-app/security-constraint",
  		   new SCAction() );
  
  	xh.addRule("web-app/security-constraint/user-data-constraint/transport-guarantee",
  		   new XmlAction() {
  			   public void end( SaxContext ctx) throws Exception {
  			       Stack st=ctx.getObjectStack();
  			       SecurityConstraint rc=(SecurityConstraint)st.peek();
  			       String  body=ctx.getBody().trim();
  			       rc.setTransport( body );
  			   }
  		       }
  		   );
  	xh.addRule("web-app/security-constraint/auth-constraint/role-name",
  		   new XmlAction() {
  			   public void end( SaxContext ctx) throws Exception {
  			       Stack st=ctx.getObjectStack();
  			       SecurityConstraint rc=(SecurityConstraint)st.peek();
  			       String  body=ctx.getBody().trim();
  			       rc.addRole( body );
  			   }
  		       }
  		   );
  
  	xh.addRule("web-app/security-constraint/web-resource-collection",
  		   new XmlAction() {
  			   public void start( SaxContext ctx) throws Exception {
  			       Stack st=ctx.getObjectStack();
  			       st.push(new ResourceCollection());
  			   }
  			   public void end( SaxContext ctx) throws Exception {
  			       Stack st=ctx.getObjectStack();
  			       ResourceCollection rc=(ResourceCollection)st.pop();
  			       SecurityConstraint sc=(SecurityConstraint)st.peek();
  			       st.push( rc );
  			       sc.addResourceCollection( rc );
  			   }
  			   public void cleanup( SaxContext ctx) {
  			       Stack st=ctx.getObjectStack();
  			       Object o=st.pop();
  			   }
  		       }
  		   );
  
  	xh.addRule("web-app/security-constraint/web-resource-collection/url-pattern",
  		   new XmlAction() {
  			   public void end( SaxContext ctx) throws Exception {
  			       Stack st=ctx.getObjectStack();
  			       ResourceCollection rc=(ResourceCollection)st.peek();
  			       String  body=ctx.getBody().trim();
  			       rc.addUrlPattern( body );
  			   }
  		       }
  		   );
  	xh.addRule("web-app/security-constraint/web-resource-collection/http-method",
  		   new XmlAction() {
  			   public void end( SaxContext ctx) throws Exception {
  			       Stack st=ctx.getObjectStack();
  			       ResourceCollection rc=(ResourceCollection)st.peek();
  			       String  body=ctx.getBody().trim();
  			       rc.addHttpMethod( body );
  			   }
  		       }
  		   );
      }
  
  }
  
  /** Specific action for Security-constraint
   */
  class SCAction extends XmlAction {
      public void start( SaxContext ctx) throws Exception {
  	Stack st=ctx.getObjectStack();
  	st.push(new SecurityConstraint());
      }
      public void end( SaxContext ctx) throws Exception {
  	Stack st=ctx.getObjectStack();
  	String tag=ctx.getTag(ctx.getTagCount()-1);
  	SecurityConstraint sc=(SecurityConstraint)st.pop();
  	Context context=(Context)st.peek();
  
  	st.push( sc ); // restore stack
  	// add all patterns that will need security
  
  	String roles[]=sc.getRoles();
  	String transport=sc.getTransport();
  	Enumeration en=sc.getResourceCollections();
  	while( en.hasMoreElements()) {
  	    ResourceCollection rc=(ResourceCollection)en.nextElement();
  	    String paths[]=rc.getPatterns();
  	    String meths[]=rc.getMethods();
  	    context.addSecurityConstraint(  paths, meths ,
  					    roles, transport);
  	}
      }
      public void cleanup( SaxContext ctx) {
  	Stack st=ctx.getObjectStack();
  	Object o=st.pop();
      }
  }
  
  class SecurityConstraint {
      Vector roles=new Vector();
      String transport;
      Vector resourceC=new Vector();
  
      public SecurityConstraint() {
      }
  
      public void setTransport( String transport ) {
  	this.transport=transport;
      }
  
      public String getTransport() {
  	return this.transport;
      }
  
      public void addRole(String role ) {
  	roles.addElement( role );
      }
  
      public void addResourceCollection( ResourceCollection rc ) {
  	resourceC.addElement( rc );
      }
  
      public String []getRoles() {
  	String rolesA[]=new String[roles.size()];
  	for( int i=0; i< rolesA.length; i++ ) {
  	    rolesA[i]=(String)roles.elementAt( i );
  	}
  	return rolesA;
      }
      public Enumeration getResourceCollections() {
  	return resourceC.elements();
      }
  }
  
  class ResourceCollection {
      Vector urlP=new Vector();
      Vector methods=new Vector();
  
      public ResourceCollection() {
      }
  
      public void addUrlPattern( String pattern ) {
  	urlP.addElement( pattern );
      }
  
      public void addHttpMethod( String method ) {
  	methods.addElement( method );
      }
  
      public String []getMethods() {
  	String methodsA[]=new String[methods.size()];
  	for( int i=0; i< methodsA.length; i++ ) {
  	    methodsA[i]=(String)methods.elementAt( i );
  	}
  	return methodsA;
      }
  
      public String []getPatterns() {
  	String patternsA[]=new String[urlP.size()];
  	for( int i=0; i< patternsA.length; i++ ) {
  	    patternsA[i]=(String)urlP.elementAt( i );
  	}
  	return patternsA;
      }
  
  
  }
  
  
  
  
  1.5       +16 -12    jakarta-tomcat/src/facade22/org/apache/tomcat/modules/facade22/JspInterceptor.java
  
  Index: JspInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/modules/facade22/JspInterceptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JspInterceptor.java	2000/09/26 03:49:53	1.4
  +++ JspInterceptor.java	2000/09/28 03:25:45	1.5
  @@ -118,6 +118,9 @@
   
       public int requestMap( Request req ) {
   	Handler wrapper=(Handler)req.getWrapper();
  +
  +	//	log( "Try: " + req );
  +	
   	if( wrapper!=null && ! "jsp".equals( wrapper.getName())
   	    && wrapper.getPath() == null)
   	    return 0;
  @@ -149,12 +152,12 @@
   	    
   	    // jump version number - the file needs to
   	    // be recompiled, and we don't want a reload
  -	    log( "Before sync block  " + jspInfo );
  +	    if( debug > 0 ) log( "Before sync block  " + jspInfo );
   	    synchronized( jspInfo ) {
   		//		if( debug>0 )
   		if( jspInfo.jspSource.lastModified() 
   		    > jspInfo.compileTime ) {
  -		    log( "Compiling " + jspInfo );
  +		    if( debug > 0 ) log( "Compiling " + jspInfo );
   		
   		    jspInfo.nextVersion();
   		    compile( req, jspInfo );
  @@ -188,7 +191,7 @@
   		wrapper=new ServletWrapper();
   		wrapper.setContext(ctx);
   		wrapper.setServletName(servletName);
  -		wrapper.setPath(classN);
  +		wrapper.setPath( servletPath );
   		wrapper.setOrigin( Handler.ORIGIN_INVOKER );
   		ctx.addServlet( wrapper );
   		
  @@ -210,7 +213,7 @@
       /** Convert the .jsp file to a java file, then compile it to class
        */
       void compile(Request req, JspInfo jspInfo ) {
  -	log( "Compiling " + jspInfo.realClassPath);
  +	if( debug > 0 ) log( "Compiling " + jspInfo.realClassPath);
   	try {
   	    // make sure we have the directories
   	    File dir=new File( jspInfo.outputDir + "/" + jspInfo.pkgDir);
  @@ -450,14 +453,15 @@
   	    updateVersionedPaths();
   	}
   
  -// 	log("uri=" + uri +
  -// 			   //" outputDir=" + outputDir +
  -// 			   //" jspSource=" + jspSource +
  -// 			   " pkgDir=" + pkgDir +
  -// 			   " baseClassN=" + baseClassN +
  -// 			   " ext=" + ext +
  -// 			   " mapPath=" + mapPath +
  -// 			   " version=" + version);
  +	if( false )
  +	    log("uri=" + uri +
  +		//" outputDir=" + outputDir +
  +		//" jspSource=" + jspSource +
  +		" pkgDir=" + pkgDir +
  +		" baseClassN=" + baseClassN +
  +		" ext=" + ext +
  +		" mapPath=" + mapPath +
  +		" version=" + version);
   	
   	
       }
  
  
  
  1.20      +33 -14    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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- BaseInterceptor.java	2000/09/26 05:17:06	1.19
  +++ BaseInterceptor.java	2000/09/28 03:25:46	1.20
  @@ -245,6 +245,21 @@
   	return 0;
       }
   
  +    /** Experimental hook: called after the request is finished,
  +	before returning to the caller. This will be called only
  +	on the main request, and will give interceptors a chance
  +	to clean up - that would be difficult in postService,
  +	that is called after included servlets too.
  +
  +	Don't use this hook until it's marked final, I added it
  +	to deal with recycle() in facades - if we find a better
  +	solution this can go. ( unless people find it
  +	useful
  +     */
  +    public int postRequest(Request request, Response response) {
  +	return 0;
  +    }
  +
       public String []getMethods()  {
   	return methods;
       }
  @@ -270,23 +285,27 @@
       {
       }
   
  -    /** A new location was added to the server. A location is defined as a
  -     *  set of URL patterns with common properties. All servlet mappings
  -     *  and security constraints are in this category - with a common
  -     *  handler and a common set of authorized roles.
  +    /** Notify that certain properties are defined for a URL pattern.
  +     *  Properties can be a "handler" that will be called for URLs
  +     *  matching the pattern or "security constraints" ( or any other
  +     *  properties that can be associated with URL patterns )
        *
  -     *  An interceptor interested in mapping  must implement this method
  -     *  and construct it's internal representation. The mapper is _required_
  -     *  to find the Container associated with a request using the mapping
  -     *  rules defined in the Servlet API.
  +     *  Interceptors will maintain their own mapping tables if they are
  +     *  interested in a certain property. General-purpose mapping
  +     *  code is provided in utils.
        *
  -     *  The interceptor must also take care of "merging" parent with child
  -     *  containers. It is possible that this method will be called several
  -     *  times for the same url pattern ( for example to define a handler
  -     *  and then security constraints), the interceptor needs to
  -     *  merge the 2 containers.
  +     *  The method will be called once for every properties associated
  +     *  with a URL - it's up to the interceptor to interpret the URL
  +     *  and deal with "merging".
        * 
  -     *  XXX  define "merging" of containers 
  +     *  A Container that defines a servlet mapping ( handler ) will have
  +     *  the handlerName set to the name of the handler. The Handler
  +     *  ( getHandler) can be null for dynamically added servlets, and
  +     *  will be set by a facade interceptor.
  +     *
  +     *   XXX We use this hook to create ServletWrappers for dynamically
  +     *  added servlets in InvokerInterceptor ( JspInterceptor is JDK1.2
  +     *  specific ). It may be good to add a new hook specifically for that
        */
       public void addContainer(Container container)
   	throws TomcatException
  
  
  
  1.34      +20 -3     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.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- Container.java	2000/09/26 05:17:06	1.33
  +++ Container.java	2000/09/28 03:25:46	1.34
  @@ -124,6 +124,7 @@
       /** The handler associated with this container.
        */
       Handler handler;
  +    String handlerName;
       
       /** Security constraints associated with this Container
        */
  @@ -262,8 +263,6 @@
   
       // -------------------- Mapping RHS --------------------
       
  -    /** The handler for this container
  -     */
       public Handler getHandler() {
   	return handler;
       }
  @@ -274,6 +273,24 @@
   	handler=h;
       }
   
  +    public void setHandlerName(String hn) {
  +	handlerName=hn;
  +    }
  +
  +    /** The handler name for this container.
  +     *  @return null if no handler is defined for this
  +     *          container ( this container defines only
  +     *          security or other type of properties, but
  +     *          not a handler )
  +     */
  +    public String getHandlerName() {
  +	if( handlerName != null ) 
  +	    return handlerName;
  +	if( handler != null )
  +	    return handler.getName();
  +	return null;
  +    }
  +
       /** If not null, this container can only be accessed by users
        *  in roles.
        */
  @@ -359,7 +376,7 @@
   	"requestMap", "contextMap", "authenticate",
   	"authorize", "preService", "beforeBody",
   	"newSessionRequest", "beforeCommit",
  -	"afterBody", "postService",
  +	"afterBody", "postService", "postRequest",
   	// special case - all interceptors will be added to the "context"
   	// chain. We plan to use a simpler Event/Listener model for
   	// all context hooks, since they don't have any performance requirement
  
  
  
  1.119     +69 -52    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.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- Context.java	2000/09/26 05:17:06	1.118
  +++ Context.java	2000/09/28 03:25:46	1.119
  @@ -180,7 +180,7 @@
       Vector vhostAliases=new Vector();
   
       String facadeClassName;
  -    FacadeManager facadeM;
  +    //    FacadeManager facadeM;
       
       public Context() {
   	defaultContainer=new Container();
  @@ -195,8 +195,8 @@
   	I'm not sure if this method is good - it adds deps to upper layers.
        */
       public Object getFacade() {
  -        if(contextFacade==null )
  -	    contextFacade = getFacadeManager().createServletContextFacade( this );
  +//         if(contextFacade==null )
  +// 	    contextFacade = getFacadeManager().createServletContextFacade( this );
   	return contextFacade;
       }
   
  @@ -217,15 +217,15 @@
   	contextM=cm;
       }
   
  -    public void setFacadeClassName(String s ) {
  -	facadeClassName=s;
  -    }
  +//     public void setFacadeClassName(String s ) {
  +// 	facadeClassName=s;
  +//     }
   
  -    public String getFacadeClassName() {
  -	return facadeClassName;
  -    }
  +//     public String getFacadeClassName() {
  +// 	return facadeClassName;
  +//     }
   
  -    private static final String DEFAULT_FACADE="org.apache.tomcat.facade.Servlet22Manager";
  +//     private static final String DEFAULT_FACADE="org.apache.tomcat.facade.Servlet22Interceptor";
   
       /** The servlet API variant that will be used for requests in this
        *  context
  @@ -233,28 +233,29 @@
       public void setServletAPI( String s ) {
   	if( s!=null &&
   	    ( s.endsWith("23") || s.endsWith("2.3")) ) {
  -	    facadeClassName="org.apache.tomcat.facade23.Servlet23Manager";
  +	    //	    facadeClassName="org.apache.tomcat.facade23.Servlet23Manager";
   	} else {
  -	    facadeClassName=DEFAULT_FACADE;
  +	    // facadeClassName=DEFAULT_FACADE;
   	}
       }
   
  -    public FacadeManager getFacadeManager() {
  -	if( facadeM==null ) {
  -	    if( facadeClassName==null) 
  -		facadeClassName=DEFAULT_FACADE;
  -	    try {
  -		Class facadeMC=Class.forName( facadeClassName );
  -		if( facadeMC==null )
  -		    facadeMC=Class.forName( DEFAULT_FACADE );
  -		Constructor cons=facadeMC.getConstructor( new Class[] { this.getClass() });
  -		facadeM=(FacadeManager)cons.newInstance( new Object[] {this });
  -	    } catch( Exception ex ) {
  -		ex.printStackTrace();
  -	    }
  -	}
  -	return facadeM;
  -    }
  +//     public FacadeManager getFacadeManager() {
  +// 	log( "getFacadeManager called ! " , new Throwable());
  +// 	if( facadeM==null ) {
  +// 	    if( facadeClassName==null) 
  +// 		facadeClassName=DEFAULT_FACADE;
  +// 	    try {
  +// 		Class facadeMC=Class.forName( facadeClassName );
  +// 		if( facadeMC==null )
  +// 		    facadeMC=Class.forName( DEFAULT_FACADE );
  +// 		Constructor cons=facadeMC.getConstructor( new Class[] { this.getClass() });
  +// 		facadeM=(FacadeManager)cons.newInstance( new Object[] {this });
  +// 	    } catch( Exception ex ) {
  +// 		ex.printStackTrace();
  +// 	    }
  +// 	}
  +// 	return facadeM;
  +//     }
   
       /** Base URL for this context
        */
  @@ -464,10 +465,10 @@
   		if( ! allowAttribute(name) ) return null;
   		return this;
   	    }
  -	    if( name.equals(FacadeManager.FACADE_ATTRIBUTE)) {
  -		if( ! allowAttribute(name) ) return null;
  -		return this.getFacadeManager();
  -	    }
  +	    // 	    if( name.equals(FacadeManager.FACADE_ATTRIBUTE)) {
  +	    // 		if( ! allowAttribute(name) ) return null;
  +	    // 		return this.getFacadeManager();
  +	    // 	    }
   	    return null; // org.apache.tomcat namespace is reserved in tomcat
   	} else {
               Object o = attributes.get(name);
  @@ -583,11 +584,16 @@
   
       /**
        * Maps a named servlet to a particular path or extension.
  +     *
        * If the named servlet is unregistered, it will be added
  -     * and subsequently mapped.
  +     * and subsequently mapped. The servlet can be set by intereceptors
  +     * during addContainer() hook.
        *
  -     * Note that the order of resolution to handle a request is:
  +     * If the mapping already exists it will be replaced by the new
  +     * mapping.
        *
  +     * Note that the servlet 2.2 standard mapings are:
  +     *
        *    exact mapped servlet (eg /catalog)
        *    prefix mapped servlets (eg /foo/bar/*)
        *    extension mapped servlets (eg *jsp)
  @@ -603,27 +609,38 @@
   	    Container ct=(Container)containers.get( path );
   	    removeContainer( ct );
   	}
  -        Handler sw = (Handler)servlets.get(servletName);
  +
  +	// sw may be null - in wich case interceptors may
  +	// set it 
  +        Handler sw = getServletByName(servletName);
  +	
  +	Container map=new Container();
  +	map.setContext( this );
  +	map.setHandlerName( servletName );
  +	map.setHandler( sw );
  +	map.setPath( path );
  +
  +	// callback - hooks are called. 
  +	contextM.addContainer( map );
  +
  +	sw = getServletByName(servletName);
  +	
  +	
   	if (sw == null) {
  -	    // Strict web.xml
  -	    throw new TomcatException( "Mapping with invalid servlet name " +
  +	    // web.xml validation - a mapping with no servlet
  +	    // rollback
  +	    contextM.removeContainer( map );
  + 	    throw new TomcatException( "Mapping with invalid servlet name " +
   				       path + " " + servletName );
  -	    // Workaround for frequent "bug" in web.xmls
  -	    // Declare a default mapping
  -	    // log("Mapping with unregistered servlet " + servletName );
  -	    // 	    sw = addServlet( servletName, servletName );
   	}
  +
  +	// override defaultServlet XXX do we need defaultServlet?
   	if( "/".equals(path) )
   	    defaultServlet = sw;
   
  +	containers.put( path, map );
   	mappings.put( path, sw );
   
  -	Container map=new Container();
  -	map.setContext( this );
  -	map.setHandler( sw );
  -	map.setPath( path );
  -	contextM.addContainer( map );
  -	containers.put( path, map );
       }
   
       /** Will add a new security constraint:
  @@ -698,9 +715,9 @@
   	return (Handler)servlets.get(servletName);
       }
   
  -    public Handler createHandler() {
  -	return getFacadeManager().createHandler();
  -    }
  +//     public Handler createHandler() {
  +// 	return getFacadeManager().createHandler();
  +//     }
       
       /**
        * Add a servlet with the given name to the container. The
  @@ -717,7 +734,7 @@
   	//	log("Adding servlet " + name  + " " + wrapper);
   
           // check for duplicates
  -        if (servlets.get(name) != null) {
  +        if (getServletByName(name) != null) {
   	    log("Removing duplicate servlet " + name  + " " + wrapper);
               removeServletByName(name);
   	    //	    getServletByName(name).destroy();
  @@ -1057,7 +1074,7 @@
   	return trusted;
       }
   
  -    private boolean allowAttribute( String name ) {
  +    boolean allowAttribute( String name ) {
   	// check if we can access this attribute.
   	if( isTrusted() ) return true;
   	log( "Illegal access to internal attribute ", null, Logger.ERROR);
  
  
  
  1.136     +25 -0     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.135
  retrieving revision 1.136
  diff -u -r1.135 -r1.136
  --- ContextManager.java	2000/09/26 05:17:07	1.135
  +++ ContextManager.java	2000/09/28 03:25:46	1.136
  @@ -580,6 +580,7 @@
   	    handleError( req, res, ex );
   	}
   	finally {
  +	    doPostRequest(req, res);
   	    req.recycle();
   	    res.recycle();
   	}
  @@ -767,6 +768,15 @@
   	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);
   
  @@ -837,6 +847,7 @@
   	}
   
   	Request lr = new Request();
  +	lr.setContextManager( this );
   	lr.setRequestURI( urlPath );
   	lr.setQueryString( queryString );
   	return lr;
  @@ -1359,6 +1370,20 @@
       public void setContainer(Container newDefaultContainer) {
           defaultContainer = newDefaultContainer;
       }
  +
  +
  +    // Do we need that ?
  +    
  +    //     /** Map the context facade back to the context.
  +    // 	This call doesn't involve any security checks, and
  +    // 	can be used by internal components (  they
  +    // 	already have access to ContextManager ).
  +    // 	Servlets need to call getAttribute(), and that
  +    // 	will do the required security checks
  +    //     */
  +    //     public Context getRealContext( Object facade ) {
  +    // 	return null;
  +    //     }
   
   
   }
  
  
  
  1.63      +38 -19    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.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- Request.java	2000/09/25 07:20:14	1.62
  +++ Request.java	2000/09/28 03:25:46	1.63
  @@ -80,6 +80,10 @@
    * @author Hans Bergsten [hans@gefionsoftware.com]
    */
   public class Request {
  +    /** Magic attribute that allows access to the real request from
  +     *  facade - for trusted applications
  +     */
  +    public static final String ATTRIB_REAL_REQUEST="org.apache.tomcat.request";
   
       protected int serverPort;
       protected String remoteAddr;
  @@ -408,28 +412,40 @@
       }
   
       public String getServletPath() {
  +	// contextM.log( "GetServletPath " + servletPath );
           return servletPath;
       }
   
  +    public void setServletPath(String servletPath) {
  +	//	contextM.log( "SetServletPath " + servletPath );
  +	this.servletPath = servletPath;
  +    }
  +
  +
  +
       // End hints
   
       // -------------------- Request methods ( high level )
       public Object getFacade() {
   	// some requests are internal, and will never need a
   	// facade - no need to create a new object unless needed.
  -        if( requestFacade==null ) {
  -	    if( context==null ) {
  -		// wrong request
  -		// XXX the will go away after we remove the one-one relation between
  -		// request and facades ( security, etc)
  -		requestFacade = contextM.getContext("" ).getFacadeManager().createHttpServletRequestFacade(this );
  -		return requestFacade;
  -	    }
  -	    requestFacade = context.getFacadeManager().createHttpServletRequestFacade(this);
  -	}
  +//         if( requestFacade==null ) {
  +// 	    if( context==null ) {
  +// 		// wrong request
  +// 		// XXX the will go away after we remove the one-one relation between
  +// 		// request and facades ( security, etc)
  +// 		requestFacade = contextM.getContext("" ).getFacadeManager().createHttpServletRequestFacade(this );
  +// 		return requestFacade;
  +// 	    }
  +// 	    requestFacade = context.getFacadeManager().createHttpServletRequestFacade(this);
  +// 	}
   	return requestFacade;
       }
   
  +    public void setFacade(Object facade ) {
  +	requestFacade=facade;
  +    }
  +
       public void setResponse(Response response) {
   	this.response = response;
       }
  @@ -615,30 +631,33 @@
   	this.queryString = queryString;
       }
   
  -    public void setServletPath(String servletPath) {
  -	this.servletPath = servletPath;
  -    }
  -
   
       // XXX
       // the server name should be pulled from a server object of some
       // sort, not just set and got.
   
       // -------------------- Attributes
  +    
       public Object getAttribute(String name) {
           Object value=attributes.get(name);
   	if( value != null )
   	    return value;
   
  -	// allow access to FacadeManager for servlets
  -	// ( this way you don't need to deal with init ).
  -	if( name.equals(FacadeManager.FACADE_ATTRIBUTE)) {
  -	    return context.getAttribute( name );
  +	// 	// allow access to FacadeManager for servlets
  +	// 	// ( this way you don't need to deal with init ).
  +	// 	if( name.equals(FacadeManager.FACADE_ATTRIBUTE)) {
  +	// 	    return context.getAttribute( name );
  +	// 	}
  +	if(name.equals(ATTRIB_REAL_REQUEST)) {
  +	    if( ! context.allowAttribute(name) ) return null;
  +	    return this;
   	}
  +
   	return null;
       }
   
       public void setAttribute(String name, Object value) {
  +	//	contextM.log( "setAttribure " + name +  " " + value );
   	if(name!=null && value!=null)
   	    attributes.put(name, value);
       }
  @@ -719,7 +738,7 @@
       // -------------------- End utils
       public void recycle() {
           if( requestFacade != null && context!=null ) {
  -            context.getFacadeManager().recycle(this);
  +	    //            context.getFacadeManager().recycle(this);
           }
   
           context = null;
  
  
  
  1.37      +12 -8     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.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- Response.java	2000/09/24 18:02:05	1.36
  +++ Response.java	2000/09/28 03:25:46	1.37
  @@ -126,15 +126,19 @@
       }
       
       public Object getFacade() {
  -        if( responseFacade==null ) {
  -	    Context ctx= request.getContext();
  -	    if( ctx == null ) {
  -		ctx=request.getContextManager().getContext("");
  -	    }
  -	    responseFacade = ctx.getFacadeManager().
  -		createHttpServletResponseFacade(this);
  -	}
  +//         if( responseFacade==null ) {
  +// 	    Context ctx= request.getContext();
  +// 	    if( ctx == null ) {
  +// 		ctx=request.getContextManager().getContext("");
  +// 	    }
  +// 	    responseFacade = ctx.getFacadeManager().
  +// 		createHttpServletResponseFacade(this);
  +// 	}
   	return responseFacade;
  +    }
  +
  +    public void setFacade(Object facade ) {
  +	responseFacade=facade;
       }
   
       public void setRequest(Request request) {
  
  
  
  1.12      +10 -7     jakarta-tomcat/src/share/org/apache/tomcat/request/InvokerInterceptor.java
  
  Index: InvokerInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/InvokerInterceptor.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- InvokerInterceptor.java	2000/09/26 04:58:27	1.11
  +++ InvokerInterceptor.java	2000/09/28 03:25:47	1.12
  @@ -84,7 +84,7 @@
   	Container ct=req.getContainer();
   
   	// 	log( "Ct: " + ct.getHandler() + " " +
  -// 	     ct.getPath() + " " + ct.getMapType());
  +	// 	     ct.getPath() + " " + ct.getMapType());
   	
   	if(  req.getWrapper()!=null &&
   	     ct!=null &&
  @@ -145,15 +145,18 @@
   	// it's a much cleaner way to construct the servlet and
   	// make sure all interceptors are up to date.
   	try {
  -	    Handler sw=ctx.createHandler();
  -	    sw.setContext(ctx);
  -	    sw.setServletName(servletName);
  +	    ctx.addServletMapping( newServletPath + "/*" ,
  +				   servletName );
  +	    // The facade should create the servlet name
  +	    
  +	    Handler sw=ctx.getServletByName( servletName );
  +	    // 	    sw.setContext(ctx);
  +	    // 	    sw.setServletName(servletName);
  +	    //	    ctx.addServlet( sw );
   	    sw.setServletClass( servletName );
   	    sw.setOrigin( Handler.ORIGIN_INVOKER );
   	    wrapper=sw;
  -	    ctx.addServlet( sw );
  -	    ctx.addServletMapping( newServletPath + "/*" ,
  -				   servletName );
  +
   	    if( debug > 0)
   		log( "Added mapping " + wrapper +
   		     " path=" + newServletPath + "/*" );
  
  
  
  1.25      +36 -16    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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- EmbededTomcat.java	2000/09/26 05:17:10	1.24
  +++ EmbededTomcat.java	2000/09/28 03:25:48	1.25
  @@ -43,7 +43,7 @@
   	servlet API version. This will change after we
   	finish the FacadeManager implementation
       */
  -    FacadeManager facadeM=null;
  +    //    FacadeManager facadeM=null;
       Vector connectors=new Vector();
   
       String workDir;
  @@ -160,8 +160,9 @@
   	    // XXX if virtual host set it.
   	    ctx.setDocBase( docRoot.getFile());
   	    contextM.addContext( ctx );
  -	    if( facadeM == null ) facadeM=ctx.getFacadeManager();
  -	    return ctx.getFacade();
  +	    // 	    if( facadeM == null ) facadeM=ctx.getFacadeManager();
  +	    // 	    return ctx.getFacade();
  +	    return ctx;
   	} catch( Exception ex ) {
   	    log("exception adding context " + ctxPath + "/" + docRoot, ex);
   	}
  @@ -173,11 +174,13 @@
       public void removeContext( Object sctx ) {
   	if(debug>0) log( "remove context " + sctx );
   	try {
  -	    if( facadeM==null ) {
  -		log("ERROR removing context " + sctx + ": no facade manager", Logger.ERROR);
  -		return;
  -	    }
  -	    Context ctx=facadeM.getRealContext( sctx );
  +// 	    if( facadeM==null ) {
  +// 		log("ERROR removing context " +
  +// 		    sctx + ": no facade manager", Logger.ERROR);
  +// 		return;
  +// 	    }
  +	    //	    Context ctx=contextM.getRealContext( sctx );
  +	    Context ctx=(Context)sctx;
   	    contextM.removeContext( ctx );
   	} catch( Exception ex ) {
   	    log("exception removing context " + sctx, ex);
  @@ -201,7 +204,8 @@
   	    }
   	    cp.addElement( cpath );
   	} catch( Exception ex ) {
  -	    log("exception adding classpath " + cpath + " to context " + context, ex);
  +	    log("exception adding classpath " + cpath +
  +		" to context " + context, ex);
   	}
   	
   	// XXX This functionality can be achieved by setting it in the parent
  @@ -228,11 +232,12 @@
        */
       public void initContext( Object sctx ) {
   	try {
  -	    if( facadeM==null ) {
  -		log("XXX ERROR: no facade manager");
  -		return;
  -	    }
  -	    Context ctx=facadeM.getRealContext( sctx );
  +// 	    if( facadeM==null ) {
  +// 		log("XXX ERROR: no facade manager");
  +// 		return;
  +// 	    }
  +	    Context ctx=(Context)sctx;
  +	    //contextM.getRealContext( sctx );
   	    contextM.initContext( ctx );
   
   	    Object pd=ctx.getProtectionDomain();
  @@ -329,8 +334,13 @@
   	// no AutoSetup !
   	
   	// set workdir, engine header, auth Servlet, error servlet, loader
  -	WebXmlReader webXmlI=new WebXmlReader();
  -	webXmlI.setValidate( false );
  +
  +	// XXX So far Embeded tomcat is specific to Servlet 2.2.
  +	// It need a major refactoring to support multiple
  +	// interfaces ( I'm not sure it'll be possible to support
  +	// multiple APIs at the same time in embeded mode )
  +	
  +	BaseInterceptor webXmlI= (BaseInterceptor)newObject("org.apache.tomcat.facade.WebXmlReader");
   	addContextInterceptor( webXmlI );
   
   	PolicyInterceptor polI=new PolicyInterceptor();
  @@ -424,6 +434,16 @@
   	    // this stack trace is ok, i guess, since it's just a
   	    // sample main
   	    t.printStackTrace();
  +	}
  +    }
  +
  +    private Object newObject( String classN ) {
  +	try {
  +	    Class c=Class.forName( classN );
  +	    return c.newInstance();
  +	} catch( Exception ex ) {
  +	    ex.printStackTrace();
  +	    return null;
   	}
       }
   	
  
  
  

Mime
View raw message