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/request SimpleMapper.java
Date Wed, 16 Feb 2000 05:44:36 GMT
costin      00/02/15 21:44:35

  Modified:    src/etc  server.xml
               src/j2ee/org/apache/tomcat/deployment
                        WebApplicationReader.java
               src/share/org/apache/tomcat/context WebXmlReader.java
               src/share/org/apache/tomcat/core BaseInterceptor.java
                        Container.java Context.java ContextInterceptor.java
                        ContextManager.java ServletWrapper.java
               src/share/org/apache/tomcat/request SimpleMapper.java
  Log:
  Changed ContextInterceptor and mapper to use a simpler and more extensible
  model.
  
  A Container represents the common properties of a set of URL paths, and we use
  this representation for both servlet-mappings ( urlPath -> handler) and
  for security properties. The model is extensible - it is possible to add
  more complex patterns ( including matching virtual hosts, source IPs, etc),
  and it is possible to fine tune the whole server.
  
  This is also similar with Catalina - and will help us share more code.
  
  Also, removed some methods from Interceptor - it's better to have a smaller set
  and add later if we need to.
  
  Revision  Changes    Path
  1.8       +6 -2      jakarta-tomcat/src/etc/server.xml
  
  Index: server.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/etc/server.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- server.xml	2000/02/14 04:59:37	1.7
  +++ server.xml	2000/02/16 05:44:31	1.8
  @@ -40,6 +40,7 @@
           <!-- Request processing -->
           <RequestInterceptor className="org.apache.tomcat.request.SimpleMapper" />
           <RequestInterceptor className="org.apache.tomcat.request.SessionInterceptor"
/>
  +        <RequestInterceptor className="org.apache.tomcat.request.SecurityCheck" />
           <RequestInterceptor className="org.apache.tomcat.request.FixHeaders" />
   
           <Connector className="org.apache.tomcat.service.http.HttpAdapter">
  @@ -52,10 +53,13 @@
           </Connector>
   
           <!-- example - how to override AutoSetup actions -->
  -        <Context path="/examples" docBase="webapps/examples" debug="1" reloadable="true"
> 
  +        <Context path="/examples" docBase="webapps/examples" debug="0" reloadable="true"
