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 [2/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/...

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java Tue Jun 20 14:45:26 2006
@@ -27,27 +27,30 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
-//import javax.naming.Binding;
-//import javax.naming.NamingException;
-//import javax.naming.directory.DirContext;
+import javax.servlet.Filter;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextAttributeEvent;
 import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletException;
 
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.coyote.servlet.util.CharsetMapper;
 import org.apache.coyote.servlet.util.Enumerator;
-
-//import org.apache.naming.resources.DirContextURLStreamHandler;
-//import org.apache.naming.resources.Resource;
-
+import org.apache.coyote.servlet.util.MappingData;
+import org.apache.coyote.servlet.webxml.WebXml;
+import org.apache.tomcat.servlets.file.DefaultServlet;
 import org.apache.tomcat.util.buf.CharChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
-import org.apache.tomcat.util.http.mapper.MappingData;
+import org.apache.tomcat.util.loader.Repository;
 import org.apache.tomcat.util.res.StringManager;
 
 
@@ -61,8 +64,7 @@
  * @version $Revision: 377994 $ $Date: 2006-02-15 04:37:28 -0800 (Wed, 15 Feb 2006) $
  */
 
-public class ServletContextImpl
-    implements ServletContext {
+public class ServletContextImpl implements ServletContext {
 
     // ----------------------------------------------------------- Constructors
 
@@ -70,95 +72,79 @@
     }
 
     // ----------------------------------------------------- Instance Variables
-
-
     /**
-     * The context attributes for this context.
+     * Empty collection to serve as the basis for empty enumerations.
+     * <strong>DO NOT ADD ANY ELEMENTS TO THIS COLLECTION!</strong>
      */
-    private HashMap attributes = new HashMap();
-
+    private static final ArrayList empty = new ArrayList();
 
+    Log log;
     /**
-     * List of read only attributes for this context.
+     * The string manager for this package.
      */
-    private HashMap readOnlyAttributes = new HashMap();
+    private static final StringManager sm =
+      StringManager.getManager("org.apache.coyote.servlet");
 
 
     /**
-     * The Context instance with which we are associated.
+     * The context attributes for this context.
      */
-    private ServletContextImpl context = this;
-
-    /** Internal mapper - it may be better to use only one per server.
-     */ 
-    private org.apache.tomcat.util.http.mapper.Mapper mapper = 
-        new org.apache.tomcat.util.http.mapper.Mapper();
+    private HashMap attributes = new HashMap();
 
 
     /**
-     * Empty collection to serve as the basis for empty enumerations.
-     * <strong>DO NOT ADD ANY ELEMENTS TO THIS COLLECTION!</strong>
+     * List of read only attributes for this context.
      */
-    private static final ArrayList empty = new ArrayList();
-
+    private HashMap readOnlyAttributes = new HashMap();
 
-//    /**
-//     * The facade around this object.
-//     */
-//    private ServletContext facade = new ApplicationContextFacade(this);
+    /** Internal mapper for request dispatcher, must have all 
+     *  context mappings. 
+     *  TODO: why do we need one mapper per context ? 
+     */ 
+    private WebappServletMapper mapper = new WebappServletMapper(this);
 
+    private WebappHasRole realm = new WebappHasRole();
 
     /**
      * The merged context initialization parameters for this Context.
      */
-    private HashMap parameters = null;
-
-
-    /**
-     * The string manager for this package.
-     */
-    private static final StringManager sm =
-      StringManager.getManager("org.apache.coyote.servlet");
+    private HashMap parameters = new HashMap();
 
+    private ArrayList lifecycleListenersClassName = new ArrayList();
+    private ArrayList lifecycleListeners = new ArrayList();
 
     /**
-     * Base path.
+     * Base path - the directory root of the webapp
      */
     private String basePath = null;
 
-
     /**
      * Thread local mapping data.
      */
     private ThreadLocal localMappingData = new ThreadLocal();
 
-
     /**
      * Thread local URI message bytes.
      */
     private ThreadLocal localUriMB = new ThreadLocal();
 
-
     private String contextName = "";
     
     private Host host;
 
-    private SessionManager manager = new SessionManager();
+    CharsetMapper charsetMapper = new CharsetMapper();
 
-    // --------------------------------------------------------- Public Methods
+    String contextPath;
 
+    private WebappSessionManager manager = new WebappSessionManager();
 
-    /**
-     * Return the resources object that is mapped to a specified path.
-     * The path must begin with a "/" and is interpreted as relative to the
-     * current context root.
-     */
-//    public DirContext getResources() {
-//
-//        return context.getResources();
-//
-//    }
+    Repository repository;
+
+    HashMap filters = new HashMap();
 
+    private WebappFilterMapper webappFilterMapper = new WebappFilterMapper(this);
+    
+    CoyoteServletFacade facade = CoyoteServletFacade.getServletImpl();
 
     // ------------------------------------------------- ServletContext Methods
 
@@ -209,7 +195,7 @@
 
         ServletContextImpl child = null;
         try {
-            Host host = (Host) context.getParent();
+            Host host = (Host) this.getParent();
             String mapuri = uri;
             while (true) {
                 child = (ServletContextImpl) host.findChild(mapuri);
@@ -227,12 +213,12 @@
         if (child == null)
             return (null);
 
-        if (context.getCrossContext()) {
+        if (this.getCrossContext()) {
             // If crossContext is enabled, can always return the context
             return child.getServletContext();
-        } else if (child == context) {
+        } else if (child == this) {
             // Can still return the current context
-            return context.getServletContext();
+            return this.getServletContext();
         } else {
             // Nothing to return
             return (null);
@@ -244,7 +230,7 @@
      * Return the main path associated with this context.
      */
     public String getContextPath() {
-        return context.getPath();
+        return contextPath;
     }
     
 
@@ -255,11 +241,7 @@
      * @param name Name of the initialization parameter to retrieve
      */
     public String getInitParameter(final String name) {
-
-        mergeParameters();
-        synchronized (parameters) {
-            return ((String) parameters.get(name));
-        }
+        return ((String) parameters.get(name));
     }
 
 
@@ -268,12 +250,7 @@
      * empty enumeration if the context has no initialization parameters.
      */
     public Enumeration getInitParameterNames() {
-
-        mergeParameters();
-        synchronized (parameters) {
-           return (new Enumerator(parameters.keySet()));
-        }
-
+        return (new Enumerator(parameters.keySet()));
     }
 
 
@@ -313,8 +290,7 @@
         String extension = file.substring(period + 1);
         if (extension.length() < 1)
             return (null);
-        return (context.findMimeMapping(extension));
-
+        return contentTypes.getProperty(extension);
     }
 
 
@@ -331,12 +307,11 @@
             return (null);
 
         // Create and return a corresponding request dispatcher
-        ServletConfigImpl wrapper = (ServletConfigImpl) context.findChild(name);
+        ServletConfigImpl wrapper = (ServletConfigImpl) this.getServletConfig(name);
         if (wrapper == null)
             return (null);
         
         return new RequestDispatcherImpl(wrapper, null, null, null, null, name);
-
     }
 
 
@@ -347,17 +322,12 @@
      * @param path The path to the desired resource
      */
     public String getRealPath(String path) {
-
-        if (!context.isFilesystemBased())
-            return null;
-
         if (path == null) {
             return null;
         }
 
         File file = new File(basePath, path);
         return (file.getAbsolutePath());
-
     }
 
 
@@ -366,6 +336,7 @@
      * Return a <code>RequestDispatcher</code> instance that acts as a
      * wrapper for the resource at the given path.  The path must begin
      * with a "/" and is interpreted as relative to the current context root.
+
      *
      * @param path The path to the desired resource.
      */
@@ -412,7 +383,7 @@
         // Map the URI
         CharChunk uriCC = uriMB.getCharChunk();
         try {
-            uriCC.append(context.getPath(), 0, context.getPath().length());
+            uriCC.append(path, 0, path.length());
             /*
              * Ignore any trailing path params (separated by ';') for mapping
              * purposes
@@ -422,7 +393,7 @@
                 semicolon = -1;
             }
             uriCC.append(path, 0, semicolon > 0 ? semicolon : pos);
-            context.getMapper().map(uriMB, mappingData);
+            this.getMapper().map(uriMB, mappingData);
             if (mappingData.wrapper == null) {
                 return (null);
             }
@@ -479,33 +450,13 @@
         String libPath = "/WEB-INF/lib/";
         if ((path.startsWith(libPath)) && (path.endsWith(".jar"))) {
             File jarFile = null;
-            if (context.isFilesystemBased()) {
-                jarFile = new File(basePath, path);
-            } else {
-                jarFile = new File(context.getWorkPath(), path);
-            }
+            jarFile = new File(basePath, path);
             if (jarFile.exists()) {
                 return jarFile.toURL();
             } else {
                 return null;
             }
         } else {
-
-            // TODO(costin): File based resources !!
-            
-//            DirContext resources = context.getResources();
-//            if (resources != null) {
-//                String fullPath = context.getName() + path;
-//                String hostName = context.getParent().getName();
-//                try {
-//                    resources.lookup(path);
-//                    return new URL
-//                        ("jndi", "", 0, getJNDIUri(hostName, fullPath),
-//                         new DirContextURLStreamHandler(resources));
-//                } catch (Exception e) {
-//                    // Ignore
-//                }
-//            }
         }
 
         return (null);
@@ -546,7 +497,7 @@
             return (null);
 
         // TODO(costin): file based resources
-//        DirContext resources = context.getResources();
+//        DirContext resources = this.getResources();
 //        if (resources != null) {
 //            try {
 //                Object resource = resources.lookup(path);
@@ -582,35 +533,22 @@
         if (path == null)
             return (null);
 
-        // TODO(costin): file based resources
-//        DirContext resources = context.getResources();
-//        if (resources != null) {
-//            return (getResourcePathsInternal(resources, path));
-//        }
-        return (null);
-
+        File f = new File(basePath + path);
+        File[] files = f.listFiles();
+        if (files == null) return null;
+        
+        HashSet result = new HashSet();
+        for (int i=0; i < files.length; i++) {
+            if (files[i].isDirectory() ) {
+                result.add(files[i].getName() + "/");
+            } else {
+                result.add(files[i].getName());
+            }
+        }
+        return result;
     }
 
 
-    /**
-     * Internal implementation of getResourcesPath() logic.
-     *
-     * @param resources Directory context to search
-     * @param path Collection path
-     */
-//    private Set getResourcePathsInternal(DirContext resources, String path) {
-//
-//        HashSet set = new HashSet();
-//        try {
-//            listCollectionPaths(set, resources, path);
-//        } catch (NamingException e) {
-//            return (null);
-//        }
-//        //set.setLocked(true);
-//        return (set);
-//
-//    }
-
 
     /**
      * Return the name and version of the servlet container.
@@ -665,7 +603,7 @@
      */
     public void log(String message) {
 
-        context.getLogger().info(message);
+        this.getLogger().info(message);
 
     }
 
@@ -681,7 +619,7 @@
      */
     public void log(Exception exception, String message) {
         
-        context.getLogger().error(message, exception);
+        this.getLogger().error(message, exception);
 
     }
 
@@ -694,7 +632,7 @@
      */
     public void log(String message, Throwable throwable) {
         
-        context.getLogger().error(message, throwable);
+        this.getLogger().error(message, throwable);
 
     }
 
@@ -724,25 +662,28 @@
         }
 
         // Notify interested application event listeners
-        Object listeners[] = context.getApplicationEventListeners();
-        if ((listeners == null) || (listeners.length == 0))
+        List listeners = this.getApplicationEventListeners();
+        if (listeners.size() == 0)
             return;
-        ServletContextAttributeEvent event =
-          new ServletContextAttributeEvent(context.getServletContext(),
-                                            name, value);
-        for (int i = 0; i < listeners.length; i++) {
-            if (!(listeners[i] instanceof ServletContextAttributeListener))
+        ServletContextAttributeEvent event = null;
+        for (int i = 0; i < listeners.size(); i++) {
+            if (!(listeners.get(i) instanceof ServletContextAttributeListener))
                 continue;
             ServletContextAttributeListener listener =
-                (ServletContextAttributeListener) listeners[i];
+                (ServletContextAttributeListener) listeners.get(i);
             try {
-//                context.fireContainerEvent("beforeContextAttributeRemoved",
+//                this.fireContainerEvent("beforeContextAttributeRemoved",
 //                                           listener);
+                if (event == null) {
+                    event = new ServletContextAttributeEvent(this.getServletContext(),
+                            name, value);
+
+                }
                 listener.attributeRemoved(event);
-//                context.fireContainerEvent("afterContextAttributeRemoved",
+//                this.fireContainerEvent("afterContextAttributeRemoved",
 //                                           listener);
             } catch (Throwable t) {
-//                context.fireContainerEvent("afterContextAttributeRemoved",
+//                this.fireContainerEvent("afterContextAttributeRemoved",
 //                                           listener);
                 // FIXME - should we do anything besides log these?
                 log(sm.getString("applicationContext.attributeEvent"), t);
@@ -787,44 +728,46 @@
         }
 
         // Notify interested application event listeners
-        Object listeners[] = context.getApplicationEventListeners();
-        if ((listeners == null) || (listeners.length == 0))
+        List listeners = this.getApplicationEventListeners();
+        if (listeners.size() == 0)
             return;
         ServletContextAttributeEvent event = null;
-        if (replaced)
-            event =
-                new ServletContextAttributeEvent(context.getServletContext(),
-                                                 name, oldValue);
-        else
-            event =
-                new ServletContextAttributeEvent(context.getServletContext(),
-                                                 name, value);
-
-        for (int i = 0; i < listeners.length; i++) {
-            if (!(listeners[i] instanceof ServletContextAttributeListener))
+        for (int i = 0; i < listeners.size(); i++) {
+            if (!(listeners.get(i) instanceof ServletContextAttributeListener))
                 continue;
             ServletContextAttributeListener listener =
-                (ServletContextAttributeListener) listeners[i];
+                (ServletContextAttributeListener) listeners.get(i);
             try {
+                if (event == null) {
+                    if (replaced)
+                        event =
+                            new ServletContextAttributeEvent(this.getServletContext(),
+                                                             name, oldValue);
+                    else
+                        event =
+                            new ServletContextAttributeEvent(this.getServletContext(),
+                                                             name, value);
+                    
+                }
                 if (replaced) {
-//                    context.fireContainerEvent
+//                    this.fireContainerEvent
 //                        ("beforeContextAttributeReplaced", listener);
                     listener.attributeReplaced(event);
-//                    context.fireContainerEvent("afterContextAttributeReplaced",
+//                    this.fireContainerEvent("afterContextAttributeReplaced",
 //                                               listener);
                 } else {
-//                    context.fireContainerEvent("beforeContextAttributeAdded",
+//                    this.fireContainerEvent("beforeContextAttributeAdded",
 //                                               listener);
                     listener.attributeAdded(event);
-//                    context.fireContainerEvent("afterContextAttributeAdded",
+//                    this.fireContainerEvent("afterContextAttributeAdded",
 //                                               listener);
                 }
             } catch (Throwable t) {
 //                if (replaced)
-//                    context.fireContainerEvent("afterContextAttributeReplaced",
+//                    this.fireContainerEvent("afterContextAttributeReplaced",
 //                                               listener);
 //                else
-//                    context.fireContainerEvent("afterContextAttributeAdded",
+//                    this.fireContainerEvent("afterContextAttributeAdded",
 //                                               listener);
                 // FIXME - should we do anything besides log these?
                 log(sm.getString("applicationContext.attributeEvent"), t);
@@ -926,89 +869,17 @@
 
     }
 
-
-    /**
-     * Merge the context initialization parameters specified in the application
-     * deployment descriptor with the application parameters described in the
-     * server configuration, respecting the <code>override</code> property of
-     * the application parameters appropriately.
-     */
-    private void mergeParameters() {
-
-        if (parameters != null)
-            return;
-//        HashMap results = new HashMap();
-//        String names[] = context.findParameters();
-//        for (int i = 0; i < names.length; i++)
-//            results.put(names[i], context.findParameter(names[i]));
-//        ApplicationParameter params[] =
-//            context.findApplicationParameters();
-//        for (int i = 0; i < params.length; i++) {
-//            if (params[i].getOverride()) {
-//                if (results.get(params[i].getName()) == null)
-//                    results.put(params[i].getName(), params[i].getValue());
-//            } else {
-//                results.put(params[i].getName(), params[i].getValue());
-//            }
-//        }
-//        parameters = results;
-
-    }
-
-
-    /**
-     * List resource paths (recursively), and store all of them in the given
-     * Set.
-     */
-//    private static void listCollectionPaths
-//        (Set set, DirContext resources, String path)
-//        throws NamingException {
-//
-//        Enumeration childPaths = resources.listBindings(path);
-//        while (childPaths.hasMoreElements()) {
-//            Binding binding = (Binding) childPaths.nextElement();
-//            String name = binding.getName();
-//            StringBuffer childPath = new StringBuffer(path);
-//            if (!"/".equals(path) && !path.endsWith("/"))
-//                childPath.append("/");
-//            childPath.append(name);
-//            Object object = binding.getObject();
-//            if (object instanceof DirContext) {
-//                childPath.append("/");
-//            }
-//            set.add(childPath.toString());
-//        }
-//
-//    }
-
-
-    /**
-     * Get full path, based on the host name and the context path.
-     */
-//    private static String getJNDIUri(String hostName, String path) {
-//        if (!path.startsWith("/"))
-//            return "/" + hostName + "/" + path;
-//        else
-//            return "/" + hostName + path;
-//    }
-
-    CharsetMapper charsetMapper = new CharsetMapper();
-    String path;
-    
     public CharsetMapper getCharsetMapper() {
         return charsetMapper;
     }
 
-
-    public String getPath() {
-        return path;
-    }
-
-    void setPath(String path) {
-        this.path = path;
+    void setContextPath(String path) {
+        this.contextPath = path;
+        mapper.contextMapElement.name = path;
+        log = LogFactory.getLog("webapp." + path.replace("/", "."));
     }
     
-    public void setBasePath(String basePath) {
+    void setBasePath(String basePath) {
         this.basePath = basePath;        
     }
 
@@ -1016,13 +887,13 @@
         return basePath;
     }
 
-    public SessionManager getManager() {
+    public WebappSessionManager getManager() {
         return manager;
     }
 
 
-    public ApplicationAuthorization getRealm() {
-        return null;
+    public WebappHasRole getRealm() {
+        return realm;
     }
 
 
@@ -1041,13 +912,16 @@
     }
 
 
-    public Object[] getApplicationEventListeners() {
-        return null;
+    public List getApplicationEventListeners() {
+        return lifecycleListeners;
     }
 
+    public List getListenersClassName() {
+        return lifecycleListenersClassName;
+    }
 
     public Log getLogger() {
-        return null;
+        return log;
     }
 
 
@@ -1060,11 +934,16 @@
         return 0;
     }
 
+    HashMap servlets = new HashMap();
 
-    public ServletConfigImpl findChild(String jsp_servlet_name) {
-        return null;
+    public ServletConfigImpl getServletConfig(String jsp_servlet_name) {
+        return (ServletConfigImpl)servlets.get(jsp_servlet_name);
     }
 
+    public void addServletConfig(ServletConfigImpl servletConfig) {
+        servlets.put(servletConfig.getServletName(), servletConfig);
+        
+    }
 
     public boolean getPrivileged() {
         return false;
@@ -1074,44 +953,161 @@
         return true;
     }
 
-    private boolean isFilesystemBased() {
-        return true;
+    static Properties contentTypes=new Properties();
+    static {
+        initContentTypes();
+    }
+    // TODO: proper implementation
+    static void initContentTypes() {
+        contentTypes.put("xhtml", "text/html");
+        contentTypes.put("html", "text/html");
+        contentTypes.put("txt", "text/plain");
+        contentTypes.put("css", "text/css");
+        contentTypes.put("xul", "application/vnd.mozilla.xul+xml");
+    }
+    
+    public void addMimeType(String ext, String type) {
+        contentTypes.put(ext, type);
     }
 
-
-    private String findMimeMapping(String extension) {
-        return null;
+    public WebappServletMapper getMapper() {
+        return mapper;
+    }
+    
+    public WebappFilterMapper getFilterMapper() {
+        return webappFilterMapper ;
+    }
+    
+    public FilterConfigImpl getFilter(String name) {
+        return (FilterConfigImpl)filters.get(name);
     }
 
+    public void addFilter(String name, String className, Map initParams) {
+        FilterConfigImpl fc = new FilterConfigImpl(this);
+        fc.setFilterClass(className);
+        fc.setFilterName(name);
+        fc.setParameterMap(initParams);
+        filters.put(name, fc);
 
-    public void destroy() {
+        // Filters are added before mappings - if the WebappFilterMapper
+        // is replaced, it can get all the mappings.
+        try {
+            if (name.equals("_tomcat.FilterMapper")) {
+                Filter filter = fc.getFilter();
+                if (filter instanceof WebappFilterMapper) {
+                    webappFilterMapper = (WebappFilterMapper)filter;
+                }
+            }
+            if (name.equals("_tomcat.ServletMapper")) {
+                Filter filter = fc.getFilter();
+                if (filter instanceof WebappServletMapper) {
+                    mapper = (WebappServletMapper)filter;
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
-
-    public org.apache.tomcat.util.http.mapper.Mapper getMapper() {
-        return (mapper);
+    
+    public void initFilters() throws ServletException {
+        Iterator fI = getFilters().values().iterator();
+        while (fI.hasNext()) {
+            FilterConfigImpl fc = (FilterConfigImpl)fI.next();
+            try {
+                fc.getFilter(); // will triger init()
+            } catch (Throwable e) {
+                log.warn("Error initializing filter " + fc.getFilterName(), e);
+            } 
+            
+        }
+    }
+    
+    public void initListeners() throws ServletException {
+        Iterator fI = getListenersClassName().iterator();
+        while (fI.hasNext()) {
+            String listenerClass = (String)fI.next();
+            try {
+                Object l = 
+                    getClassLoader().loadClass(listenerClass).newInstance();
+                lifecycleListeners.add(l);
+            } catch (Throwable e) {
+                log.warn("Error initializing listener " + listenerClass, e);
+            } 
+            
+        }
     }
+    
+    public Map getFilters() {
+        return filters;
+    }
+    
 
+    public void setRepository(Repository repo) {
+        repository = repo;
+    }
+    
+    public ClassLoader getClassLoader() {
+        if( repository != null ) 
+            return repository.getClassLoader();
+        return this.getClass().getClassLoader();
+    }
 
-    public FilterMap[] findFilterMaps() {
-        return null;
+    public Map getContextParameters() {
+        return parameters;
     }
 
 
-    public FilterConfigImpl findFilterConfig(String filterName) {
-        return null;
-    }
+    public void init() throws ServletException {
+        String base = getBasePath();
+        
+        // create a class loader
+        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"));
+        setRepository(ctxRepo);
+        ClassLoader cl = ctxRepo.getClassLoader();
+
+        // Add default mappings.
+        ServletConfig fileS =
+            facade.createServletWrapper(this, "default", new DefaultServlet());
+        facade.addMapping("/", fileS);
 
+        WebXml webXml = new WebXml(this);
+        webXml.readWebXml(base);
 
-    public ClassLoader getClassLoader() {
-        return this.getClass().getClassLoader();
-    }
+        // TODO: read a simpler version of web.xml
 
+        // TODO: read the real web.xml
 
-    public Object[] getApplicationLifecycleListeners() {
-        return null;
+        facade.notifyAdd(this);
+        
+        initFilters();
+        initListeners();
     }
-
-    void setContextParameters(HashMap params) {
-        this.parameters = params;
+    
+    public void destroy() throws ServletException {
+        // destroy filters
+        Iterator fI = filters.values().iterator();
+        while(fI.hasNext()) {
+            FilterConfigImpl fc = (FilterConfigImpl) fI.next();
+            try {
+                fc.getFilter().destroy();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        // destroy servlets
+        fI = servlets.values().iterator();
+        while(fI.hasNext()) {
+            ServletConfigImpl fc = (ServletConfigImpl) fI.next();
+            try {
+                fc.destroy();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
     }
+
 }
+

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java Tue Jun 20 14:45:26 2006
@@ -28,6 +28,7 @@
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.TimeZone;
@@ -53,6 +54,7 @@
 
 import org.apache.coyote.ActionCode;
 import org.apache.coyote.servlet.util.Enumerator;
+import org.apache.coyote.servlet.util.MappingData;
 import org.apache.coyote.servlet.util.MessageReader;
 import org.apache.coyote.servlet.util.ParameterMap;
 import org.apache.coyote.servlet.util.RequestUtil;
@@ -65,7 +67,6 @@
 import org.apache.tomcat.util.http.FastHttpDateFormat;
 import org.apache.tomcat.util.http.Parameters;
 import org.apache.tomcat.util.http.ServerCookie;
-import org.apache.tomcat.util.http.mapper.MappingData;
 import org.apache.tomcat.util.res.StringManager;
 
 
@@ -80,6 +81,298 @@
 public class ServletRequestImpl
     implements HttpServletRequest {
 
+    /**
+     * The servlet context attribute under which we store the alternate
+     * deployment descriptor for this web application 
+     */
+    public static final String ALT_DD_ATTR = 
+        "org.apache.catalina.deploy.alt_dd";
+
+    /**
+     * The request attribute under which we store the array of X509Certificate
+     * objects representing the certificate chain presented by our client,
+     * if any.
+     */
+    public static final String CERTIFICATES_ATTR =
+        "javax.servlet.request.X509Certificate";
+
+    /**
+     * The request attribute under which we store the name of the cipher suite
+     * being used on an SSL connection (as an object of type
+     * java.lang.String).
+     */
+    public static final String CIPHER_SUITE_ATTR =
+        "javax.servlet.request.cipher_suite";
+
+
+    /**
+     * The servlet context attribute under which we store the class loader
+     * used for loading servlets (as an object of type java.lang.ClassLoader).
+     */
+    public static final String CLASS_LOADER_ATTR =
+        "org.apache.catalina.classloader";
+
+    /**
+     * Request dispatcher state.
+     */
+    public static final String DISPATCHER_TYPE_ATTR = 
+        "org.apache.catalina.core.DISPATCHER_TYPE";
+
+    /**
+     * Request dispatcher path.
+     */
+    public static final String DISPATCHER_REQUEST_PATH_ATTR = 
+        "org.apache.catalina.core.DISPATCHER_REQUEST_PATH";
+
+    /**
+     * The JNDI directory context which is associated with the context. This
+     * context can be used to manipulate static files.
+     */
+    public static final String RESOURCES_ATTR =
+        "org.apache.catalina.resources";
+
+
+    /**
+     * The servlet context attribute under which we store the class path
+     * for our application class loader (as an object of type String),
+     * delimited with the appropriate path delimiter for this platform.
+     */
+    public static final String CLASS_PATH_ATTR =
+        "org.apache.catalina.jsp_classpath";
+
+
+    /**
+     * The request attribute under which we forward a Java exception
+     * (as an object of type Throwable) to an error page.
+     */
+    public static final String EXCEPTION_ATTR =
+        "javax.servlet.error.exception";
+
+
+    /**
+     * The request attribute under which we forward the request URI
+     * (as an object of type String) of the page on which an error occurred.
+     */
+    public static final String EXCEPTION_PAGE_ATTR =
+        "javax.servlet.error.request_uri";
+
+
+    /**
+     * The request attribute under which we forward a Java exception type
+     * (as an object of type Class) to an error page.
+     */
+    public static final String EXCEPTION_TYPE_ATTR =
+        "javax.servlet.error.exception_type";
+
+
+    /**
+     * The request attribute under which we forward an HTTP status message
+     * (as an object of type STring) to an error page.
+     */
+    public static final String ERROR_MESSAGE_ATTR =
+        "javax.servlet.error.message";
+
+
+    /**
+     * The request attribute under which the Invoker servlet will store
+     * the invoking servlet path, if it was used to execute a servlet
+     * indirectly instead of through a servlet mapping.
+     */
+    public static final String INVOKED_ATTR =
+        "org.apache.catalina.INVOKED";
+
+
+    /**
+     * The request attribute under which we expose the value of the
+     * <code>&lt;jsp-file&gt;</code> value associated with this servlet,
+     * if any.
+     */
+    public static final String JSP_FILE_ATTR =
+        "org.apache.catalina.jsp_file";
+
+
+    /**
+     * The request attribute under which we store the key size being used for
+     * this SSL connection (as an object of type java.lang.Integer).
+     */
+    public static final String KEY_SIZE_ATTR =
+        "javax.servlet.request.key_size";
+
+    /**
+     * The request attribute under which we store the session id being used
+     * for this SSL connection (as an object of type java.lang.String).
+     */
+    public static final String SSL_SESSION_ID_ATTR =
+        "javax.servlet.request.ssl_session";
+
+
+    /**
+     * The servlet context attribute under which the managed bean Registry
+     * will be stored for privileged contexts (if enabled).
+     */
+    public static final String MBEAN_REGISTRY_ATTR =
+        "org.apache.catalina.Registry";
+
+
+    /**
+     * The servlet context attribute under which the MBeanServer will be stored
+     * for privileged contexts (if enabled).
+     */
+    public static final String MBEAN_SERVER_ATTR =
+        "org.apache.catalina.MBeanServer";
+
+
+    /**
+     * The request attribute under which we store the servlet name on a
+     * named dispatcher request.
+     */
+    public static final String NAMED_DISPATCHER_ATTR =
+        "org.apache.catalina.NAMED";
+
+
+    /**
+     * The request attribute under which the request URI of the included
+     * servlet is stored on an included dispatcher request.
+     */
+    public static final String INCLUDE_REQUEST_URI_ATTR =
+        "javax.servlet.include.request_uri";
+
+
+    /**
+     * The request attribute under which the context path of the included
+     * servlet is stored on an included dispatcher request.
+     */
+    public static final String INCLUDE_CONTEXT_PATH_ATTR =
+        "javax.servlet.include.context_path";
+
+
+    /**
+     * The request attribute under which the path info of the included
+     * servlet is stored on an included dispatcher request.
+     */
+    public static final String INCLUDE_PATH_INFO_ATTR =
+        "javax.servlet.include.path_info";
+
+
+    /**
+     * The request attribute under which the servlet path of the included
+     * servlet is stored on an included dispatcher request.
+     */
+    public static final String INCLUDE_SERVLET_PATH_ATTR =
+        "javax.servlet.include.servlet_path";
+
+
+    /**
+     * The request attribute under which the query string of the included
+     * servlet is stored on an included dispatcher request.
+     */
+    public static final String INCLUDE_QUERY_STRING_ATTR =
+        "javax.servlet.include.query_string";
+
+
+    /**
+     * The request attribute under which the original request URI is stored
+     * on an forwarded dispatcher request.
+     */
+    public static final String FORWARD_REQUEST_URI_ATTR =
+        "javax.servlet.forward.request_uri";
+    
+    
+    /**
+     * The request attribute under which the original context path is stored
+     * on an forwarded dispatcher request.
+     */
+    public static final String FORWARD_CONTEXT_PATH_ATTR =
+        "javax.servlet.forward.context_path";
+
+
+    /**
+     * The request attribute under which the original path info is stored
+     * on an forwarded dispatcher request.
+     */
+    public static final String FORWARD_PATH_INFO_ATTR =
+        "javax.servlet.forward.path_info";
+
+
+    /**
+     * The request attribute under which the original servlet path is stored
+     * on an forwarded dispatcher request.
+     */
+    public static final String FORWARD_SERVLET_PATH_ATTR =
+        "javax.servlet.forward.servlet_path";
+
+
+    /**
+     * The request attribute under which the original query string is stored
+     * on an forwarded dispatcher request.
+     */
+    public static final String FORWARD_QUERY_STRING_ATTR =
+        "javax.servlet.forward.query_string";
+
+
+    /**
+     * The request attribute under which we forward a servlet name to
+     * an error page.
+     */
+    public static final String SERVLET_NAME_ATTR =
+        "javax.servlet.error.servlet_name";
+
+    
+    /**
+     * The name of the cookie used to pass the session identifier back
+     * and forth with the client.
+     */
+    public static final String SESSION_COOKIE_NAME = "JSESSIONID";
+
+
+    /**
+     * The name of the path parameter used to pass the session identifier
+     * back and forth with the client.
+     */
+    public static final String SESSION_PARAMETER_NAME = "jsessionid";
+
+
+    /**
+     * The servlet context attribute under which we store a flag used
+     * to mark this request as having been processed by the SSIServlet.
+     * We do this because of the pathInfo mangling happening when using
+     * the CGIServlet in conjunction with the SSI servlet. (value stored
+     * as an object of type String)
+     */
+     public static final String SSI_FLAG_ATTR =
+         "org.apache.catalina.ssi.SSIServlet";
+
+
+    /**
+     * The request attribute under which we forward an HTTP status code
+     * (as an object of type Integer) to an error page.
+     */
+    public static final String STATUS_CODE_ATTR =
+        "javax.servlet.error.status_code";
+
+
+    /**
+     * The subject under which the AccessControlContext is running.
+     */
+    public static final String SUBJECT_ATTR =
+        "javax.security.auth.subject";
+
+    
+    /**
+     * The servlet context attribute under which we record the set of
+     * welcome files (as an object of type String[]) for this application.
+     */
+    public static final String WELCOME_FILES_ATTR =
+        "org.apache.catalina.WELCOME_FILES";
+
+
+    /**
+     * The servlet context attribute under which we store a temporary
+     * working directory (as an object of type File) for use by servlets
+     * within this web application.
+     */
+    public static final String WORK_DIR_ATTR =
+        "javax.servlet.context.tempdir";
 
     // ----------------------------------------------------------- Constructors
 
@@ -439,7 +732,7 @@
     /**
      * Filter chain associated with the request.
      */
-    protected FilterChain filterChain = null;
+    protected FilterChainImpl filterChain = new FilterChainImpl();
 
     /**
      * Get filter chain associated with the request.
@@ -448,15 +741,6 @@
         return (this.filterChain);
     }
 
-    /**
-     * Set filter chain associated with the request.
-     * 
-     * @param filterChain new filter chain
-     */
-    public void setFilterChain(FilterChain filterChain) {
-        this.filterChain = filterChain;
-    }
-
 
 //    /**
 //     * Return the Host within which this Request is being processed.
@@ -786,11 +1070,11 @@
      */
     public Object getAttribute(String name) {
 
-        if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
+        if (name.equals(ServletRequestImpl.DISPATCHER_TYPE_ATTR)) {
             return (dispatcherType == null) 
                 ? REQUEST_INTEGER
                 : dispatcherType;
-        } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
+        } else if (name.equals(ServletRequestImpl.DISPATCHER_REQUEST_PATH_ATTR)) {
             return (requestDispatcherPath == null) 
                 ? getRequestPathMB().toString()
                 : requestDispatcherPath.toString();
@@ -807,21 +1091,21 @@
         if( isSSLAttribute(name) ) {
             coyoteRequest.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE, 
                                  coyoteRequest);
-            attr = coyoteRequest.getAttribute(Globals.CERTIFICATES_ATTR);
+            attr = coyoteRequest.getAttribute(ServletRequestImpl.CERTIFICATES_ATTR);
             if( attr != null) {
-                attributes.put(Globals.CERTIFICATES_ATTR, attr);
+                attributes.put(ServletRequestImpl.CERTIFICATES_ATTR, attr);
             }
-            attr = coyoteRequest.getAttribute(Globals.CIPHER_SUITE_ATTR);
+            attr = coyoteRequest.getAttribute(ServletRequestImpl.CIPHER_SUITE_ATTR);
             if(attr != null) {
-                attributes.put(Globals.CIPHER_SUITE_ATTR, attr);
+                attributes.put(ServletRequestImpl.CIPHER_SUITE_ATTR, attr);
             }
-            attr = coyoteRequest.getAttribute(Globals.KEY_SIZE_ATTR);
+            attr = coyoteRequest.getAttribute(ServletRequestImpl.KEY_SIZE_ATTR);
             if(attr != null) {
-                attributes.put(Globals.KEY_SIZE_ATTR, attr);
+                attributes.put(ServletRequestImpl.KEY_SIZE_ATTR, attr);
             }
-            attr = coyoteRequest.getAttribute(Globals.SSL_SESSION_ID_ATTR);
+            attr = coyoteRequest.getAttribute(ServletRequestImpl.SSL_SESSION_ID_ATTR);
             if(attr != null) {
-                attributes.put(Globals.SSL_SESSION_ID_ATTR, attr);
+                attributes.put(ServletRequestImpl.SSL_SESSION_ID_ATTR, attr);
             }
             attr = attributes.get(name);
         }
@@ -833,10 +1117,10 @@
      * Test if a given name is one of the special Servlet-spec SSL attributes.
      */
     static boolean isSSLAttribute(String name) {
-        return Globals.CERTIFICATES_ATTR.equals(name) ||
-            Globals.CIPHER_SUITE_ATTR.equals(name) ||
-            Globals.KEY_SIZE_ATTR.equals(name)  ||
-            Globals.SSL_SESSION_ID_ATTR.equals(name);
+        return ServletRequestImpl.CERTIFICATES_ATTR.equals(name) ||
+            ServletRequestImpl.CIPHER_SUITE_ATTR.equals(name) ||
+            ServletRequestImpl.KEY_SIZE_ATTR.equals(name)  ||
+            ServletRequestImpl.SSL_SESSION_ID_ATTR.equals(name);
     }
 
     /**
@@ -845,7 +1129,7 @@
      */
     public Enumeration getAttributeNames() {
         if (isSecure()) {
-            getAttribute(Globals.CERTIFICATES_ATTR);
+            getAttribute(ServletRequestImpl.CERTIFICATES_ATTR);
         }
         return new Enumerator(attributes.keySet(), true);
     }
@@ -1173,7 +1457,7 @@
             return (context.getRequestDispatcher(path));
 
         // Convert a request-relative path to a context-relative one
-        String servletPath = (String) getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR);
+        String servletPath = (String) getAttribute(ServletRequestImpl.INCLUDE_SERVLET_PATH_ATTR);
         if (servletPath == null)
             servletPath = getServletPath();
 
@@ -1257,23 +1541,26 @@
         }
 
         // Notify interested application event listeners
-        Object listeners[] = context.getApplicationEventListeners();
-        if ((listeners == null) || (listeners.length == 0))
+        List listeners = context.getApplicationEventListeners();
+        if (listeners.size() == 0)
             return;
-        ServletRequestAttributeEvent event =
-          new ServletRequestAttributeEvent(context.getServletContext(),
-                                           getRequest(), name, value);
-        for (int i = 0; i < listeners.length; i++) {
-            if (!(listeners[i] instanceof ServletRequestAttributeListener))
+        ServletRequestAttributeEvent event = null;
+        for (int i = 0; i < listeners.size(); i++) {
+            if (!(listeners.get(i) instanceof ServletRequestAttributeListener))
                 continue;
             ServletRequestAttributeListener listener =
-                (ServletRequestAttributeListener) listeners[i];
+                (ServletRequestAttributeListener) listeners.get(i);
             try {
+                if (event == null) {
+                    event = 
+                        new ServletRequestAttributeEvent(context.getServletContext(),
+                            getRequest(), name, value);
+                }
                 listener.attributeRemoved(event);
             } catch (Throwable t) {
                 context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
                 // Error valve will pick this execption up and display it to user
-                attributes.put( Globals.EXCEPTION_ATTR, t );
+                attributes.put( ServletRequestImpl.EXCEPTION_ATTR, t );
             }
         }
     }
@@ -1298,10 +1585,10 @@
             return;
         }
 
-        if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
+        if (name.equals(ServletRequestImpl.DISPATCHER_TYPE_ATTR)) {
             dispatcherType = value;
             return;
-        } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
+        } else if (name.equals(ServletRequestImpl.DISPATCHER_REQUEST_PATH_ATTR)) {
             requestDispatcherPath = value;
             return;
         }
@@ -1327,25 +1614,27 @@
         }
         
         // Notify interested application event listeners
-        Object listeners[] = context.getApplicationEventListeners();
-        if ((listeners == null) || (listeners.length == 0))
+        List listeners = context.getApplicationEventListeners();
+        if (listeners.size() == 0)
             return;
         ServletRequestAttributeEvent event = null;
-        if (replaced)
-            event =
-                new ServletRequestAttributeEvent(context.getServletContext(),
-                                                 getRequest(), name, oldValue);
-        else
-            event =
-                new ServletRequestAttributeEvent(context.getServletContext(),
-                                                 getRequest(), name, value);
 
-        for (int i = 0; i < listeners.length; i++) {
-            if (!(listeners[i] instanceof ServletRequestAttributeListener))
+        for (int i = 0; i < listeners.size(); i++) {
+            if (!(listeners.get(i) instanceof ServletRequestAttributeListener))
                 continue;
             ServletRequestAttributeListener listener =
-                (ServletRequestAttributeListener) listeners[i];
+                (ServletRequestAttributeListener) listeners.get(i);
             try {
+                if (event == null) {
+                    if (replaced)
+                        event =
+                            new ServletRequestAttributeEvent(context.getServletContext(),
+                                                             getRequest(), name, oldValue);
+                    else
+                        event =
+                            new ServletRequestAttributeEvent(context.getServletContext(),
+                                                             getRequest(), name, value);
+                }
                 if (replaced) {
                     listener.attributeReplaced(event);
                 } else {
@@ -1354,7 +1643,7 @@
             } catch (Throwable t) {
                 context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
                 // Error valve will pick this execption up and display it to user
-                attributes.put( Globals.EXCEPTION_ATTR, t );
+                attributes.put( ServletRequestImpl.EXCEPTION_ATTR, t );
             }
         }
     }
@@ -1661,7 +1950,7 @@
                 subject.getPrincipals().add(principal);         
             }
             if (session != null){
-                session.setAttribute(Globals.SUBJECT_ATTR, subject);
+                session.setAttribute(ServletRequestImpl.SUBJECT_ATTR, subject);
             }
         } 
 
@@ -2034,7 +2323,7 @@
             return (false);
         if (context == null)
             return (false);
-        SessionManager manager = context.getManager();
+        WebappSessionManager manager = context.getManager();
         if (manager == null)
             return (false);
         HttpSessionImpl session = null;
@@ -2066,7 +2355,7 @@
         // Identify the Realm we will use for checking role assignmenets
         if (context == null)
             return (false);
-        ApplicationAuthorization realm = context.getRealm();
+        WebappHasRole realm = context.getRealm();
         if (realm == null)
             return (false);
 
@@ -2140,7 +2429,7 @@
             return (session);
 
         // Return the requested session if it exists and is valid
-        SessionManager manager = null;
+        WebappSessionManager manager = null;
         if (context != null)
             manager = context.getManager();
         if (manager == null)
@@ -2182,7 +2471,7 @@
         // Creating a new session cookie based on that session
         if ((session != null) && (getContext() != null)
                && getContext().getCookies()) {
-            Cookie cookie = new Cookie(Globals.SESSION_COOKIE_NAME,
+            Cookie cookie = new Cookie(ServletRequestImpl.SESSION_COOKIE_NAME,
                                        session.getIdInternal());
             configureSessionCookie(cookie);
             response.addCookie(cookie);

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestWrapperImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestWrapperImpl.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestWrapperImpl.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestWrapperImpl.java Tue Jun 20 14:45:26 2006
@@ -67,11 +67,11 @@
      * The set of attribute names that are special for request dispatchers.
      */
     protected static final String specials[] =
-    { Globals.INCLUDE_REQUEST_URI_ATTR, Globals.INCLUDE_CONTEXT_PATH_ATTR,
-      Globals.INCLUDE_SERVLET_PATH_ATTR, Globals.INCLUDE_PATH_INFO_ATTR,
-      Globals.INCLUDE_QUERY_STRING_ATTR, Globals.FORWARD_REQUEST_URI_ATTR, 
-      Globals.FORWARD_CONTEXT_PATH_ATTR, Globals.FORWARD_SERVLET_PATH_ATTR, 
-      Globals.FORWARD_PATH_INFO_ATTR, Globals.FORWARD_QUERY_STRING_ATTR };
+    { ServletRequestImpl.INCLUDE_REQUEST_URI_ATTR, ServletRequestImpl.INCLUDE_CONTEXT_PATH_ATTR,
+      ServletRequestImpl.INCLUDE_SERVLET_PATH_ATTR, ServletRequestImpl.INCLUDE_PATH_INFO_ATTR,
+      ServletRequestImpl.INCLUDE_QUERY_STRING_ATTR, ServletRequestImpl.FORWARD_REQUEST_URI_ATTR, 
+      ServletRequestImpl.FORWARD_CONTEXT_PATH_ATTR, ServletRequestImpl.FORWARD_SERVLET_PATH_ATTR, 
+      ServletRequestImpl.FORWARD_PATH_INFO_ATTR, ServletRequestImpl.FORWARD_QUERY_STRING_ATTR };
 
 
     /**
@@ -206,9 +206,9 @@
      */
     public Object getAttribute(String name) {
 
-        if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
+        if (name.equals(ServletRequestImpl.DISPATCHER_TYPE_ATTR)) {
             return dispatcherType;
-        } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
+        } else if (name.equals(ServletRequestImpl.DISPATCHER_REQUEST_PATH_ATTR)) {
             if ( requestDispatcherPath != null ){
                 return requestDispatcherPath.toString();
             } else {
@@ -266,10 +266,10 @@
      */
     public void setAttribute(String name, Object value) {
 
-        if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
+        if (name.equals(ServletRequestImpl.DISPATCHER_TYPE_ATTR)) {
             dispatcherType = value;
             return;
-        } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
+        } else if (name.equals(ServletRequestImpl.DISPATCHER_REQUEST_PATH_ATTR)) {
             requestDispatcherPath = value;
             return;
         }
@@ -300,7 +300,7 @@
 
         // Convert a request-relative path to a context-relative one
         String servletPath = 
-            (String) getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR);
+            (String) getAttribute(ServletRequestImpl.INCLUDE_SERVLET_PATH_ATTR);
         if (servletPath == null)
             servletPath = getServletPath();
 
@@ -563,7 +563,7 @@
                 return (false);
             if (context == null)
                 return (false);
-            SessionManager manager = context.getManager();
+            WebappSessionManager manager = context.getManager();
             if (manager == null)
                 return (false);
             HttpSessionImpl session = null;
@@ -673,9 +673,9 @@
         super.setRequest(request);
 
         // Initialize the attributes for this request
-        dispatcherType = request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
+        dispatcherType = request.getAttribute(ServletRequestImpl.DISPATCHER_TYPE_ATTR);
         requestDispatcherPath = 
-            request.getAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR);
+            request.getAttribute(ServletRequestImpl.DISPATCHER_REQUEST_PATH_ATTR);
 
         // Initialize the path elements for this request
         contextPath = request.getContextPath();

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java?rev=415818&r1=415817&r2=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java Tue Jun 20 14:45:26 2006
@@ -1307,7 +1307,7 @@
         if (serverPort != urlPort)
             return (false);
 
-        String contextPath = request.getContext().getPath();
+        String contextPath = request.getContext().getContextPath();
         if (contextPath != null) {
             String file = url.getFile();
             if ((file == null) || !file.startsWith(contextPath))

Added: tomcat/sandbox/java/org/apache/coyote/servlet/WebappContextMapper.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/WebappContextMapper.java?rev=415818&view=auto
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/WebappContextMapper.java (added)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/WebappContextMapper.java Tue Jun 20 14:45:26 2006
@@ -0,0 +1,282 @@
+package org.apache.coyote.servlet;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.coyote.servlet.WebappServletMapper.ContextMapElement;
+import org.apache.coyote.servlet.util.MappingData;
+import org.apache.tomcat.util.buf.CharChunk;
+import org.apache.tomcat.util.buf.MessageBytes;
+
+/** 
+ * 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.
+ * 
+ * You can extend and override the mapper in MapperAdapter.
+ */
+public class WebappContextMapper implements Filter {
+    
+    // TODO: compare toString + lowercase + hash with 
+    //  list[] + ignore case and sorted list and ignore case and also
+    //  a tree. 
+    // For the simple container - most of the time only the default host will
+    // be used.
+    
+    /** String lowercase(hostname) -> Host object
+     *  All aliases are included.
+     */
+    Map hostMap = new HashMap();
+    
+    // If no host or alias matches
+    Host defaultHost = new Host();
+    
+    private static org.apache.commons.logging.Log log=
+        org.apache.commons.logging.LogFactory.getLog( WebappContextMapper.class );
+
+
+    public WebappContextMapper() {
+        defaultHost.setName("");
+        hostMap.put("", defaultHost);
+    }
+        /**
+     * Add a new host to the mapper.
+     *
+     * @param name Virtual host name
+     * @param host Host object
+     */
+    public void addHost(String name, String[] aliases, Host host) {
+        hostMap.put(name.toLowerCase(), host);
+        for (int i = 0; i < aliases.length; i++) {
+            hostMap.put(aliases[i].toLowerCase(), host);
+        }
+    }
+    
+    public Iterator getHosts() {
+        return hostMap.values().iterator();
+    }
+
+    /**
+     * Remove a host from the mapper.
+     *
+     * @param name Virtual host name
+     */
+    public void removeHost(String name) {
+        Host host = findHost(name);
+        if (host == null) {
+            return;
+        }
+        Iterator hostIt = hostMap.entrySet().iterator();
+        while( hostIt.hasNext()) {
+            Map.Entry entry = (Map.Entry)hostIt.next();
+            if(entry.getValue() == host) {
+                hostIt.remove();
+            }
+        }
+    }
+
+    /**
+     * Add a new Context to an existing Host.
+     *
+     * @param hostName Virtual host name this context belongs to
+     * @param contextPath Context path
+     * @param context Context object
+     * @param welcomeResources Welcome files defined for this context
+     * @param resources Static resources of the context
+     */
+    public void addContext
+        (String hostName, ServletContextImpl context,
+         String[] welcomeResources, File resources) 
+        throws ServletException
+    {
+        Host host = findHost(hostName);
+        if (host == null) throw new ServletException("Host not found");
+        String path = context.getContextPath();
+        int slashCount = WebappServletMapper.slashCount(path);
+        synchronized (host) {
+                ContextMapElement[] contexts = host.contexts;
+                // Update nesting
+                if (slashCount > host.nesting) {
+                    host.nesting = slashCount;
+                }
+                ContextMapElement[] newContexts = new ContextMapElement[contexts.length + 1];
+                ContextMapElement newContext = context.getMapper().contextMapElement;
+                newContext.name = path;
+                newContext.object = context;
+                newContext.welcomeResources = welcomeResources;
+                newContext.resources = resources;
+                if (WebappServletMapper.insertMap(contexts, newContexts, newContext)) {
+                    host.contexts = newContexts;
+                }
+            }
+    }
+
+
+    /**
+     * Remove a context from an existing host.
+     *
+     * @param hostName Virtual host name this context belongs to
+     * @param path Context path
+     */
+    public void removeContext(String hostName, String path) 
+            throws ServletException {
+        Host host = findHost(hostName);
+        if (host == null) throw new ServletException("Host not found");
+        if (host.name.equals(hostName)) {
+            synchronized (host) {
+                ContextMapElement[] contexts = host.contexts;
+                if( contexts.length == 0 ){
+                    return;
+                }
+                ContextMapElement[] newContexts = new ContextMapElement[contexts.length - 1];
+                if (WebappServletMapper.removeMap(contexts, newContexts, path)) {
+                    host.contexts = newContexts;
+                    // Recalculate nesting
+                    host.nesting = 0;
+                    for (int i = 0; i < newContexts.length; i++) {
+                        int slashCount = WebappServletMapper.slashCount(newContexts[i].name);
+                        if (slashCount > host.nesting) {
+                            host.nesting = slashCount;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Map the specified host name and URI, mutating the given mapping data.
+     *
+     * @param host Virtual host name
+     * @param uri URI
+     * @param mappingData This structure will contain the result of the mapping
+     *                    operation
+     */
+    public void mapContext(MessageBytes host, MessageBytes uri,
+                           MappingData mappingData)
+        throws Exception {
+
+        if (host.isNull()) {
+            host.getCharChunk().append(defaultHost.getName());
+        }
+        host.toChars();
+        uri.toChars();
+        internalMap(host.getCharChunk(), uri.getCharChunk(), mappingData);
+
+    }
+
+    // -------------------------------------------------------- Private Methods
+
+    /** Find a the host. 
+     *  Override for corner cases ( wildcards, huge number of hosts, 
+     *  special patterns, dynamic behavior ).
+     *  
+     */
+    public Host findHost(String hostName) {
+        Host host = null;
+        if(hostMap.size() > 0 ) {
+            // don't bother if we only have default host
+            host = (Host)hostMap.get(hostName.toLowerCase());
+        }
+        if (host == null) host = defaultHost;
+        return host;
+    }
+    
+    /**
+     * Map the specified URI.
+     */
+    private final void internalMap(CharChunk host, CharChunk uri,
+                                   MappingData mappingData)
+        throws Exception {
+
+        uri.setLimit(-1);
+
+        // Virtual host mapping
+        if (mappingData.host == null) {
+            mappingData.host = findHost(host.toString());
+        }
+        if (mappingData.host == null) {
+            throw new ServletException("Host not found");
+        }
+
+        ContextMapElement[] contexts = null;
+        ContextMapElement context = null;
+        int nesting = 0;
+
+        contexts = ((Host)mappingData.host).contexts;
+        nesting = ((Host)mappingData.host).nesting;
+
+        // Context mapping
+        if (mappingData.context == null) {
+            int pos = WebappServletMapper.find(contexts, uri);
+            if (pos == -1) {
+                return;
+            }
+
+            int lastSlash = -1;
+            int uriEnd = uri.getEnd();
+            int length = -1;
+            boolean found = false;
+            while (pos >= 0) {
+                if (uri.startsWith(contexts[pos].name)) {
+                    length = contexts[pos].name.length();
+                    if (uri.getLength() == length) {
+                        found = true;
+                        break;
+                    } else if (uri.startsWithIgnoreCase("/", length)) {
+                        found = true;
+                        break;
+                    }
+                }
+                if (lastSlash == -1) {
+                    lastSlash = WebappServletMapper.nthSlash(uri, nesting + 1);
+                } else {
+                    lastSlash = WebappServletMapper.lastSlash(uri);
+                }
+                uri.setEnd(lastSlash);
+                pos = WebappServletMapper.find(contexts, uri);
+            }
+            uri.setEnd(uriEnd);
+
+            if (!found) {
+                if (contexts[0].name.equals("")) {
+                    context = contexts[0];
+                }
+            } else {
+                context = contexts[pos];
+            }
+            if (context != null) {
+                mappingData.context = context.object;
+                mappingData.contextPath.setString(context.name);
+            }
+        }
+    }
+
+    
+    public void init(FilterConfig filterConfig) throws ServletException {
+    }
+    
+    public void doFilter(ServletRequest request, 
+                         ServletResponse response, 
+                         FilterChain chain) 
+            throws IOException, ServletException {
+    }
+    
+    public void destroy() {
+    }
+
+
+}
\ No newline at end of file

Copied: tomcat/sandbox/java/org/apache/coyote/servlet/WebappFilterMapper.java (from r410655, tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationFilterFactory.java)
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/WebappFilterMapper.java?p2=tomcat/sandbox/java/org/apache/coyote/servlet/WebappFilterMapper.java&p1=tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationFilterFactory.java&r1=410655&r2=415818&rev=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationFilterFactory.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/WebappFilterMapper.java Tue Jun 20 14:45:26 2006
@@ -18,26 +18,36 @@
 package org.apache.coyote.servlet;
 
 
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
 import javax.servlet.Servlet;
+import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 
-//import org.apache.catalina.Globals;
+import org.apache.coyote.servlet.util.RequestUtil;
 
 /**
- * Factory for the creation and caching of Filters and creationg 
- * of Filter Chains.
+ * First filter after the context and servlet are mapped. It will add 
+ * web.xml-defined filters. 
  * 
- * costin: This is another mapping - done in RequestDispatcher.
+ * costin: This is another mapping - done in RequestDispatcher or initial 
+ * mapping.
  * Also: StandardHostValve - sets attribute for error pages,
  *   StandardWrapperValve - mapping per invocation
  *
  * @author Greg Murray
  * @author Remy Maucherat
- * @version $Revision: 1.0
  */
-
-public final class ApplicationFilterFactory {
+public class WebappFilterMapper implements Filter {
 
 
     // -------------------------------------------------------------- Constants
@@ -64,36 +74,36 @@
     public static final String DISPATCHER_REQUEST_PATH_ATTR = 
         "org.apache.catalina.core.DISPATCHER_REQUEST_PATH";
 
-    private static final SecurityManager securityManager = 
-        System.getSecurityManager();
-
-    private static ApplicationFilterFactory factory = null;;
-
 
     // ----------------------------------------------------------- Constructors
+    ServletContextImpl servletContext;
 
+    public WebappFilterMapper() {
+    }
 
-    /*
-     * Prevent instanciation outside of the getInstanceMethod().
-     */
-    private ApplicationFilterFactory() {
+    public WebappFilterMapper(ServletContextImpl impl) {
+        servletContext = impl;
     }
 
+    public void setServletContext(ServletContextImpl sc) {
+        servletContext = sc;
+    }
 
     // --------------------------------------------------------- Public Methods
 
-
-    /**
-     * Return the fqctory instance.
-     */
-    public static ApplicationFilterFactory getInstance() {
-        if (factory == null) {
-            factory = new ApplicationFilterFactory();
-        }
-        return factory;
+    ArrayList filterMaps = new ArrayList();
+    
+    public void addMapping(String filterName, 
+                           String url, 
+                           String servletName, 
+                           String type[]) {
+        FilterMap map = new FilterMap();
+        map.setURLPattern(url);
+        map.setFilterName(filterName);
+        map.setServletName(servletName);
+        filterMaps.add(map);
     }
 
-
     /**
      * Construct and return a FilterChain implementation that will wrap the
      * execution of the specified servlet instance.  If we should not execute
@@ -102,8 +112,13 @@
      * @param request The servlet request we are processing
      * @param servlet The servlet instance to be wrapped
      */
-    public FilterChainImpl createFilterChain
-        (ServletRequest request, ServletConfigImpl wrapper, Servlet servlet) {
+    public FilterChainImpl createFilterChain(ServletRequest request, 
+                                             ServletConfigImpl wrapper, 
+                                             Servlet servlet) {
+
+        // If there is no servlet to execute, return null
+        if (servlet == null)
+            return (null);
 
         // get the dispatcher type
         int dispatcher = -1; 
@@ -122,19 +137,13 @@
         HttpServletRequest hreq = null;
         if (request instanceof HttpServletRequest) 
             hreq = (HttpServletRequest)request;
-        // If there is no servlet to execute, return null
-        if (servlet == null)
-            return (null);
 
         // Create and initialize a filter chain object
         FilterChainImpl filterChain = null;
-        if ((securityManager == null) && (request instanceof ServletRequestImpl)) {
+        if ((request instanceof ServletRequestImpl)) {
             ServletRequestImpl req = (ServletRequestImpl) request;
             filterChain = (FilterChainImpl) req.getFilterChain();
-            if (filterChain == null) {
-                filterChain = new FilterChainImpl();
-                req.setFilterChain(filterChain);
-            }
+            filterChain.release();
         } else {
             // Security: Do not recycle
             filterChain = new FilterChainImpl();
@@ -142,15 +151,8 @@
 
         filterChain.setServlet(servlet);
 
-//        filterChain.setSupport
-//            (((ServletWrapper)wrapper).getInstanceSupport());
-
-        // Acquire the filter mappings for this Context
-        ServletContextImpl context = (ServletContextImpl) wrapper.getParent();
-        FilterMap filterMaps[] = context.findFilterMaps();
-
         // If there are no filter mappings, we are done
-        if ((filterMaps == null) || (filterMaps.length == 0))
+        if ((filterMaps.size() == 0))
             return (filterChain);
 
         // Acquire the information we will need to match filter mappings
@@ -158,17 +160,25 @@
 
         int n = 0;
 
+        // TODO(costin): optimize: separate in 2 lists, one for url-mapped, one for
+        // servlet-name. Maybe even separate list for dispatcher and 
+        // non-dispatcher
+        
+        // TODO(costin): optimize: set the FilterConfig in the FilterMap, to 
+        // avoid second hash lookup
+        
         // Add the relevant path-mapped filters to this filter chain
-        for (int i = 0; i < filterMaps.length; i++) {
-            if (!matchDispatcher(filterMaps[i] ,dispatcher)) {
+        for (int i = 0; i < filterMaps.size(); i++) {
+            FilterMap filterMap = (FilterMap)filterMaps.get(i);
+            if (!matchDispatcher(filterMap ,dispatcher)) {
                 continue;
             }
-            if (!matchFiltersURL(filterMaps[i], requestPath))
+            if (!matchFiltersURL(filterMap, requestPath))
                 continue;
-            FilterConfigImpl filterConfig = (FilterConfigImpl)
-                context.findFilterConfig(filterMaps[i].getFilterName());
+            FilterConfigImpl filterConfig = 
+                servletContext.getFilter(filterMap.getFilterName());
             if (filterConfig == null) {
-                ;       // FIXME - log configuration problem
+                // FIXME - log configuration problem
                 continue;
             }
             filterChain.addFilter(filterConfig);
@@ -176,14 +186,15 @@
         }
 
         // Add filters that match on servlet name second
-        for (int i = 0; i < filterMaps.length; i++) {
-            if (!matchDispatcher(filterMaps[i] ,dispatcher)) {
+        for (int i = 0; i < filterMaps.size(); i++) {
+            FilterMap filterMap = (FilterMap)filterMaps.get(i);
+            if (!matchDispatcher(filterMap ,dispatcher)) {
                 continue;
             }
-            if (!matchFiltersServlet(filterMaps[i], servletName))
+            if (!matchFiltersServlet(filterMap, servletName))
                 continue;
-            FilterConfigImpl filterConfig = (FilterConfigImpl)
-                context.findFilterConfig(filterMaps[i].getFilterName());
+            FilterConfigImpl filterConfig = 
+                servletContext.getFilter(filterMap.getFilterName());
             if (filterConfig == null) {
                 ;       // FIXME - log configuration problem
                 continue;
@@ -343,5 +354,178 @@
         return false;
     }
 
+
+    // -------------------- Map elements -----------------------
+    
+    public static class FilterMap implements Serializable {
+
+
+        // ------------------------------------------------------------- Properties
+
+
+        /**
+         * The name of this filter to be executed when this mapping matches
+         * a particular request.
+         */
+        
+        public static final int ERROR = 1;
+        public static final int FORWARD = 2;
+        public static final int FORWARD_ERROR =3;  
+        public static final int INCLUDE = 4;
+        public static final int INCLUDE_ERROR  = 5;
+        public static final int INCLUDE_ERROR_FORWARD  =6;
+        public static final int INCLUDE_FORWARD  = 7;
+        public static final int REQUEST = 8;
+        public static final int REQUEST_ERROR = 9;
+        public static final int REQUEST_ERROR_FORWARD = 10;
+        public static final int REQUEST_ERROR_FORWARD_INCLUDE = 11;
+        public static final int REQUEST_ERROR_INCLUDE = 12;
+        public static final int REQUEST_FORWARD = 13;
+        public static final int REQUEST_INCLUDE = 14;
+        public static final int REQUEST_FORWARD_INCLUDE= 15;
+        
+        // represents nothing having been set. This will be seen 
+        // as equal to a REQUEST
+        private static final int NOT_SET = -1;
+        
+        private int dispatcherMapping=NOT_SET;
+        
+        private String filterName = null;    
+
+        /**
+         * The URL pattern this mapping matches.
+         */
+        private String urlPattern = null;
+
+        /**
+         * The servlet name this mapping matches.
+         */
+        private String servletName = null;
+
+
+
+        public String getFilterName() {
+            return (this.filterName);
+        }
+
+        public void setFilterName(String filterName) {
+            this.filterName = filterName;
+        }
+
+
+        public String getServletName() {
+            return (this.servletName);
+        }
+
+        public void setServletName(String servletName) {
+            this.servletName = servletName;
+        }
+
+
+        public String getURLPattern() {
+            return (this.urlPattern);
+        }
+
+        public void setURLPattern(String urlPattern) {
+            this.urlPattern = RequestUtil.URLDecode(urlPattern);
+        }
+        
+        /**
+         *
+         * This method will be used to set the current state of the FilterMap
+         * representing the state of when filters should be applied:
+         *
+         *        ERROR
+         *        FORWARD
+         *        FORWARD_ERROR
+         *        INCLUDE
+         *        INCLUDE_ERROR
+         *        INCLUDE_ERROR_FORWARD
+         *        REQUEST
+         *        REQUEST_ERROR
+         *        REQUEST_ERROR_INCLUDE
+         *        REQUEST_ERROR_FORWARD_INCLUDE
+         *        REQUEST_INCLUDE
+         *        REQUEST_FORWARD,
+         *        REQUEST_FORWARD_INCLUDE
+         *
+         */
+        public void setDispatcher(String dispatcherString) {
+            String dispatcher = dispatcherString.toUpperCase();
+            
+            if (dispatcher.equals("FORWARD")) {
+
+                // apply FORWARD to the global dispatcherMapping.
+                switch (dispatcherMapping) {
+                    case NOT_SET  :  dispatcherMapping = FORWARD; break;
+                    case ERROR : dispatcherMapping = FORWARD_ERROR; break;
+                    case INCLUDE  :  dispatcherMapping = INCLUDE_FORWARD; break;
+                    case INCLUDE_ERROR  :  dispatcherMapping = INCLUDE_ERROR_FORWARD; break;
+                    case REQUEST : dispatcherMapping = REQUEST_FORWARD; break;
+                    case REQUEST_ERROR : dispatcherMapping = REQUEST_ERROR_FORWARD; break;
+                    case REQUEST_ERROR_INCLUDE : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
+                    case REQUEST_INCLUDE : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break;
+                }
+            } else if (dispatcher.equals("INCLUDE")) {
+                // apply INCLUDE to the global dispatcherMapping.
+                switch (dispatcherMapping) {
+                    case NOT_SET  :  dispatcherMapping = INCLUDE; break;
+                    case ERROR : dispatcherMapping = INCLUDE_ERROR; break;
+                    case FORWARD  :  dispatcherMapping = INCLUDE_FORWARD; break;
+                    case FORWARD_ERROR  :  dispatcherMapping = INCLUDE_ERROR_FORWARD; break;
+                    case REQUEST : dispatcherMapping = REQUEST_INCLUDE; break;
+                    case REQUEST_ERROR : dispatcherMapping = REQUEST_ERROR_INCLUDE; break;
+                    case REQUEST_ERROR_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
+                    case REQUEST_FORWARD : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break;
+                }
+            } else if (dispatcher.equals("REQUEST")) {
+                // apply REQUEST to the global dispatcherMapping.
+                switch (dispatcherMapping) {
+                    case NOT_SET  :  dispatcherMapping = REQUEST; break;
+                    case ERROR : dispatcherMapping = REQUEST_ERROR; break;
+                    case FORWARD  :  dispatcherMapping = REQUEST_FORWARD; break;
+                    case FORWARD_ERROR  :  dispatcherMapping = REQUEST_ERROR_FORWARD; break;
+                    case INCLUDE  :  dispatcherMapping = REQUEST_INCLUDE; break;
+                    case INCLUDE_ERROR  :  dispatcherMapping = REQUEST_ERROR_INCLUDE; break;
+                    case INCLUDE_FORWARD : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break;
+                    case INCLUDE_ERROR_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
+                }
+            }  else if (dispatcher.equals("ERROR")) {
+                // apply ERROR to the global dispatcherMapping.
+                switch (dispatcherMapping) {
+                    case NOT_SET  :  dispatcherMapping = ERROR; break;
+                    case FORWARD  :  dispatcherMapping = FORWARD_ERROR; break;
+                    case INCLUDE  :  dispatcherMapping = INCLUDE_ERROR; break;
+                    case INCLUDE_FORWARD : dispatcherMapping = INCLUDE_ERROR_FORWARD; break;
+                    case REQUEST : dispatcherMapping = REQUEST_ERROR; break;
+                    case REQUEST_INCLUDE : dispatcherMapping = REQUEST_ERROR_INCLUDE; break;
+                    case REQUEST_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD; break;
+                    case REQUEST_FORWARD_INCLUDE : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
+                }
+            }
+        }
+        
+        public int getDispatcherMapping() {
+            // per the SRV.6.2.5 absence of any dispatcher elements is
+            // equivelant to a REQUEST value
+            if (dispatcherMapping == NOT_SET) return REQUEST;
+            else return dispatcherMapping; 
+        }
+
+    }
+
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+    }
+
+
+    public void doFilter(ServletRequest request, ServletResponse response, 
+                         FilterChain chain) 
+            throws IOException, ServletException {
+    }
+
+
+    public void destroy() {
+    }
 
 }

Copied: tomcat/sandbox/java/org/apache/coyote/servlet/WebappHasRole.java (from r410655, tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationAuthorization.java)
URL: http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/WebappHasRole.java?p2=tomcat/sandbox/java/org/apache/coyote/servlet/WebappHasRole.java&p1=tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationAuthorization.java&r1=410655&r2=415818&rev=415818&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ApplicationAuthorization.java (original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/WebappHasRole.java Tue Jun 20 14:45:26 2006
@@ -4,18 +4,20 @@
 
 import java.security.Principal;
 
-/** Subset of Realm. 
- * 
- * Authentication and web.xml-defined authorization are done in a filter ( valve ), 
- * this is needed for the programmatic callbacks.
- * 
+/** 
+ * Callback to check roles. By default, matching username and role is used,
+ * should be overriden.
  * 
+ * An authentication filter should use group if available or user matches.
  * 
  * @author Costin Manolache
  */
-public class ApplicationAuthorization {
+public class WebappHasRole {
     
     public boolean hasRole(Principal userPrincipal, String realRole) {
+        if (realRole != null && realRole.equals(userPrincipal.getName())) {
+            return true;
+        }
         return false;
     }
 



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