You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2006/06/20 23:45:28 UTC

svn commit: r415818 [1/3] - in /tomcat/sandbox: java/org/apache/coyote/servlet/ java/org/apache/coyote/servlet/mapper/ java/org/apache/coyote/servlet/servlets/ java/org/apache/coyote/servlet/util/ java/org/apache/coyote/servlet/webxml/ java/org/apache/...

Author: costin
Date: Tue Jun 20 14:45:26 2006
New Revision: 415818

URL: http://svn.apache.org/viewvc?rev=415818&view=rev
Log:
More code to support minimal tomcat ( refactored from tomcat6 classes, with many
features removed - sandbox and jndi removed, valves replaced with plain filters, etc)

Added:
    tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteAdapter.java
      - copied, changed from r410655, tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java
    tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteMain.java
      - copied, changed from r410655, tomcat/sandbox/java/org/apache/coyote/servlet/Main.java
    tomcat/sandbox/java/org/apache/coyote/servlet/WebappContextMapper.java
    tomcat/sandbox/java/org/apache/coyote/servlet/WebappFilterMapper.java
      - copied, changed from r410655, tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationFilterFactory.java
    tomcat/sandbox/java/org/apache/coyote/servlet/WebappHasRole.java
      - copied, changed from r410655, tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationAuthorization.java
    tomcat/sandbox/java/org/apache/coyote/servlet/WebappServletMapper.java
    tomcat/sandbox/java/org/apache/coyote/servlet/WebappSessionManager.java
      - copied, changed from r410655, tomcat/sandbox/java/org/apache/coyote/servlet/SessionManager.java
    tomcat/sandbox/java/org/apache/coyote/servlet/mapper/
    tomcat/sandbox/java/org/apache/coyote/servlet/servlets/
    tomcat/sandbox/java/org/apache/coyote/servlet/servlets/ReloadServlet.java
    tomcat/sandbox/java/org/apache/coyote/servlet/util/MappingData.java
    tomcat/sandbox/java/org/apache/coyote/servlet/webxml/
    tomcat/sandbox/java/org/apache/coyote/servlet/webxml/WebXml.java
    tomcat/sandbox/resources/coyote-servlet.MF   (with props)
Removed:
    tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationAuthorization.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationFilterFactory.java
    tomcat/sandbox/java/org/apache/coyote/servlet/FilterMap.java
    tomcat/sandbox/java/org/apache/coyote/servlet/Globals.java
    tomcat/sandbox/java/org/apache/coyote/servlet/Main.java
    tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java
    tomcat/sandbox/java/org/apache/coyote/servlet/SessionManager.java
    tomcat/sandbox/java/org/apache/tomcat/standalone/Main.java
    tomcat/sandbox/js-bin/
    tomcat/sandbox/resources/coyote-http11.MF
Modified:
    tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java
    tomcat/sandbox/java/org/apache/coyote/servlet/FilterChainImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/FilterConfigImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/Host.java
    tomcat/sandbox/java/org/apache/coyote/servlet/HttpSessionImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/RequestDispatcherImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletConfigImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestWrapperImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageWriter.java

Copied: tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteAdapter.java (from r410655, tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java)
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteAdapter.java?p2=tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteAdapter.java&p1=tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java&r1=410655&r2=415818&rev=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteAdapter.java Tue Jun 20 14:45:26 2006
@@ -8,28 +8,49 @@
 import org.apache.coyote.Adapter;
 import org.apache.coyote.Request;
 import org.apache.coyote.Response;
+import org.apache.coyote.servlet.util.MappingData;
 import org.apache.coyote.servlet.util.MessageWriter;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
-import org.apache.tomcat.util.http.mapper.Mapper;
-import org.apache.tomcat.util.http.mapper.MappingData;
 
-/** Main adapter - mapping.
- * TODO: filters
- * TODO: auth
+/** Main adapter - top mapping and adaptation.
+ * 
+ * This handles host and context mapping - the data structures are stored
+ * in this class. 
+ * 
+ * All context-specific mapping is done in the Mapper class, one per
+ * context. Mapper should also handle filters and authentication.
  */