> 
           </Context>
           <!-- example - how to override AutoSetup actions -->
  -        <Context path="" docBase="webapps/ROOT" debug="1" reloadable="true" > 
  +        <Context path="" docBase="webapps/ROOT" debug="0" reloadable="true" > 
  +        </Context>
  +
  +        <Context path="/test" docBase="webapps/test" debug="9" reloadable="true" >

           </Context>
   
       </ContextManager>
  
  
  
  1.4       +0 -8      jakarta-tomcat/src/j2ee/org/apache/tomcat/deployment/WebApplicationReader.java
  
  Index: WebApplicationReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/j2ee/org/apache/tomcat/deployment/WebApplicationReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WebApplicationReader.java	2000/02/13 01:43:40	1.3
  +++ WebApplicationReader.java	2000/02/16 05:44:32	1.4
  @@ -868,14 +868,6 @@
   
   		if (! containsServlet(ctx, mapping) &&
   		    ! containsJSP(ctx, mapping)) {
  -		    if (ctx.getServletMapping(mapping)!=null) {
  -// 		        String msg = sm.getString("context.dd.dropMapping",
  -// 			    mapping);
  -
  -// 			System.out.println(msg);
  -
  -			ctx.removeMapping(mapping);
  -		    }
   
                       ctx.addServletMapping( mapping, name);
   		} else {
  
  
  
  1.10      +4 -4      jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java
  
  Index: WebXmlReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- WebXmlReader.java	2000/02/15 17:35:37	1.9
  +++ WebXmlReader.java	2000/02/16 05:44:33	1.10
  @@ -26,7 +26,7 @@
       }
   
       public void contextInit(Context ctx) {
  -	//	System.out.println("Context(" + ctx.getPath() + "): " + ctx.getDocBase());
  +	if( ctx.getDebug() > 0 ) ctx.log("XmlReader - init  " + ctx.getPath() + " " + ctx.getDocBase()
);
   
   	// read default web.xml
   	try {
  @@ -42,10 +42,10 @@
   
       void processFile( Context ctx, String file) {
   	try {
  -	    File f=new File(file);
  -
  +	    File f=new File(file);	
  +	    if( ctx.getDebug() > 0 ) ctx.log("Reading " + file );
   	    XmlMapper xh=new XmlMapper();
  -	    xh.setDebug( 0 );
  +	    if( ctx.getDebug() > 5 ) xh.setDebug( 2 );
   
   	    xh.addRule("web-app/context-param", xh.methodSetter("addInitParameter", 2) );
   	    xh.addRule("web-app/context-param/param-name", xh.methodParam(0) ); 
  
  
  
  1.6       +2 -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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BaseInterceptor.java	2000/02/16 00:30:29	1.5
  +++ BaseInterceptor.java	2000/02/16 05:44:33	1.6
  @@ -129,22 +129,10 @@
   
       public void contextShutdown(Context ctx) throws TomcatException {
       }
  -
  -    /** Notify when a new servlet is added
  -     */
  -    public void addServlet( Context ctx, ServletWrapper sw) throws TomcatException {
  -    }
  -    
  -    /** Notify when a servlet is removed from context
  -     */
  -    public void removeServlet( Context ctx, ServletWrapper sw) throws TomcatException {
  +    public void addContainer(Container container) throws TomcatException {
       }
  -
  -    public void addMapping( Context ctx, String path, ServletWrapper servlet) throws TomcatException
{
  -    }
  -
   
  -    public void removeMapping( Context ctx, String path ) throws TomcatException {
  +    public void removeContainer(Container container) throws TomcatException {
       }
   
       /** 
  
  
  
  1.11      +26 -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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Container.java	2000/02/15 17:35:37	1.10
  +++ Container.java	2000/02/16 05:44:33	1.11
  @@ -97,6 +97,10 @@
       // The context including this container, if any
       Context context;
   
  +    // Location where this container is mapped
  +    String path;
  +    String proto;
  +    
       // Container attributes
       private Hashtable attributes = new Hashtable();
   
  @@ -117,9 +121,16 @@
       }
   	
       public ContextManager getContextManager() {
  +	if( contextM==null ) {
  +	    if(context!=null) contextM=context.getContextManager();
  +	}
   	return contextM;
       }
   
  +    public void setContextManager(ContextManager cm) {
  +	contextM=cm;
  +    }
  +    
       public void setContext( Context ctx ) {
   	this.context=ctx;
       }
  @@ -128,11 +139,23 @@
   	return context;
       }
       
  -    public void setContextManager(ContextManager cm) {
  -	contextM=cm;
  +
  +    public void setPath( String path ) {
  +	this.path=path;
       }
  -    
   
  +    public String getPath() {
  +	return path;
  +    }
  +
  +    public void setProtocol( String protocol ) {
  +	this.proto=protocol;
  +    }
  +
  +    public String getProtocol() {
  +	return proto;
  +    }
  +    
       public void addContextInterceptor( ContextInterceptor ci) {
   	contextInterceptors.addElement( ci );
       }
  
  
  
  1.55      +37 -44    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.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Context.java	2000/02/15 17:35:37	1.54
  +++ Context.java	2000/02/16 05:44:33	1.55
  @@ -126,6 +126,9 @@
       // Maps specified in web.xml ( String url -> ServletWrapper  )
       private Hashtable mappings = new Hashtable();
       Hashtable constraints=new Hashtable();
  +    
  +    Hashtable containers=new Hashtable();
  +    
       private ServletWrapper defaultServlet = null;
       
       // Authentication properties
  @@ -409,8 +412,13 @@
       public void addServletMapping(String path, String servletName)
   	throws TomcatException
       {
  +	if( mappings.get( path )!= null) {
  +	    log( "Removing duplicate " + path + " -> " + mappings.get(path) );
  +	    mappings.remove( path );
  +	    Container ct=(Container)containers.get( path );
  +	    removeContainer( ct );
  +	}
           ServletWrapper sw = (ServletWrapper)servlets.get(servletName);
  -
   	if (sw == null) {
   	    //	    System.out.println("Servlet not registered " + servletName );
   	    // Workaround for frequent "bug" in web.xmls
  @@ -433,36 +441,15 @@
   	    defaultServlet = sw;
   
   	mappings.put( path, sw );
  -	contextM.addMapping( this, path, sw );
  -    }
  -
  -    public Enumeration getServletMappings() {
  -	return mappings.keys();
  -    }
  -
  -    public ServletWrapper getServletMapping( String mapping ) {
  -        mapping = mapping.trim();
  -	return (ServletWrapper)mappings.get(mapping);
  -    }
  -
  -    public void removeMapping( String path ) {
  -	log( "Removing " + path + " -> " + mappings.get(path) );
  -	mappings.remove( path );
  -    }
  -    
  -    public void removeMappingsFor( ServletWrapper sw ) {
  -	Enumeration enum = mappings.keys();
   	
  -	while (enum.hasMoreElements()) {
  -	    String key = (String)enum.nextElement();
  -
  -	    if (mappings.get(key).equals(sw)) {
  -		log( "Removing " + key + " -> " + sw );
  -		mappings.remove(key);
  -	    }
  -	}
  +	Container map=new Container();
  +	map.setContext( this );
  +	map.setHandler( sw );
  +	map.setPath( path );
  +	contextM.addContainer( map );
  +	containers.put( path, map );
       }
  -    
  +
       public void addSecurityConstraint( String path[], String methods[],
   				       String roles[], String transport)
   	throws TomcatException
  @@ -472,42 +459,46 @@
   	    ct.setContext( this );
   	    ct.setTransport( transport );
   	    ct.setRoles( roles );
  +	    ct.setPath( path[i] );
   	    
   	    // XXX check if exists, merge if true.
   	    constraints.put( path[i], ct );
  -	    contextM.addSecurityConstraint( this, path[i], ct);
  +	    //contextM.addSecurityConstraint( this, path[i], ct);
  +	    contextM.addContainer(  ct );
   	}
       }
   
  -    public Enumeration getSecurityConstraints() {
  -	return constraints.keys();
  +    public Enumeration getContainers() {
  +	return containers.elements();
       }
  -
  -    public Container getSecurityConstraint( String path ) {
  -	return (Container)constraints.get(path);
  +    
  +    public Enumeration getContainerLocations() {
  +	return containers.keys();
       }
   
  +    public Container getContainer( String path ) {
  +	return (Container)containers.get(path);
  +    }
  +    
  +    public void removeContainer( Container ct ) {
  +	containers.remove(ct.getPath());
  +    }
  +    
       public ServletWrapper getDefaultServlet() {
   	if( defaultServlet==null)
   	    defaultServlet=getServletByName(Constants.DEFAULT_SERVLET_NAME );
  -	// XXX works only if we do load default web.xml first - we should
  -	// be able to work without that trick ( i.e. define a "default" )
  -	
   	return defaultServlet;
       }
   
       // -------------------- Servlets management --------------------
  -    
  +
  +    // XXX do we need that ?? 
       /** Remove the servlet with a specific name
        */
       public void removeServletByName(String servletName)
   	throws TomcatException
       {
  -	ServletWrapper wrapper=(ServletWrapper)servlets.get(servletName);
  -	if( wrapper != null ) {
  -	    servlets.remove( servletName );
  -	    contextM.removeServlet( this, wrapper );
  -	}
  +	servlets.remove( servletName );
       }
   
       public ServletWrapper getServletByName(String servletName) {
  @@ -531,6 +522,7 @@
           if (servlets.get(name) != null) {
   	    log("Removing duplicate servlet " + name  + " " + wrapper);
               removeServletByName(name);
  +	    //	    getServletByName(name).destroy();
           }
   	servlets.put(name, wrapper);
       }
  @@ -559,6 +551,7 @@
   
       /* -------------------- Utils  -------------------- */
       public void setDebug( int level ) {
  +	if(level>0) log( "Set debug to " + level );
   	debug=level;
       }
   
  
  
  
  1.9       +51 -33    jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java
  
  Index: ContextInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ContextInterceptor.java	2000/02/15 17:35:37	1.8
  +++ ContextInterceptor.java	2000/02/16 05:44:34	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v
1.8 2000/02/15 17:35:37 costin Exp $
  - * $Revision: 1.8 $
  - * $Date: 2000/02/15 17:35:37 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v
1.9 2000/02/16 05:44:34 costin Exp $
  + * $Revision: 1.9 $
  + * $Date: 2000/02/16 05:44:34 $
    *
    * ====================================================================
    *
  @@ -75,63 +75,80 @@
    */
   public interface ContextInterceptor {
   
  -    /** Called when the ContextManger is started
  +    /** Called when the ContextManger is started. 
        */
       public void engineInit(ContextManager cm) throws TomcatException;
       
  +
       /** Called before the ContextManager is stoped.
        *  You need to stop any threads and remove any resources.
        */
       public void engineShutdown(ContextManager cm) throws TomcatException;
   
  -    /** Called when a context is added to a CM
  +    
  +    /** Called when a context is added to a CM. The context is probably not
  +     *  initialized yet, only path and docRoot are probably set.
  +     *
  +     *  If you need informations that are available in web.xml use contextInit()
  +     *  ( a WebXmlReader needs to be the first interceptor in the contextInit chain ).
  +     * 
  +     *  We do that to support ( eventualy ) a "lazy" init, where you have many contexts,
  +     *  most of them not in active use, and you'll init them at first request. ( for
  +     *  example an ISP with many users )
  +     *
        */
       public void addContext( ContextManager cm, Context ctx ) throws TomcatException;
   
  -    /** Called when a context is removed from a CM
  -     */
  -    public void removeContext( ContextManager cm, Context ctx ) throws TomcatException;
   
  -    /** Notification when a context is initialized
  +    /** Notify when a context is initialized.
  +     *  The first interceptor in the chain for contextInit must read web.xml and set
  +     *  the context. When this method is called you can expect the context to be filled
  +     *  in with all the informations from web.xml.
        */
       public void contextInit(Context ctx) throws TomcatException;
   
  -    /** Called when a context is stoped.
  +
  +    /** Called when a context is stoped, before removeContext. You must free all resources.
  +     * XXX  - do we need this or removeContext is enough ?? ( will be removed from 3.1
if
  +     * nobody asks for it)
        */
       public void contextShutdown(Context ctx) throws TomcatException;
       
  -    /** Notify when a new servlet is added
  -     */
  -    public void addServlet( Context ctx, ServletWrapper sw) throws TomcatException;
   
  -    /** Notify when a servlet is removed from context
  +    /** Called when a context is removed from a CM. A context is removed either as
  +     *  a result of admin ( remove or update), to support "clean" servlet reloading
  +     *  or at shutdown.
        */
  -    public void removeServlet( Context ctx, ServletWrapper sw) throws TomcatException;
  -
  -    /** Notify when a mapping is added to a context
  -     */
  -    public void addMapping( Context ctx, String path, ServletWrapper servlet) throws TomcatException;
  +    public void removeContext( ContextManager cm, Context ctx ) throws TomcatException;
   
  -    /** Notify when a mapping is deleted  from  a context
  -     */
  -    public void removeMapping( Context ctx, String path ) throws TomcatException;
   
  -    
  -    /** Add a security restriction.
  +    /** 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.
        *
  -     *  We treat the security-constraint as in Apache and most web servers,
  -     *  and reverse from web.xml - instead of defining a set of roles and the
  -     *  patterns that will be constrainted, we associate some constraints with
  -     *  url patterns. ( i.e. path->constraint instead of constraint -> path-set )
  +     *  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.
        *
  -     *  XXX We should unify method + path
  -     *  here and path in addMapping into UrlMatch and transport, roles and wrapper
  -     *  under UrlAction ( or something like that ).
  +     *  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.
  +     * 
  +     *  XXX  define "merging" of containers 
        */
  -    public void addSecurityConstraint( Context ctx, String path, Container dirConf ) throws
TomcatException;
  +    public void addContainer( Container container ) throws TomcatException;
   
  +    /** A rule was removed, update the internal strucures. You can also clean up
  +     * and reload everything using Context.getContainers()
  +     */
  +    public void removeContainer( Container container ) throws TomcatException;
   
  -    /** Servlet Init  notification
  +    
  +    /** Servlet Init notification.
  +     *  XXX do we need "pre/post" for init/destroy ? transactions? 
        */
       public void preServletInit( Context ctx, ServletWrapper sw ) throws TomcatException;
       
  @@ -143,4 +160,5 @@
       public void preServletDestroy( Context ctx, ServletWrapper sw ) throws TomcatException;
       
       public void postServletDestroy( Context ctx, ServletWrapper sw ) throws TomcatException;
  +
   }
  
  
  
  1.45      +4 -34     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.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- ContextManager.java	2000/02/16 02:41:13	1.44
  +++ ContextManager.java	2000/02/16 05:44:34	1.45
  @@ -310,53 +310,23 @@
   	}
       }
   
  -    public void removeServlet( Context ctx, ServletWrapper sw )
  -	throws TomcatException
  -    {
  -	if( sw==null) return;
  -	ContextInterceptor cI[]=getContextInterceptors();
  -	for( int i=0; i< cI.length; i++ ) {
  -	    cI[i].removeServlet( ctx, sw );
  -	}
  -
  -    }
  -
  -    public void addServlet( Context ctx, ServletWrapper sw )
  -	throws TomcatException
  -    {
  -	ContextInterceptor cI[]=getContextInterceptors();
  -	for( int i=0; i< cI.length; i++ ) {
  -	    cI[i].addServlet( ctx, sw );
  -	}
  -    }
  -
  -    public void addMapping( Context ctx ,String path, ServletWrapper sw )
  +    public void addContainer( Container container )
       	throws TomcatException
       {
   	ContextInterceptor cI[]=getContextInterceptors();
   	for( int i=0; i< cI.length; i++ ) {
  -	    cI[i].addMapping( ctx, path, sw );
  +	    cI[i].addContainer( container);
   	}
       }
   
  -    public void removeMapping( Context ctx, String path )
  -    	throws TomcatException
  -    {
  -	ContextInterceptor cI[]=getContextInterceptors();
  -	for( int i=0; i< cI.length; i++ ) {
  -	    cI[i].removeMapping( ctx, path );
  -	}
  -    }
  -
  -    public void addSecurityConstraint( Context ctx, String path, Container ct )
  +    public void removeContainer( Container container )
   	throws TomcatException
       {
   	ContextInterceptor cI[]=getContextInterceptors();
   	for( int i=0; i< cI.length; i++ ) {
  -	    cI[i].addSecurityConstraint( ctx, path, ct );
  +	    cI[i].removeContainer( container);
   	}
       }
  -
   
       // -------------------- Connectors and Interceptors --------------------
   
  
  
  
  1.27      +5 -5      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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- ServletWrapper.java	2000/02/15 17:35:38	1.26
  +++ ServletWrapper.java	2000/02/16 05:44:34	1.27
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
1.26 2000/02/15 17:35:38 costin Exp $
  - * $Revision: 1.26 $
  - * $Date: 2000/02/15 17:35:38 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
1.27 2000/02/16 05:44:34 costin Exp $
  + * $Revision: 1.27 $
  + * $Date: 2000/02/16 05:44:34 $
    *
    * ====================================================================
    *
  @@ -393,9 +393,9 @@
               // the full exception object.  Oh well.
   
               request.setAttribute(Constants.ATTRIBUTE_ERROR_EXCEPTION_TYPE,
  -	        t.getClass().getName());
  +				 t.getClass().getName());
               request.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,
  -                t.getMessage());
  +				 t.getMessage());
   
               try {
   		// A forward would be ideal, so reset and try it
  
  
  
  1.11      +26 -109   jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java
  
  Index: SimpleMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SimpleMapper.java	2000/02/15 17:35:40	1.10
  +++ SimpleMapper.java	2000/02/16 05:44:35	1.11
  @@ -242,48 +242,6 @@
   
       */
   
  -
  -    /** Called when a context is added to a CM
  -     */
  -    public void addContext( ContextManager cm, Context ctx )
  -	throws TomcatException
  -    {
  -	Mappings m=new Mappings();
  -	m.ctx=ctx;
  -	m.prefixMappedServlets=new Hashtable();
  -	m.extensionMappedServlets=new Hashtable();
  -	m.pathMappedServlets=new Hashtable();
  -	contextPaths.put( ctx.getPath(), m );
  -
  -	if(debug>0) ctx.log("New context added to maps. ");
  -	// add all existing mappings
  -	Enumeration enum=ctx.getServletMappings();
  -	while( enum.hasMoreElements() ) {
  -	    String path=(String) enum.nextElement();
  -	    ServletWrapper sw=ctx.getServletMapping( path );
  -	    Container ct=new Container();
  -	    ct.setContext( ctx );
  -	    ct.setHandler( sw );
  -	    if(debug>0) ctx.log("Adding existing " + path );
  -	    addMapping( contextPaths, ctx, path, ct );
  -	}
  -	// set default container
  -	Container def=new Container();
  -	def.setContext( ctx );
  -	ServletWrapper wrapper = ctx.getDefaultServlet();
  -	def.setHandler( wrapper );
  -	m.defaultContainer=def;
  -	
  -	enum=ctx.getSecurityConstraints();
  -	while( enum.hasMoreElements() ) {
  -	    String path=(String) enum.nextElement();
  -	    Container ct=ctx.getSecurityConstraint( path );
  -	    if(debug>0) ctx.log("Adding existing " + path );
  -	    addMapping( securityConstraints, ctx, path, ct );
  -	}
  -
  -    }
  -
       /** Called when a context is removed from a CM
        */
       public void removeContext( ContextManager cm, Context ctx ) throws TomcatException
  @@ -298,18 +256,6 @@
       }
   
   
  -    /** Notification - new handler mapping
  -     */
  -    public void addMapping( Context ctx, String path, ServletWrapper sw)
  -	throws TomcatException
  -    {
  -	Container ct=new Container();
  -	ct.setContext( ctx );
  -	ct.setHandler( sw );
  -	if(debug>0) ctx.log("Adding existing " + path );
  -	addMapping( contextPaths, ctx, path, ct );
  -    }
  -
       /**
        * Associate URL pattern  to a set of propreties.
        * 
  @@ -321,10 +267,20 @@
        *    default servlet
        *
        */
  -    void addMapping( Hashtable mtable, Context ctx, String path, Container ct)
  +    public void addContainer( Container ct )
   	throws TomcatException
       {
  +	Context ctx=ct.getContext();
  +	String path=ct.getPath();
   	String ctxP=ctx.getPath();
  +
  +	// add the mapping in the "securityContraints"
  +	// or in contextPaths if it's a servlet mapping
  +	Hashtable mtable=securityConstraints;
  +	if( ct.getHandler() != null )
  +	    mtable=contextPaths;
  +	//	System.out.println("XXX " + path + " " + ctx.getDebug() + " " + ctxP + " " + ct.getHandler()
+ " " + ct.getRoles());
  +	
   	Mappings m=(Mappings)mtable.get(ctxP);
   	if( m==null ) {
   	    m=new Mappings();
  @@ -333,6 +289,11 @@
   	    m.extensionMappedServlets=new Hashtable();
   	    m.pathMappedServlets=new Hashtable();
   	    mtable.put( ctxP, m );
  +	    Container def=new Container();
  +	    def.setContext( ctx );
  +	    ServletWrapper wrapper = ctx.getDefaultServlet();
  +	    def.setHandler( wrapper );
  +	    m.defaultContainer=def;
   	}
   	if(debug>0) ctx.log( "Add mapping " + path + " " + ct + " " + m );
   	
  @@ -351,69 +312,25 @@
   	} 
       }
   
  -    /** Notify when a mapping is deleted  from  a context
  -     */
  -    public void removeMapping( Context ctx, String mapping )
  +    public void removeContainer( Container ct )
   	throws TomcatException
       {
  +	Context ctx=ct.getContext();
  +	String mapping=ct.getPath();
   	String ctxP=ctx.getPath();
  -	Mappings m=(Mappings)contextPaths.get(ctxP);
  -	
  -	if(debug>0) ctx.log( "Remove mapping " + mapping );
  -	
           mapping = mapping.trim();
  -	
  +	if(debug>0) ctx.log( "Remove mapping " + mapping );
  +
  +	Mappings m=(Mappings)contextPaths.get(ctxP);
   	m.prefixMappedServlets.remove(mapping);
   	m.extensionMappedServlets.remove(mapping);
   	m.pathMappedServlets.remove(mapping);
  -    }
  -
  -    
  -    public void removeServlet(Context ctx, ServletWrapper sw) {
  -
  -	// find the mappings for ctx
  -	if( debug > 0 ) ctx.log( "Remove servlet " + sw );
  -	String path=ctx.getPath();
  -	Mappings m=(Mappings)contextPaths.get(path);
  -	
  -	Enumeration enum = m.prefixMappedServlets.keys();
  -	    
  -	while (enum.hasMoreElements()) {
  -	    String key = (String)enum.nextElement();
  -	    
  -	    if (((Container)m.prefixMappedServlets.get(key)).getHandler().equals(sw)) {
  -		m.prefixMappedServlets.remove(key);
  -	    }
  -	}
  -	
  -	enum = m.extensionMappedServlets.keys();
  -	    
  -	while (enum.hasMoreElements()) {
  -	    String key = (String)enum.nextElement();
  -	    
  -	    if (((Container)m.extensionMappedServlets.get(key)).getHandler().equals(sw)) {
  -		m.extensionMappedServlets.remove(key);
  -		}
  -	}
   
  -	enum = m.pathMappedServlets.keys();
  -	    
  -	while (enum.hasMoreElements()) {
  -	    String key = (String)enum.nextElement();
  -	    
  -	    if (((Container)m.pathMappedServlets.get(key)).getHandler().equals(sw)) {
  -		m.pathMappedServlets.remove(key);
  -	    }
  -	}
  -    }
  -    
  -    public void addSecurityConstraint( Context ctx, String path, Container ct)
  -	throws TomcatException
  -    {
  -	if(debug>0) ctx.log( "Add SC " + path + " " + ct );
  -	addMapping( securityConstraints, ctx, path, ct );
  +	m=(Mappings)securityConstraints.get(ctxP);
  +	m.prefixMappedServlets.remove(mapping);
  +	m.extensionMappedServlets.remove(mapping);
  +	m.pathMappedServlets.remove(mapping);
       }
  -
   
       // -------------------- Implementation --------------------
       /** Get an exact match ( /catalog ) - rule 1 in 10.1
  
  
  

Mime
View raw message