-public class MapperAdapter implements Adapter {
-    private Mapper mapper=new Mapper();
+public class CoyoteAdapter implements Adapter {
+    WebappContextMapper hostMapper = new WebappContextMapper();
+    
     private static org.apache.commons.logging.Log log=
-        org.apache.commons.logging.LogFactory.getLog( MapperAdapter.class );
+        org.apache.commons.logging.LogFactory.getLog( CoyoteAdapter.class );
 
 
-    public MapperAdapter(Mapper mapper2) {
-        mapper = mapper2;
+    public CoyoteAdapter() {
     }
+    
+    public static int REQUEST_MAPPING_NOTE = 4;
 
+    /** Override the default host mapper.
+     *  This allow fine tunning for very large number of domains,
+     *  dynamic domain names, large/deep/atypical context names,
+     *  dynamic context names. 
+     * 
+     * @param hmapper
+     */
+    public void setHostMapper(WebappContextMapper hmapper) {
+        hostMapper = hmapper;
+    }
+    
+    public WebappContextMapper getHostMapper() {
+        return hostMapper;
+    }
+    
     public void service(Request req, final Response res)
             throws Exception {
+        MappingData mapRes = null;
         try {
             
             MessageBytes decodedURI = req.decodedURI();
@@ -59,22 +80,48 @@
                 decodedURI.toChars();
             }
 
+            ServletRequestImpl request = (ServletRequestImpl) req.getNote(ADAPTER_NOTES);
+            ServletResponseImpl response = (ServletResponseImpl) res.getNote(ADAPTER_NOTES);
 
+            if (request == null) {
+                // Create objects
+                request = new ServletRequestImpl();
+                request.setCoyoteRequest(req);
+                response = new ServletResponseImpl();
+                response.setRequest(request);
+                response.setCoyoteResponse(res);
+                // Link objects
+                request.setResponse(response);
+
+                // Set as notes
+                req.setNote(ADAPTER_NOTES, request);
+                res.setNote(ADAPTER_NOTES, response);
+            }
             
-            // TODO: per thread data - does it help ? 
-            
-            MappingData mapRes = new MappingData();
-            mapper.map(req.remoteHost(), req.decodedURI(), 
-                       mapRes);
+            mapRes = request.getMappingData(); 
+            if(mapRes == null ) {
+                mapRes = new MappingData();
+                req.setNote(REQUEST_MAPPING_NOTE, mapRes);
+            }
+            hostMapper.mapContext(req.remoteHost(), req.decodedURI(), mapRes);
+            ServletContextImpl ctx = (ServletContextImpl)mapRes.context;
+            if( ctx == null ) {
+                // TODO: 404
+                return;
+            }
+            WebappServletMapper mapper = ctx.getMapper();
+            mapper.map(req.decodedURI(), mapRes);
             
             ServletConfigImpl h=(ServletConfigImpl)mapRes.wrapper;
             if (h != null) {
-                serviceServlet( req, res, h );
+                serviceServlet( req, request, response, h, mapRes );
             }
-            
         } catch( Throwable t ) {
             t.printStackTrace(System.out);
-        } 
+        } finally {
+            if(mapRes != null ) 
+                mapRes.recycle();
+        }
 
         // Final processing
         MessageWriter.getWriter(req, res, 0).flush();
@@ -93,41 +140,18 @@
      *  This replaces the valve chain, the path is: 
      *    1. coyote calls mapper -> result Adapter 
      *    2. service is called. Additional filters are set on the wrapper. 
+     * @param mapRes 
      */
-    public void serviceServlet(org.apache.coyote.Request req, 
-                               org.apache.coyote.Response res,
-                               ServletConfigImpl servletConfig) 
+    public void serviceServlet(Request req, ServletRequestImpl request, 
+                               ServletResponseImpl response,
+                               ServletConfigImpl servletConfig, MappingData mapRes) 
         throws IOException {
         
-        ServletRequestImpl request = (ServletRequestImpl) req.getNote(ADAPTER_NOTES);
-        ServletResponseImpl response = (ServletResponseImpl) res.getNote(ADAPTER_NOTES);
-
-        if (request == null) {
-
-            // Create objects
-            request = new ServletRequestImpl();
-            request.setCoyoteRequest(req);
-            response = new ServletResponseImpl();
-            response.setRequest(request);
-            response.setCoyoteResponse(res);
-
-            // Link objects
-            request.setResponse(response);
-
-            // Set as notes
-            req.setNote(ADAPTER_NOTES, request);
-            res.setNote(ADAPTER_NOTES, response);
-
-            // Set query string encoding
-//            req.getParameters().setQueryStringEncoding
-//                (connector.getURIEncoding());
-
-        }
-
         try {
 
             // Parse and set Catalina and configuration specific 
             // request parameters
+            
 //            if ( postParseRequest(req, request, res, response) ) {
 //                // Calling the container
 //                connector.getContainer().getPipeline().getFirst().invoke(request, response);
@@ -139,8 +163,15 @@
             
 
             Servlet servlet = servletConfig.allocate();
+            WebappFilterMapper filterMap = servletConfig.getParent().getFilterMapper();
+            FilterChainImpl chain = 
+                filterMap.createFilterChain(request, servletConfig, servlet);
             
-            servlet.service(request, response);
+            if (chain == null) {
+                servlet.service(request, response);
+            } else {
+                chain.doFilter(request, response);
+            }
             
             response.finishResponse();
             req.action( ActionCode.ACTION_POST_REQUEST , null);
@@ -276,4 +307,5 @@
         return false;
     }
 
+    // --------------------------------------------------------- Public Methods
 }

Copied: tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteMain.java (from r410655, tomcat/sandbox/java/org/apache/coyote/servlet/Main.java)
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteMain.java?p2=tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteMain.java&p1=tomcat/sandbox/java/org/apache/coyote/servlet/Main.java&r1=410655&r2=415818&rev=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/Main.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteMain.java Tue Jun 20 14:45:26 2006
@@ -7,10 +7,10 @@
  * Simple example of embeding coyote servlet.
  * 
  */
-public class Main  {
+public class CoyoteMain  {
     CoyoteServletFacade facade;
     
-    public Main() {        
+    public CoyoteMain() {        
     }
 
     /**
@@ -22,16 +22,15 @@
     
     public void init() {
         facade = CoyoteServletFacade.getServletImpl();
-        facade.initHttp(8800);
+        facade.setPort(8800);
         facade.getProtocol().getEndpoint().setDaemon(false);        
     }
     
     
     public void start() {
         try {
-            ServletContext ctx = facade.createServletContext("localhost", "");
-            facade.setBasePath(ctx, "webapps/ROOT");
-            facade.initContext(ctx);
+            ServletContext ctx = facade.addServletContext("localhost", 
+                                "webapps/ROOT", "");
             facade.start();
         } catch (Throwable e) {
             e.printStackTrace();
@@ -40,7 +39,7 @@
     
     // ------------------- Main ---------------------
     public static void main( String args[]) {
-        Main sa=new Main();
+        CoyoteMain sa=new CoyoteMain();
         sa.run();
     }
 

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java Tue Jun 20 14:45:26 2006
@@ -4,191 +4,318 @@
 
 import java.io.File;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 import javax.servlet.Servlet;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
-import org.apache.tomcat.servlets.file.FileServlet;
-import org.apache.tomcat.util.http.mapper.Mapper;
-import org.apache.tomcat.util.loader.Module;
+import org.apache.coyote.servlet.webxml.WebXml;
+import org.apache.tomcat.servlets.file.DefaultServlet;
 import org.apache.tomcat.util.loader.Repository;
 import org.apache.tomcat.util.net.http11.Http11Protocol;
 
 /**
  * Frontend for a minimal servlet impl for coyote.
  * 
- * This is based on catalina classes, with non-essential features removed.
- * It is possible to add back some of the flexibility using callbacks/hooks, but
- * without requiring additional code - this package should be a sufficient 
- * implementation for a working servlet container.
+ * This is based on catalina classes, with non-essential features removed. It is
+ * possible to add back some of the flexibility using callbacks/hooks - but this
+ * package should be a sufficient implementation for a working servlet
+ * container, with no extra features ( just hooks ).
+ * 
+ * Most of the implementation classes are not public - and must be accessed via
+ * the facade. This can provide additional control and may simplify the
+ * interface ( while allowing changes in the impl ).
  * 
  * @author Costin Manolache
  */
 public class CoyoteServletFacade {
-    static CoyoteServletFacade facade = new CoyoteServletFacade();
-    
-    /** Simple interface to be used by manually or generated web.xml
-     *  readers.
-     */ 
+    private static CoyoteServletFacade facade = new CoyoteServletFacade();
+
+    /**
+     * Simple interface to be used by manually or generated web.xml readers.
+     */
     public static interface WebappInitializer {
-        public void initWebapp(CoyoteServletFacade facade, ServletContext ctx) 
-          throws ServletException;
+        public void initWebapp(CoyoteServletFacade facade, ServletContext ctx)
+            throws ServletException;
     }
 
-    protected HashMap hosts = new HashMap(); 
+    protected ManagedObjectListener[] listeners = new ManagedObjectListener[8];
+
     protected Http11Protocol proto;
-    Mapper mapper = new Mapper();
-    Mapper authMapper = new Mapper();
-    
+
+    /*
+     * Top-level mapper.
+     */
+    protected CoyoteAdapter mainAdapter;
+
     String hostname = ""; // current hostname, used for settings
-    
-    protected MapperAdapter mainAdapter;
-    //FileAdapter fa = new FileAdapter();
-    
-    
+
     private CoyoteServletFacade() {
         proto = new Http11Protocol();
-
-        mainAdapter = new MapperAdapter(mapper);        
-
-        //Counters cnt=new Counters();
-        //cnt.setNext( mainAdapter );
+        mainAdapter = new CoyoteAdapter();
         proto.setAdapter(mainAdapter);
-        //proto.setAdapter(cnt);
-
-        //mapper.addWrapper("*", fa);
-        mapper.setDefaultHostName("localhost");
-
     }
-    
+
     public static CoyoteServletFacade getServletImpl() {
         // TODO: restrict access to only first call.
         return facade;
     }
-    
+
+    // --------------- Connector related features -------------
+
+    /**
+     * Fine tunning
+     */
     public Http11Protocol getProtocol() {
         return proto;
     }
-    
-    public void initHttp(int port) {
+
+    /** 
+     */
+    public void setPort(int port) {
         proto.getEndpoint().setPort(port);
     }
 
+    // --------------- start/stop ---------------
+
     public void start() {
-        if( proto.getEndpoint().getPort() == 0 ) { //&& 
-                //proto.getEndpoint().getServerSocket() == null) {
-            proto.getEndpoint().setPort(8800);
-        }
-        
+        // start all contexts
+
         try {
             proto.init();
-
-            proto.getEndpoint().setDaemon(false);
+            
+            // init all contexts
+            Iterator hostI = mainAdapter.getHostMapper().getHosts();
+            while(hostI.hasNext()) {
+                Host host = (Host)hostI.next();
+                Iterator ctxI = host.getContexts();
+                while (ctxI.hasNext()) {
+                    ServletContextImpl ctx = (ServletContextImpl)ctxI.next();
+                    ctx.init();
+                }
+            }
             
             proto.start();
-
         } catch (Throwable e) {
             e.printStackTrace();
         }
     }
-    
-    // TODO: make sure the mapper is the only one holding references to any
-    // of the objects - better reloading
+
+    public void stop() {
+        try {
+            proto.destroy();
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        // TODO: stop all contexts
+    }
+
+    // --------------- Host add/remove -------------
+
+    public Host getDefaultHost() {
+        return mainAdapter.hostMapper.defaultHost;
+    }
 
     /**
+     * Add a host. You don't need to add the default host.
+     * 
+     * Hosts must be added before any context for that host. If a context is
+     * added without a host, the default host will be used.
      * 
-     * @param hostname - "" if default host, or string to be matched with Host header
-     * @param path - context path, "/" for root, "/examples", etc
+     */
+    public Host addHost(String name, String aliases[]) {
+        Host host = new Host();
+        host.setName(name);
+
+        mainAdapter.getHostMapper().addHost(name, aliases, host);
+        notifyAdd(host);
+        return host;
+    }
+
+    // -------------- Context add/remove --------------
+
+    /**
+     * 
+     * @param hostname - ""
+     *            if default host, or string to be matched with Host header
+     * @param path -
+     *            context path, "/" for root, "/examples", etc
      * @return a servlet context
-     * @throws ServletException 
+     * @throws ServletException
      */
-    public ServletContext createServletContext(String hostname, String path) 
-            throws ServletException {
-        
-        Host host = (Host)hosts.get(hostname);
-        if( host == null ) {
-            host = new Host();
-            host.setName(hostname);
-            hosts.put(hostname, host);
-            mapper.addHost(hostname, new String[] {}, host);
-        }
+    public ServletContext addServletContext(String hostname, String basePath,
+                                            String path)
+        throws ServletException
+    {
+
+        Host host =
+            (hostname == null) ? getDefaultHost() : mainAdapter.getHostMapper()
+                    .findHost(hostname);
+            
         ServletContextImpl ctx = new ServletContextImpl();
         ctx.setParent(host);
-        ctx.setPath(path);
-        
+        ctx.setContextPath(path);
+        ctx.setBasePath(basePath);
+
         // TODO: read web.xml or equivalent
-        
-        // TODO: defaults 
+
+        // TODO: defaults
         // 
-        mapper.addContext(hostname, path, ctx, new String[] {"index.html"}, 
-                null);
-        
+        mainAdapter.getHostMapper().addContext(hostname, ctx,
+                                               new String[] { "index.html" },
+                                               new File(basePath));
+
         host.addChild(ctx);
-        
-        // Add default mappings. 
-        ServletConfig fileS = createServletWrapper(ctx, "file", 
-                new FileServlet());
-        addMapping("/", fileS);
+
         return ctx;
     }
-    
-    public void setBasePath(ServletContext ctx, String dir) {
-        ((ServletContextImpl)ctx).setBasePath(dir);
+
+    public void removeServletContext(ServletContext sctx)
+        throws ServletException
+    {
+        ServletContextImpl ctx = (ServletContextImpl) sctx;
+
+        
+        // TODO: destroy all servlets and filters
+        // TODO: clean up any other reference to the context or its loader
+        
+        mainAdapter.getHostMapper().removeContext(ctx.getParent().getName(),
+                                                  ctx.getContextPath());
+        notifyRemove(ctx);
+    }
+
+    public ServletContext reloadServletContext(ServletContext sctx)
+        throws ServletException
+    {
+        ServletContextImpl ctx = (ServletContextImpl) sctx;
+        String hostname = ctx.getParent().getName();
+        String basePath = ctx.getBasePath();
+        String path = ctx.getContextPath();
+
+        removeServletContext(sctx);
+
+        ServletContextImpl res = 
+            (ServletContextImpl)addServletContext(hostname, basePath, path);
+        res.init();
+        return res;
     }
+    
 
     // -------------- Web.xml reader will call this ---------
     // For specialized cases - you can call this directly
     // Experiment: WebXmlConfig to call this or generate properties, then
     // at run time read the properties.
-    
-    public void setContextParams(ServletContext ctx, HashMap params) {
-        ((ServletContextImpl)ctx).setContextParameters(params);
-    }
 
-    public ServletConfig createServletWrapper(ServletContext ctx, 
-            String name, Servlet servlet) throws ServletException {
+    public ServletConfig createServletWrapper(ServletContext ctx, String name,
+                                              Servlet servlet)
+        throws ServletException
+    {
         ServletConfigImpl w = new ServletConfigImpl();
         // TODO: postpone to first use
         // TODO: grab config
-        servlet.init(w);
         w.setServlet(servlet);
-        w.setParent((ServletContextImpl)ctx);
+        w.setParent((ServletContextImpl) ctx);
+
+        ((ServletContextImpl)ctx).addServletConfig(w);
+        notifyAdd(w);
+        // won't be called automatically if Servlet is used.
+        servlet.init(w);
+        return w;
+    }
+
+    public ServletConfig createServletWrapper(ServletContext ctx, String name,
+                                              String servletClass, Map initParams)
+        throws ServletException
+    {
+        ServletConfigImpl w = new ServletConfigImpl();
+        // TODO: postpone to first use
+        // TODO: grab config
+        w.setServletClass(servletClass);
+        w.setParent((ServletContextImpl) ctx);
+        w.setServletName(name);
+        
+        if (initParams != null)
+            w.setInitParameters(initParams);
+        
+        ((ServletContextImpl)ctx).addServletConfig(w);
+        notifyAdd(w);
         return w;
     }
 
     public void addMapping(String path, ServletConfig wrapper) {
-        ServletContextImpl ctx = (ServletContextImpl)wrapper.getServletContext();
-        Host host = (ctx).getParent();
-        mapper.addWrapper(host.getName(), ctx.getPath(), path, wrapper);
-        //new CoyoteServletAdapter(wrapper));
+        ServletContextImpl ctx =
+            (ServletContextImpl) wrapper.getServletContext();
+        ctx.getMapper().addWrapper(ctx.getMapper().contextMapElement, path, wrapper);
     }
-    
 
-    public void initContext(ServletContext ctx) {
-        // Set up class loader.
-        String base = ((ServletContextImpl)ctx).getBasePath();
-        Repository ctxRepo = new Repository();
-        ctxRepo.setParentClassLoader(this.getClass().getClassLoader());
-        ctxRepo.addDir(new File(base + "/WEB-INF/classes"));
-        ctxRepo.addLibs(new File(base + "/WEB-INF/lib"));
-        
-        ClassLoader cl = ctxRepo.getClassLoader();
-        
-        // Code-based configuration - experiment with generated web.xml->class
-        try {
-            Class c = cl.loadClass("WebappInit");
-            WebappInitializer webInit = (WebappInitializer)c.newInstance();
-            webInit.initWebapp(this, ctx);
-        } catch(Throwable t) {
-            t.printStackTrace();
+    // ------------ Notifications for JMX ----------------
+
+    /**
+     * Hook for JMX
+     */
+    public static interface ManagedObjectListener {
+        public void addManagedObject(Object o);
+
+        public void removeManagedObject(Object o);
+    }
+
+    public void addManagedObjectListener(ManagedObjectListener l) {
+        for (int i = 0; i < listeners.length; i++) {
+            if (listeners[i] == null) {
+                listeners[i] = l;
+                return;
+            }
+        }
+        // TODO: resize
+    }
+
+    public void removeManagedObjectListener(ManagedObjectListener l) {
+        int found = -1;
+        int i = 0;
+        while (i < listeners.length) {
+            if (listeners[i] == l) {
+                found = i;
+            }
+            if (listeners[i] == null) {
+                i--;
+                break;
+            }
+            i++;
+        }
+        if (found == -1)
+            return;
+        if (found == i) {
+            listeners[found] = null;
+        }
+        listeners[found] = listeners[i];
+        listeners[i] = null;
+    }
+
+    void notifyAdd(Object o) {
+        for (int i = 0; i < listeners.length; i++) {
+            if (listeners[i] == null)
+                return;
+            try {
+                listeners[i].addManagedObject(o);
+            } catch (Throwable t) {
+                t.printStackTrace();
+            }
         }
-        
-        // TODO: read a simpler version of web.xml
-        
-        // TODO: read the real web.xml
-        
     }
 
+    void notifyRemove(Object o) {
+        for (int i = 0; i < listeners.length; i++) {
+            if (listeners[i] == null)
+                return;
+            try {
+                listeners[i].removeManagedObject(o);
+            } catch (Throwable t) {
+                t.printStackTrace();
+            }
+        }
+    }
 }

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/FilterChainImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/FilterChainImpl.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/FilterChainImpl.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/FilterChainImpl.java Tue Jun 20 14:45:26 2006
@@ -19,7 +19,6 @@
 
 
 import java.io.IOException;
-import java.security.PrivilegedActionException;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
@@ -27,8 +26,6 @@
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import org.apache.tomcat.util.res.StringManager;
 
@@ -47,10 +44,6 @@
 
 final class FilterChainImpl implements FilterChain {
 
-
-    // -------------------------------------------------------------- Constants
-
-
     public static final int INCREMENT = 10;
 
 
@@ -143,38 +136,6 @@
     public void doFilter(ServletRequest request, ServletResponse response)
         throws IOException, ServletException {
 
-        if( System.getSecurityManager() != null ) {
-            final ServletRequest req = request;
-            final ServletResponse res = response;
-            try {
-                java.security.AccessController.doPrivileged(
-                    new java.security.PrivilegedExceptionAction() {
-                        public Object run() 
-                            throws ServletException, IOException {
-                            internalDoFilter(req,res);
-                            return null;
-                        }
-                    }
-                );
-            } catch( PrivilegedActionException pe) {
-                Exception e = pe.getException();
-                if (e instanceof ServletException)
-                    throw (ServletException) e;
-                else if (e instanceof IOException)
-                    throw (IOException) e;
-                else if (e instanceof RuntimeException)
-                    throw (RuntimeException) e;
-                else
-                    throw new ServletException(e.getMessage(), e);
-            }
-        } else {
-            internalDoFilter(request,response);
-        }
-    }
-
-    private void internalDoFilter(ServletRequest request, 
-                                  ServletResponse response)
-        throws IOException, ServletException {
 
         // Call the next filter if there is one
         if (pos < n) {
@@ -182,45 +143,15 @@
             Filter filter = null;
             try {
                 filter = filterConfig.getFilter();
-//                support.fireInstanceEvent(InstanceEvent.BEFORE_FILTER_EVENT,
-//                                          filter, request, response);
-                
-//                if( System.getSecurityManager() != null ) {
-//                    final ServletRequest req = request;
-//                    final ServletResponse res = response;
-//                    Principal principal = 
-//                        ((HttpServletRequest) req).getUserPrincipal();
-//
-//                    Object[] args = new Object[]{req, res, this};
-//                    SecurityUtil.doAsPrivilege
-//                        ("doFilter", filter, classType, args);
-//                    
-//                    args = null;
-//                } else {  
-                    filter.doFilter(request, response, this);
-//                }
-
-//                support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
-//                                          filter, request, response);
+                filter.doFilter(request, response, this);
             } catch (IOException e) {
-//                if (filter != null)
-//                    support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
-//                                              filter, request, response, e);
                 throw e;
             } catch (ServletException e) {
-//                if (filter != null)
-//                    support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
-//                                              filter, request, response, e);
                 throw e;
             } catch (RuntimeException e) {
-//                if (filter != null)
-//                    support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
-//                                              filter, request, response, e);
                 throw e;
             } catch (Throwable e) {
-//                if (filter != null)
-//                    support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
-//                                              filter, request, response, e);
+                e.printStackTrace();
                 throw new ServletException
                   (sm.getString("filterChain.filter"), e);
             }
@@ -229,51 +160,18 @@
 
         // We fell off the end of the chain -- call the servlet instance
         try {
-//            support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
-//                                      servlet, request, response);
-            if ((request instanceof HttpServletRequest) &&
-                (response instanceof HttpServletResponse)) {
-//                    
-//                if( System.getSecurityManager() != null ) {
-//                    final ServletRequest req = request;
-//                    final ServletResponse res = response;
-//                    Principal principal = 
-//                        ((HttpServletRequest) req).getUserPrincipal();
-//                    Object[] args = new Object[]{req, res};
-//                    SecurityUtil.doAsPrivilege("service",
-//                                               servlet,
-//                                               classTypeUsedInService, 
-//                                               args,
-//                                               principal);   
-//                    args = null;
-//                } else {  
-                    servlet.service((HttpServletRequest) request,
-                                    (HttpServletResponse) response);
-//                }
-            } else {
+            if (servlet != null) 
                 servlet.service(request, response);
-            }
-//            support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
-//                                      servlet, request, response);
         } catch (IOException e) {
-//            support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
-//                                      servlet, request, response, e);
             throw e;
         } catch (ServletException e) {
-//            support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
-//                                      servlet, request, response, e);
             throw e;
         } catch (RuntimeException e) {
-//            support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
-//                                      servlet, request, response, e);
             throw e;
         } catch (Throwable e) {
-//            support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
-//                                      servlet, request, response, e);
             throw new ServletException
               (sm.getString("filterChain.servlet"), e);
         }
-
     }
 
 
@@ -287,7 +185,6 @@
      * @param filterConfig The FilterConfig for the servlet to be executed
      */
     void addFilter(FilterConfigImpl filterConfig) {
-
         if (n == filters.length) {
             FilterConfigImpl[] newFilters =
                 new FilterConfigImpl[n + INCREMENT];
@@ -295,7 +192,6 @@
             filters = newFilters;
         }
         filters[n++] = filterConfig;
-
     }
 
 
@@ -303,12 +199,9 @@
      * Release references to the filters and wrapper executed by this chain.
      */
     void release() {
-
         n = 0;
         pos = 0;
         servlet = null;
-//        support = null;
-
     }
 
 
@@ -317,24 +210,10 @@
      *
      * @param servlet The Wrapper for the servlet to be executed
      */
-    void setServlet(Servlet servlet) {
+    public void setServlet(Servlet servlet) {
 
         this.servlet = servlet;
 
     }
-
-
-    /**
-     * Set the InstanceSupport object used for event notifications
-     * for this filter chain.
-     *
-     * @param support The InstanceSupport object for our Wrapper
-     */
-//    void setSupport(InstanceSupport support) {
-//
-//        this.support = support;
-//
-//    }
-
 
 }

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/FilterConfigImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/FilterConfigImpl.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/FilterConfigImpl.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/FilterConfigImpl.java Tue Jun 20 14:45:26 2006
@@ -54,6 +54,8 @@
      */
     private ServletContextImpl context = null;
 
+    private Map parameters = new HashMap();
+
     /**
      * The application Filter we are configured for.
      */
@@ -61,17 +63,19 @@
 
     private String filterName = null;
 
+    private String filterClass = null;
+
     void setFilterName(String filterName) {
         this.filterName = filterName;
     }
     
-    private Map parameters = new HashMap();
-
     public Map getParameterMap() {
         return (this.parameters);
     }
 
-    private String filterClass = null;
+    public void setParameterMap(Map initParams) {
+        parameters = initParams;
+    }
 
     public String getFilterClass() {
         return (this.filterClass);
@@ -81,8 +85,6 @@
         this.filterClass = filterClass;
     }
 
-
-
     // --------------------------------------------------- FilterConfig Methods
 
     public String getFilterName() {
@@ -117,31 +119,9 @@
      * Return the ServletContext of our associated web application.
      */
     public ServletContext getServletContext() {
-
-        return (this.context.getServletContext());
-
+        return context;
     }
 
-
-    /**
-     * Return a String representation of this object.
-     */
-    public String toString() {
-
-        StringBuffer sb = new StringBuffer("ApplicationFilterConfig[");
-        sb.append("name=");
-        sb.append(getFilterName());
-        sb.append(", filterClass=");
-        sb.append(getFilterClass());
-        sb.append("]");
-        return (sb.toString());
-
-    }
-
-
-    // -------------------------------------------------------- Package Methods
-
-
     /**
      * Return the application Filter we are configured for.
      *
@@ -164,7 +144,7 @@
         // Identify the class loader we will be using
         String filterClass = getFilterClass();
         ClassLoader classLoader = null;
-        if (filterClass.startsWith("org.apache.catalina."))
+        if (filterClass.startsWith("org.apache.tomcat.servlet."))
             classLoader = this.getClass().getClassLoader();
         else
             classLoader = context.getClassLoader();
@@ -174,6 +154,8 @@
 
         // Instantiate a new instance of this filter and return it
         Class clazz = classLoader.loadClass(filterClass);
+        
+        
         this.filter = (Filter) clazz.newInstance();
         if (context instanceof ServletContextImpl &&
             ((ServletContextImpl)context).getSwallowOutput()) {

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/Host.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/Host.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/Host.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/Host.java Tue Jun 20 14:45:26 2006
@@ -19,7 +19,9 @@
 
 
 import java.util.HashMap;
+import java.util.Iterator;
 
+import org.apache.coyote.servlet.WebappServletMapper.ContextMapElement;
 import org.apache.tomcat.util.res.StringManager;
 
 
@@ -57,107 +59,47 @@
 
     // ----------------------------------------------------- Instance Variables
 
+    String  name = "";
 
     /**
      * The set of aliases for this Host.
      */
     private String[] aliases = new String[0];
 
+    // <String path, ServletContextImp>
+    private HashMap children = new HashMap();
+
+    ContextMapElement[] contexts = new ContextMapElement[0];
+    int nesting = 0;
 
+    // ---- Deployer stuff - shouldn't be in here -----
+    
     /**
      * The application root for this Host.
      */
     private String appBase = ".";
 
-
-    /**
-     * The auto deploy flag for this Host.
-     */
-    private boolean autoDeploy = true;
-
-
     /**
-     * The Java class name of the default context configuration class
-     * for deployed web applications.
+     * Work Directory base for applications.
      */
-    private String configClass =
-        "org.apache.catalina.startup.ContextConfig";
-
+    private String workDir = null;
 
     /**
-     * The Java class name of the default Context implementation class for
-     * deployed web applications.
+     * The auto deploy flag for this Host.
      */
-    private String contextClass =
-        "org.apache.catalina.core.StandardContext";
-
+    private boolean autoDeploy = true;
 
     /**
      * The deploy on startup flag for this Host.
      */
     private boolean deployOnStartup = true;
 
-
     /**
      * deploy Context XML config files property.
      */
     private boolean deployXML = true;
 
 
-    /**
-     * The Java class name of the default error reporter implementation class 
-     * for deployed web applications.
-     */
-    private String errorReportValveClass =
-        "org.apache.catalina.valves.ErrorReportValve";
-
-    /**
-     * The object name for the errorReportValve.
-     */
-//    private ObjectName errorReportValveObjectName = null;
-
-    /**
-     * The descriptive information string for this implementation.
-     */
-    private static final String info =
-        "org.apache.catalina.core.StandardHost/1.0";
-
-
-    /**
-     * The live deploy flag for this Host.
-     */
-    private boolean liveDeploy = true;
-
-
-    /**
-     * Unpack WARs property.
-     */
-    private boolean unpackWARs = true;
-
-
-    /**
-     * Work Directory base for applications.
-     */
-    private String workDir = null;
-
-
-    /**
-     * Attribute value used to turn on/off XML validation
-     */
-     private boolean xmlValidation = false;
-
-
-    /**
-     * Attribute value used to turn on/off XML namespace awarenes.
-     */
-     private boolean xmlNamespaceAware = false;
-
-
-    private String name;
-
-    private HashMap children = new HashMap();
-
-
     // ------------------------------------------------------------- Properties
 
 
@@ -211,62 +153,6 @@
 //                                   this.autoDeploy);
 
     }
-
-
-    /**
-     * Return the Java class name of the context configuration class
-     * for new web applications.
-     */
-    public String getConfigClass() {
-
-        return (this.configClass);
-
-    }
-
-
-    /**
-     * Set the Java class name of the context configuration class
-     * for new web applications.
-     *
-     * @param configClass The new context configuration class
-     */
-    public void setConfigClass(String configClass) {
-
-        String oldConfigClass = this.configClass;
-        this.configClass = configClass;
-//        support.firePropertyChange("configClass",
-//                                   oldConfigClass, this.configClass);
-
-    }
-
-
-    /**
-     * Return the Java class name of the Context implementation class
-     * for new web applications.
-     */
-    public String getContextClass() {
-
-        return (this.contextClass);
-
-    }
-
-
-    /**
-     * Set the Java class name of the Context implementation class
-     * for new web applications.
-     *
-     * @param contextClass The new context implementation class
-     */
-    public void setContextClass(String contextClass) {
-
-        String oldContextClass = this.contextClass;
-        this.contextClass = contextClass;
-//        support.firePropertyChange("contextClass",
-//                                   oldContextClass, this.contextClass);
-
-    }
-
-
     /**
      * Return the value of the deploy on startup flag.  If true, it indicates 
      * that this host's child webapps should be discovred and automatically 
@@ -335,35 +221,6 @@
         setAutoDeploy(liveDeploy);
     }
 
-
-    /**
-     * Return the Java class name of the error report valve class
-     * for new web applications.
-     */
-    public String getErrorReportValveClass() {
-
-        return (this.errorReportValveClass);
-
-    }
-
-
-    /**
-     * Set the Java class name of the error report valve class
-     * for new web applications.
-     *
-     * @param errorReportValveClass The new error report valve class
-     */
-    public void setErrorReportValveClass(String errorReportValveClass) {
-
-        String oldErrorReportValveClassClass = this.errorReportValveClass;
-        this.errorReportValveClass = errorReportValveClass;
-//        support.firePropertyChange("errorReportValveClass",
-//                                   oldErrorReportValveClassClass, 
-//                                   this.errorReportValveClass);
-
-    }
-
-
     /**
      * Return the canonical, fully qualified, name of the virtual host
      * this Container represents.
@@ -399,64 +256,6 @@
 
 
     /**
-     * Unpack WARs flag accessor.
-     */
-    public boolean isUnpackWARs() {
-
-        return (unpackWARs);
-
-    }
-
-
-    /**
-     * Unpack WARs flag mutator.
-     */
-    public void setUnpackWARs(boolean unpackWARs) {
-
-        this.unpackWARs = unpackWARs;
-
-    }
-
-     /**
-     * Set the validation feature of the XML parser used when
-     * parsing xml instances.
-     * @param xmlValidation true to enable xml instance validation
-     */
-    public void setXmlValidation(boolean xmlValidation){
-        
-        this.xmlValidation = xmlValidation;
-
-    }
-
-    /**
-     * Get the server.xml <host> attribute's xmlValidation.
-     * @return true if validation is enabled.
-     *
-     */
-    public boolean getXmlValidation(){
-        return xmlValidation;
-    }
-
-    /**
-     * Get the server.xml <host> attribute's xmlNamespaceAware.
-     * @return true if namespace awarenes is enabled.
-     *
-     */
-    public boolean getXmlNamespaceAware(){
-        return xmlNamespaceAware;
-    }
-
-
-    /**
-     * Set the namespace aware feature of the XML parser used when
-     * parsing xml instances.
-     * @param xmlNamespaceAware true to enable namespace awareness
-     */
-    public void setXmlNamespaceAware(boolean xmlNamespaceAware){
-        this.xmlNamespaceAware=xmlNamespaceAware;
-    }    
-    
-    /**
      * Host work directory base.
      */
     public String getWorkDir() {
@@ -513,13 +312,7 @@
      * @param child Child container to be added
      */
     public void addChild(ServletContextImpl child) {
-
-        if (!(child instanceof ServletContextImpl))
-            throw new IllegalArgumentException
-                (sm.getString("standardHost.notContext"));
-//        super.addChild(child);
-
-        children .put(child.getName(), child);
+        children.put(child.getName(), child);
     }
 
 
@@ -535,18 +328,6 @@
 
 
     /**
-     * Return descriptive information about this Container implementation and
-     * the corresponding version number, in the format
-     * <code>&lt;description&gt;/&lt;version&gt;</code>.
-     */
-    public String getInfo() {
-
-        return (info);
-
-    }
-
-
-    /**
      * Return the Context that would be used to process the specified
      * host-relative request URI, if any; otherwise return <code>null</code>.
      *
@@ -589,7 +370,7 @@
 
         // Return the mapped Context (if any)
         if (log.isDebugEnabled())
-            log.debug(" Mapped to context '" + context.getPath() + "'");
+            log.debug(" Mapped to context '" + context.getContextPath() + "'");
         return (context);
 
     }
@@ -706,12 +487,6 @@
 //                     errorReportValveClass));
 //            }
 //        }
-        if(log.isInfoEnabled()) {
-            if (xmlValidation)
-                log.info( sm.getString("standardHost.validationEnabled"));
-            else
-                log.info( sm.getString("standardHost.validationDisabled"));
-        }
 //        super.start();
 
     }
@@ -797,6 +572,9 @@
       
     }
 
+    public Iterator getContexts() {
+        return children.values().iterator();
+    }
 
     public ServletContextImpl findChild(String mapuri) {
         return (ServletContextImpl)children.get(mapuri);

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/HttpSessionImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/HttpSessionImpl.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/HttpSessionImpl.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/HttpSessionImpl.java Tue Jun 20 14:45:26 2006
@@ -31,6 +31,7 @@
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.servlet.ServletContext;
@@ -71,8 +72,7 @@
  * @version $Revision: 375376 $ $Date: 2006-02-06 13:22:14 -0800 (Mon, 06 Feb 2006) $
  */
 
-public class HttpSessionImpl
-    implements HttpSession, Serializable {
+public class HttpSessionImpl  implements HttpSession, Serializable {
 
 
     // ----------------------------------------------------------- Constructors
@@ -83,7 +83,7 @@
      *
      * @param manager The manager with which this Session is associated
      */
-    public HttpSessionImpl(SessionManager manager) {
+    public HttpSessionImpl(WebappSessionManager manager) {
 
         super();
         this.manager = manager;
@@ -203,7 +203,7 @@
     /**
      * The Manager with which this Session is associated.
      */
-    protected transient SessionManager manager = null;
+    protected transient WebappSessionManager manager = null;
 
 
     /**
@@ -368,15 +368,16 @@
 
         // Notify interested application event listeners
         ServletContextImpl context = (ServletContextImpl) manager.getContainer();
-        Object listeners[] = context.getApplicationLifecycleListeners();
-        if (listeners != null) {
+        List listeners = context.getApplicationEventListeners();
+        if (listeners.size() > 0) {
             HttpSessionEvent event =
                 new HttpSessionEvent(getSession());
-            for (int i = 0; i < listeners.length; i++) {
-                if (!(listeners[i] instanceof HttpSessionListener))
+            for (int i = 0; i < listeners.size(); i++) {
+                Object listenerObj = listeners.get(i);
+                if (!(listenerObj instanceof HttpSessionListener))
                     continue;
                 HttpSessionListener listener =
-                    (HttpSessionListener) listeners[i];
+                    (HttpSessionListener) listenerObj;
                 try {
                     fireContainerEvent(context,
                                        "beforeSessionCreated",
@@ -434,7 +435,7 @@
     /**
      * Return the Manager within which this Session is valid.
      */
-    public SessionManager getManager() {
+    public WebappSessionManager getManager() {
 
         return (this.manager);
 
@@ -446,7 +447,7 @@
      *
      * @param manager The new Manager
      */
-    public void setManager(SessionManager manager) {
+    public void setManager(WebappSessionManager manager) {
 
         this.manager = manager;
 
@@ -664,16 +665,17 @@
             // Notify interested application event listeners
             // FIXME - Assumes we call listeners in reverse order
             ServletContextImpl context = (ServletContextImpl) manager.getContainer();
-            Object listeners[] = context.getApplicationLifecycleListeners();
-            if (notify && (listeners != null)) {
+            List listeners = context.getApplicationEventListeners();
+            if (notify && (listeners.size() > 0)) {
                 HttpSessionEvent event =
                     new HttpSessionEvent(getSession());
-                for (int i = 0; i < listeners.length; i++) {
-                    int j = (listeners.length - 1) - i;
-                    if (!(listeners[j] instanceof HttpSessionListener))
+                for (int i = 0; i < listeners.size(); i++) {
+                    Object listenerObj = listeners.get(i);
+                    int j = (listeners.size() - 1) - i;
+                    if (!(listenerObj instanceof HttpSessionListener))
                         continue;
                     HttpSessionListener listener =
-                        (HttpSessionListener) listeners[j];
+                        (HttpSessionListener) listenerObj;
                     try {
                         fireContainerEvent(context,
                                            "beforeSessionDestroyed",
@@ -1280,14 +1282,14 @@
 
         // Notify interested application event listeners
         ServletContextImpl context = (ServletContextImpl) manager.getContainer();
-        Object listeners[] = context.getApplicationEventListeners();
-        if (listeners == null)
+        List listeners = context.getApplicationEventListeners();
+        if (listeners.size() == 0)
             return;
-        for (int i = 0; i < listeners.length; i++) {
-            if (!(listeners[i] instanceof HttpSessionAttributeListener))
+        for (int i = 0; i < listeners.size(); i++) {
+            if (!(listeners.get(i) instanceof HttpSessionAttributeListener))
                 continue;
             HttpSessionAttributeListener listener =
-                (HttpSessionAttributeListener) listeners[i];
+                (HttpSessionAttributeListener) listeners.get(i);
             try {
                 if (unbound != null) {
                     fireContainerEvent(context,
@@ -1605,14 +1607,14 @@
 
         // Notify interested application event listeners
         ServletContextImpl context = (ServletContextImpl) manager.getContainer();
-        Object listeners[] = context.getApplicationEventListeners();
-        if (listeners == null)
+        List listeners = context.getApplicationEventListeners();
+        if (listeners.size() == 0)
             return;
-        for (int i = 0; i < listeners.length; i++) {
-            if (!(listeners[i] instanceof HttpSessionAttributeListener))
+        for (int i = 0; i < listeners.size(); i++) {
+            if (!(listeners.get(i) instanceof HttpSessionAttributeListener))
                 continue;
             HttpSessionAttributeListener listener =
-                (HttpSessionAttributeListener) listeners[i];
+                (HttpSessionAttributeListener) listeners.get(i);
             try {
                 fireContainerEvent(context,
                                    "beforeSessionAttributeRemoved",

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/RequestDispatcherImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/RequestDispatcherImpl.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/RequestDispatcherImpl.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/RequestDispatcherImpl.java Tue Jun 20 14:45:26 2006
@@ -59,44 +59,7 @@
  * @version $Revision: 303947 $ $Date: 2005-06-08 22:50:26 -0700 (Wed, 08 Jun 2005) $
  */
 
-final class RequestDispatcherImpl
-    implements RequestDispatcher {
-
-
-    protected class PrivilegedForward implements PrivilegedExceptionAction {
-        private ServletRequest request;
-        private ServletResponse response;
-
-        PrivilegedForward(ServletRequest request, ServletResponse response)
-        {
-            this.request = request;
-            this.response = response;
-        }
-
-        public Object run() throws java.lang.Exception {
-            doForward(request,response);
-            return null;
-        }
-    }
-
-    protected class PrivilegedInclude implements PrivilegedExceptionAction {
-        private ServletRequest request;
-        private ServletResponse response;
-
-        PrivilegedInclude(ServletRequest request, ServletResponse response)
-        {
-            this.request = request;
-            this.response = response;
-        }
-
-        public Object run() throws ServletException, IOException {
-            doInclude(request,response);
-            return null;
-        }
-    }
-
-    // ----------------------------------------------------------- Constructors
-
+final class RequestDispatcherImpl implements RequestDispatcher {
 
     /**
      * Construct a new instance of this class, configured according to the
@@ -375,25 +338,6 @@
     public void forward(ServletRequest request, ServletResponse response)
         throws ServletException, IOException
     {
-        if (System.getSecurityManager() != null) {
-            try {
-                PrivilegedForward dp = new PrivilegedForward(request,response);
-                AccessController.doPrivileged(dp);
-            } catch (PrivilegedActionException pe) {
-                Exception e = pe.getException();
-                if (e instanceof ServletException)
-                    throw (ServletException) e;
-                throw (IOException) e;
-            }
-        } else {
-            doForward(request,response);
-        }
-    }
-
-    private void doForward(ServletRequest request, ServletResponse response)
-        throws ServletException, IOException
-    {
-        
         // Reset any output that has been buffered, but keep headers/cookies
         if (response.isCommitted()) {
             if ( log.isDebugEnabled() )
@@ -459,7 +403,7 @@
 
             ServletRequestWrapperImpl wrequest =
                 (ServletRequestWrapperImpl) wrapRequest();
-            String contextPath = context.getPath();
+            String contextPath = context.getContextPath();
 
             if (hrequest.getAttribute(FORWARD_REQUEST_URI_ATTR) == null) {
                 wrequest.setAttribute(FORWARD_REQUEST_URI_ATTR,
@@ -539,15 +483,15 @@
         throws IOException, ServletException {
                 
         Integer disInt = (Integer) request.getAttribute
-            (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR);
+            (WebappFilterMapper.DISPATCHER_TYPE_ATTR);
         if (disInt != null) {
-            if (disInt.intValue() != ApplicationFilterFactory.ERROR) {
+            if (disInt.intValue() != WebappFilterMapper.ERROR) {
                 outerRequest.setAttribute
-                    (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
+                    (WebappFilterMapper.DISPATCHER_REQUEST_PATH_ATTR,
                      origServletPath);
                 outerRequest.setAttribute
-                    (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-                     new Integer(ApplicationFilterFactory.FORWARD));
+                    (WebappFilterMapper.DISPATCHER_TYPE_ATTR,
+                     new Integer(WebappFilterMapper.FORWARD));
                 invoke(outerRequest, response);
             } else {
                 invoke(outerRequest, response);
@@ -572,25 +516,7 @@
     public void include(ServletRequest request, ServletResponse response)
         throws ServletException, IOException
     {
-        if (System.getSecurityManager() != null) {
-            try {
-                PrivilegedInclude dp = new PrivilegedInclude(request,response);
-                AccessController.doPrivileged(dp);
-            } catch (PrivilegedActionException pe) {
-                Exception e = pe.getException();
-
-                if (e instanceof ServletException)
-                    throw (ServletException) e;
-                throw (IOException) e;
-            }
-        } else {
-            doInclude(request,response);
-        }
-    }
 
-    private void doInclude(ServletRequest request, ServletResponse response)
-        throws ServletException, IOException
-    {
         // Set up to handle the specified request and response
         setup(request, response, true);
 
@@ -604,9 +530,9 @@
 
             if ( log.isDebugEnabled() )
                 log.debug(" Non-HTTP Include");
-            request.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-                                             new Integer(ApplicationFilterFactory.INCLUDE));
-            request.setAttribute(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, origServletPath);
+            request.setAttribute(WebappFilterMapper.DISPATCHER_TYPE_ATTR,
+                                             new Integer(WebappFilterMapper.INCLUDE));
+            request.setAttribute(WebappFilterMapper.DISPATCHER_REQUEST_PATH_ATTR, origServletPath);
             invoke(request, outerResponse);
         }
 
@@ -621,9 +547,9 @@
             wrequest.setAttribute(NAMED_DISPATCHER_ATTR, name);
             if (servletPath != null)
                 wrequest.setServletPath(servletPath);
-            wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-                                             new Integer(ApplicationFilterFactory.INCLUDE));
-            wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, origServletPath);
+            wrequest.setAttribute(WebappFilterMapper.DISPATCHER_TYPE_ATTR,
+                                             new Integer(WebappFilterMapper.INCLUDE));
+            wrequest.setAttribute(WebappFilterMapper.DISPATCHER_REQUEST_PATH_ATTR, origServletPath);
             invoke(outerRequest, outerResponse);
 
             wrequest.recycle();
@@ -637,7 +563,7 @@
 
             ServletRequestWrapperImpl wrequest =
                 (ServletRequestWrapperImpl) wrapRequest();
-            String contextPath = context.getPath();
+            String contextPath = context.getContextPath();
             if (requestURI != null)
                 wrequest.setAttribute(INCLUDE_REQUEST_URI_ATTR,
                                       requestURI);
@@ -656,9 +582,9 @@
                 wrequest.setQueryParams(queryString);
             }
             
-            wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-                                             new Integer(ApplicationFilterFactory.INCLUDE));
-            wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, origServletPath);
+            wrequest.setAttribute(WebappFilterMapper.DISPATCHER_TYPE_ATTR,
+                                             new Integer(WebappFilterMapper.INCLUDE));
+            wrequest.setAttribute(WebappFilterMapper.DISPATCHER_REQUEST_PATH_ATTR, origServletPath);
             invoke(outerRequest, outerResponse);
 
             wrequest.recycle();
@@ -743,7 +669,8 @@
         }
                 
         // Get the FilterChain Here
-        ApplicationFilterFactory factory = ApplicationFilterFactory.getInstance();
+        WebappFilterMapper factory = 
+            ((ServletContextImpl)wrapper.getServletContext()).getFilterMapper();
         FilterChainImpl filterChain = factory.createFilterChain(request,
                                                                 wrapper,servlet);
         // Call the service() method for the allocated servlet instance
@@ -985,7 +912,7 @@
                     // Forward
                     contextPath = houterRequest.getContextPath();
                 }
-                crossContext = !(context.getPath().equals(contextPath));
+                crossContext = !(context.getContextPath().equals(contextPath));
             }
             wrapper = new ServletRequestWrapperImpl
                 (hcurrent, context, crossContext);

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletConfigImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletConfigImpl.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletConfigImpl.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletConfigImpl.java Tue Jun 20 14:45:26 2006
@@ -23,6 +23,7 @@
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Stack;
 
 import javax.servlet.Servlet;
@@ -34,6 +35,7 @@
 import javax.servlet.SingleThreadModel;
 import javax.servlet.UnavailableException;
 
+import org.apache.catalina.LifecycleException;
 import org.apache.commons.logging.Log;
 import org.apache.coyote.servlet.util.Enumerator;
 import org.apache.tomcat.util.IntrospectionUtils;
@@ -141,7 +143,7 @@
      * The initialization parameters for this servlet, keyed by
      * parameter name.
      */
-    private HashMap parameters = new HashMap();
+    private Map parameters = new HashMap();
 
 
     /**
@@ -620,14 +622,12 @@
      * @param value Value of this initialization parameter to add
      */
     public void addInitParameter(String name, String value) {
-
-        synchronized (parameters) {
-            parameters.put(name, value);
-        }
-//        fireContainerEvent("addInitParameter", name);
-
+        parameters.put(name, value);
     }
 
+    public void setInitParameters(Map params) {
+        parameters = params;
+    }
 
     /**
      * Add a mapping associated with the Wrapper.
@@ -900,7 +900,7 @@
             String actualClass = servletClass;
             if ((actualClass == null) && (jspFile != null)) {
                 ServletConfigImpl jspWrapper = (ServletConfigImpl)
-                    ((ServletContextImpl) getParent()).findChild(JSP_SERVLET_NAME);
+                    ((ServletContextImpl) getParent()).getServletConfig(JSP_SERVLET_NAME);
                 if (jspWrapper != null) {
                     actualClass = jspWrapper.getServletClass();
                     // Merge init parameters
@@ -933,7 +933,10 @@
 //            ClassLoader classLoader = loader.getClassLoader();
 
             // TODO(costin): use real loader if multiple webapps
-            ClassLoader classLoader = this.getClass().getClassLoader();
+            
+            ClassLoader classLoader = parent.getClassLoader(); 
+            if (classLoader == null ) 
+                classLoader = this.getClass().getClassLoader();
             
             // Special case class loader for a container provided servlet
             //  
@@ -1344,6 +1347,9 @@
 
     // -------------------------------------------------- ServletConfig Methods
 
+    public void destroy() {
+        
+    }
 
     /**
      * Return the initialization parameter value for the specified name,



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org