tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject svn commit: r793797 - in /tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite: ./ webxml/
Date Tue, 14 Jul 2009 05:38:06 GMT
Author: costin
Date: Tue Jul 14 05:38:02 2009
New Revision: 793797

URL: http://svn.apache.org/viewvc?rev=793797&view=rev
Log:
Some initial implementations for the 3.0 dynamic registration methods. Moving back web.xml
config to separate package - with annotations requiring scanning of all files it needs to
be done at deploy time - so it'll be better to just load a .ser file at startup.

Added:
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/ServletContextConfig.java
      - copied, changed from r793382, tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextConfig.java
Removed:
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextConfig.java
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/WebAnnotation.java
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/WebResourceCollectionData.java
Modified:
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/WebappFilterMapper.java
    tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/WebXml.java

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java?rev=793797&r1=793796&r2=793797&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java Tue
Jul 14 05:38:02 2009
@@ -19,13 +19,19 @@
 
 
 import java.util.ArrayList;
+import java.util.EnumSet;
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
+import javax.servlet.DispatcherType;
 import javax.servlet.Filter;
 import javax.servlet.FilterConfig;
+import javax.servlet.FilterRegistration;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
+import javax.servlet.FilterRegistration.Dynamic;
 
 import org.apache.tomcat.servlets.util.Enumerator;
 
@@ -41,29 +47,37 @@
  * 
  * @see ServletConfigImpl
  */
-public final class FilterConfigImpl implements FilterConfig {
+public final class FilterConfigImpl implements FilterConfig, FilterRegistration {
 
+    DynamicFilterRegistration dynamic = new DynamicFilterRegistration();
+    
     public FilterConfigImpl(ServletContextImpl context) {
-        this.context = context;
+        this.ctx = context;
     }
     
-    private ServletContextImpl context = null;
+    boolean asyncSupported;
+    
+    private ServletContextImpl ctx = null;
 
     /**
      * The application Filter we are configured for.
      */
     private transient Filter filter = null;
-
+    
+    String descryption;
+    
     private String filterName;
 
-    private String filterClass;
+    private String filterClassName;
+
+    Map<String, String> initParams;
 
-    private Map<String, String> initParams;
+    private Class<? extends Filter> filterClass;
 
     public void setData(String filterName, String filterClass,
                         Map<String, String> params) {
         this.filterName = filterName;
-        this.filterClass = filterClass;
+        this.filterClassName = filterClass;
         this.initParams = params;
     }
     
@@ -75,6 +89,11 @@
         return filterName;
     }
 
+    public void setFilterClass(Class<? extends Filter> filterClass2) {
+        this.filterClass = filterClass2;
+    }
+    
+
     public String getInitParameter(String name) {
         if (initParams == null) return null;
         return initParams.get(name);
@@ -96,20 +115,20 @@
      * Return the ServletContext of our associated web application.
      */
     public ServletContext getServletContext() {
-        return context;
+        return ctx;
     }
 
     /**
      * Return the application Filter we are configured for.
      */
-    public Filter getFilter() throws ClassCastException, ClassNotFoundException,
+    public Filter createFilter() throws ClassCastException, ClassNotFoundException,
         IllegalAccessException, InstantiationException, ServletException {
 
         // Return the existing filter instance, if any
         if (filter != null)
             return filter;
 
-        ClassLoader classLoader = context.getClassLoader();
+        ClassLoader classLoader = ctx.getClassLoader();
 
         ClassLoader oldCtxClassLoader =
             Thread.currentThread().getContextClassLoader();
@@ -117,14 +136,23 @@
             Thread.currentThread().setContextClassLoader(classLoader);
         }
         try {
-            Class clazz = classLoader.loadClass(filterClass);
-            this.filter = (Filter) clazz.newInstance();
+            if (filterClass == null) {
+                filterClass = (Class<? extends Filter>) classLoader.loadClass(filterClassName);
+            }
+            this.filter = (Filter) filterClass.newInstance();
         } finally {        
             if (classLoader != oldCtxClassLoader) {
                 Thread.currentThread().setContextClassLoader(oldCtxClassLoader);
             }
         }
         
+        // TODO: resource injection
+        
+        return filter;
+    }
+    
+    public Filter getFilter() throws ClassCastException, ClassNotFoundException, IllegalAccessException,
InstantiationException, ServletException {
+        Filter filter = createFilter();
         filter.init(this);
         return (this.filter);
     }
@@ -140,4 +168,105 @@
         }
         this.filter = null;
      }
+
+    @Override
+    public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes,
+                                          boolean isMatchAfter,
+                                          String... servletNames) {
+        if (ctx.startDone) {
+            // Use the context method instead of the servlet API to 
+            // add mappings after context init.
+            throw new IllegalStateException();
+        }
+        ArrayList<String> dispatchers = new ArrayList<String>();
+        for (DispatcherType dt: dispatcherTypes) {
+            dispatchers.add(dt.name());
+        }
+        for (String servletName: servletNames) {
+            ctx.getFilterMapper().addMapping(getFilterName(),
+                    null, servletName, (String[]) dispatchers.toArray(), isMatchAfter);
+        }
+    }
+
+    @Override
+    public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes,
+                                         boolean isMatchAfter,
+                                         String... urlPatterns) {
+        if (ctx.startDone) {
+            // Use the context method instead of the servlet API to 
+            // add mappings after context init.
+            throw new IllegalStateException();
+        }
+        ArrayList<String> dispatchers = new ArrayList<String>();
+        for (DispatcherType dt: dispatcherTypes) {
+            dispatchers.add(dt.name());
+        }
+        for (String url: urlPatterns) {
+            ctx.getFilterMapper().addMapping(getFilterName(),
+                    url, null, (String[]) dispatchers.toArray(), isMatchAfter);
+        }
+    }
+
+    @Override
+    public boolean setInitParameter(String name, String value)
+            throws IllegalArgumentException, IllegalStateException {
+        return ServletContextImpl.setInitParameter(ctx, initParams, 
+                name, value);
+    }
+
+    @Override
+    public Set<String> setInitParameters(Map<String, String> initParameters)
+    throws IllegalArgumentException, IllegalStateException {
+        return ServletContextImpl.setInitParameters(ctx, initParams, 
+                initParameters);
+    }
+    
+    public Dynamic getDynamic() {
+        return dynamic;
+    }
+    
+    public class DynamicFilterRegistration implements Dynamic {
+
+        @Override
+        public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes,
+                                              boolean isMatchAfter,
+                                              String... servletNames) {
+            FilterConfigImpl.this.addMappingForServletNames(dispatcherTypes, isMatchAfter,
servletNames);
+        }
+
+        @Override
+        public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes,
+                                             boolean isMatchAfter,
+                                             String... urlPatterns) {
+            FilterConfigImpl.this.addMappingForUrlPatterns(dispatcherTypes, isMatchAfter,
urlPatterns);
+        }
+
+        @Override
+        public boolean setInitParameter(String name, String value)
+                throws IllegalArgumentException, IllegalStateException {
+            return ServletContextImpl.setInitParameter(ctx, initParams, 
+                    name, value);
+        }
+
+        @Override
+        public Set<String> setInitParameters(Map<String, String> initParameters)
+                throws IllegalArgumentException, IllegalStateException {
+            return ServletContextImpl.setInitParameters(ctx, initParams, 
+                    initParameters);
+        }
+
+        @Override
+        public void setAsyncSupported(boolean isAsyncSupported)
+                throws IllegalStateException {
+            asyncSupported = isAsyncSupported;
+        }
+
+        @Override
+        public void setDescription(String description)
+                throws IllegalStateException {
+            FilterConfigImpl.this.descryption = description;
+        }
+    }
+
+    
 }

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java?rev=793797&r1=793796&r2=793797&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java Tue
Jul 14 05:38:02 2009
@@ -23,6 +23,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 import java.util.Stack;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -31,6 +32,7 @@
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
+import javax.servlet.ServletRegistration;
 import javax.servlet.SingleThreadModel;
 import javax.servlet.UnavailableException;
 
@@ -48,7 +50,12 @@
  * @author Craig R. McClanahan
  * @author Remy Maucherat
  */
-public class ServletConfigImpl implements ServletConfig {
+@SuppressWarnings("deprecation")
+public class ServletConfigImpl implements ServletConfig, ServletRegistration {
+    
+    ServletDynamicRegistration dynamic = new ServletDynamicRegistration();
+    
+    protected boolean asyncSupported;
     
     private static Logger log=
         Logger.getLogger(ServletConfigImpl.class.getName());
@@ -60,10 +67,10 @@
     //    public static final String SINGLE_THREADED_PROXY =
     //             "org.apache.tomcat.servlets.jsp.SingleThreadedProxyServlet";
 
-
+    protected String description;
     protected Map<String, String> initParams = new HashMap<String, String>();
     protected String servletName;
-    protected String servletClass;
+    protected String servletClassName;
     protected String jspFile;
     protected int loadOnStartup = -1;
     protected String runAs;
@@ -89,7 +96,7 @@
      */
     private transient boolean unloading = false;
 
-    private Class classClass = null;
+    private Class servletClass = null;
 
     // Support for SingleThreaded
     /**
@@ -113,7 +120,7 @@
     public ServletConfigImpl(ServletContextImpl ctx, String name, 
                              String classname) {
         this.servletName = name;
-        this.servletClass = classname;
+        this.servletClassName = classname;
         this.ctx = ctx;
         ctx.facade.notifyAdd(this);
     }
@@ -183,7 +190,7 @@
      * Return the fully qualified servlet class name for this servlet.
      */
     public String getServletClass() {
-        return servletClass;
+        return servletClassName;
     }
 
     /**
@@ -368,9 +375,12 @@
         }
     }
 
-    private Servlet newInstance() throws ServletException {
-        String actualClass = servletClass;
+    public Servlet newInstance() throws ServletException {
+        String actualClass = servletClassName;
 
+        if (instance != null) {
+            return instance;
+        }
         if (actualClass == null) {
             // No explicit name. Try to use the framework
             if (jspFile != null) {
@@ -378,8 +388,8 @@
                 // Named JSPs can be handled by a servlet or by the mapper.
                 Servlet res = (Servlet) ctx.getObjectManager().get("filetemplate-servlet");
                 if (res != null) {
-                    classClass = res.getClass();
-                    actualClass = classClass.getName();
+                    servletClass = res.getClass();
+                    actualClass = servletClass.getName();
                     initParams.put("jsp-file", jspFile);
                     return res;
                 } else {
@@ -396,8 +406,8 @@
                 Servlet res = (Servlet) ctx.getObjectManager().get( servletName +
                         "-servlet");
                 if (res != null) {
-                    classClass = res.getClass();
-                    actualClass = classClass.getName();
+                    servletClass = res.getClass();
+                    actualClass = servletClass.getName();
                     return res;
                 }
             }
@@ -407,7 +417,7 @@
         }
             
         
-        if (classClass == null) {
+        if (servletClass == null) {
             // set classClass
             loadClass(actualClass);
         }
@@ -424,14 +434,14 @@
         
         // the jsp proxy is replaced by the web.xml processor
         
-        if (classClass == null) {
+        if (servletClass == null) {
             unavailable(null);
             throw new UnavailableException("ClassNotFound: " + actualClass);
         }
         
         // Instantiate and initialize an instance of the servlet class itself
         try {
-            return (Servlet) classClass.newInstance();
+            return (Servlet) servletClass.newInstance();
         } catch (ClassCastException e) {
             unavailable(null);
             throw new UnavailableException("ClassCast: (Servlet)" + 
@@ -509,9 +519,9 @@
         
         // Load the specified servlet class from the appropriate class loader
         try {
-            classClass = classLoader.loadClass(actualClass);
+            servletClass = classLoader.loadClass(actualClass);
         } catch (ClassNotFoundException e) {
-            classClass = null;
+            servletClass = null;
         }
     }
 
@@ -526,7 +536,7 @@
         }
         sb.append("Servlet[");
         sb.append(getServletName()).append(" ");
-        sb.append(servletClass);
+        sb.append(servletClassName);
         if (jspFile != null) {
             sb.append(" jsp=").append(jspFile);
         }
@@ -652,9 +662,7 @@
      * @param name Name of the initialization parameter to retrieve
      */
     public String getInitParameter(String name) {
-
-        return (String)initParams.get(name);
-
+        return initParams.get(name);
     }
 
 
@@ -663,11 +671,9 @@
      * servlet.  If none are defined, an empty Enumeration is returned.
      */
     public Enumeration getInitParameterNames() {
-
         synchronized (initParams) {
             return (new Enumerator(initParams.keySet()));
         }
-
     }
 
 
@@ -805,5 +811,63 @@
       this.loadOnStartup = loadOnStartup;
     }
 
+    @Override
+    public Set<String> addMapping(String... urlPatterns) {
+        if (ctx.startDone) {
+            // Use the context method instead of the servlet API to 
+            // add mappings after context init.
+            throw new IllegalStateException();
+        }
+        Set<String> failed = new HashSet<String>();
+        for (String url: urlPatterns) {
+            if (url == null) {
+                throw new IllegalArgumentException();
+            }
+            if (ctx.contextConfig.servletMapping.get(url) != null) {
+                failed.add(url);
+            } else {
+                ctx.contextConfig.servletMapping.put(url, getServletName());
+                ctx.addMapping(url, this);
+            }
+        }
+        return failed;
+    }
 
+    @Override
+    public boolean setInitParameter(String name, String value)
+            throws IllegalArgumentException, IllegalStateException {
+        return ServletContextImpl.setInitParameter(ctx, initParams, 
+                name, value);
+    }
+
+    @Override
+    public Set<String> setInitParameters(Map<String, String> initParameters)
+            throws IllegalArgumentException, IllegalStateException {
+        return ServletContextImpl.setInitParameters(ctx, initParams, 
+                initParameters);
+    }
+
+    public Dynamic getDynamic() {
+        return dynamic;
+    }
+    
+    class ServletDynamicRegistration implements Dynamic {
+
+        @Override
+        public void setAsyncSupported(boolean isAsyncSupported)
+                throws IllegalStateException {
+            asyncSupported = isAsyncSupported;
+        }
+
+        @Override
+        public void setDescription(String description)
+                throws IllegalStateException {
+            ServletConfigImpl.this.description = description;
+        }
+        
+    }
+
+    public void setServletClass(Class<? extends Servlet> servletClass2) {
+        servletClass = servletClass2;
+    }
 }

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java?rev=793797&r1=793796&r2=793797&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java Tue
Jul 14 05:38:02 2009
@@ -37,9 +37,11 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.servlet.DispatcherType;
 import javax.servlet.Filter;
 import javax.servlet.FilterRegistration;
 import javax.servlet.RequestDispatcher;
@@ -58,9 +60,10 @@
 
 import org.apache.tomcat.addons.UserSessionManager;
 import org.apache.tomcat.integration.ObjectManager;
-import org.apache.tomcat.lite.ServletContextConfig.FilterData;
-import org.apache.tomcat.lite.ServletContextConfig.FilterMappingData;
-import org.apache.tomcat.lite.ServletContextConfig.ServletData;
+import org.apache.tomcat.lite.webxml.ServletContextConfig;
+import org.apache.tomcat.lite.webxml.ServletContextConfig.FilterData;
+import org.apache.tomcat.lite.webxml.ServletContextConfig.FilterMappingData;
+import org.apache.tomcat.lite.webxml.ServletContextConfig.ServletData;
 import org.apache.tomcat.servlets.util.Enumerator;
 import org.apache.tomcat.servlets.util.RequestUtil;
 import org.apache.tomcat.servlets.util.UrlUtils;
@@ -144,6 +147,11 @@
 
     private String hostname;
 
+
+    boolean initDone = false;
+
+    boolean startDone = false;
+    
     // ------------------------------------------------- ServletContext Methods
     public ServletContextImpl() {
     }
@@ -836,13 +844,6 @@
         }
     }
     
-    public void addFilter(String filterName, String filterClass, 
-                          Map params) {
-        FilterConfigImpl fc = new FilterConfigImpl(this);
-        fc.setData(filterName, filterClass, params);
-        filters.put(filterName, fc);
-    }
-    
     public void initFilters() throws ServletException {
         Iterator fI = getFilters().values().iterator();
         while (fI.hasNext()) {
@@ -856,6 +857,7 @@
             
         }
     }
+    
     public void initServlets() throws ServletException {
         Iterator fI = getServletConfigs().values().iterator();
         Map/*<Integer, List<ServletConfigImpl>>*/ onStartup = 
@@ -915,6 +917,8 @@
         getMapper().addWrapper(getMapper().contextMapElement, path, wrapper);
     }
     
+    
+    
     public void setWelcomeFiles(String[] name) {
       getMapper().contextMapElement.welcomeResources = name;
     }
@@ -1010,12 +1014,13 @@
       sc.setConfig(params);
       addServletConfig(sc);
     }
-    
+
+    @Override
     public javax.servlet.Registration.Dynamic addServlet(String servletName, Servlet servlet)
{
       ServletConfigImpl sc = new ServletConfigImpl(this, servletName, null);
       sc.setServlet(servlet);
       addServletConfig(sc);
-      return null;
+      return sc.getDynamic();
     }
     
     public void addServletSec(String serlvetName, String runAs, Map roles) {
@@ -1027,7 +1032,7 @@
     public void addFilterMapping(String path, String filterName, 
                                  String[] dispatcher) {
       getFilterMapper().addMapping(filterName, 
-          path, null, dispatcher);
+          path, null, dispatcher, true);
       
     }
 
@@ -1036,11 +1041,9 @@
                                         String[] dispatcher) {
       getFilterMapper().addMapping(filterName, 
           null, servlet, 
-          dispatcher);      
+          dispatcher, true);      
     }
     
-    boolean initDone = false;
-    
     /**
      * Called from TomcatLite.init(), required before start.
      * 
@@ -1167,6 +1170,9 @@
 
 
     public void start() throws ServletException {
+        if (startDone) {
+            return;
+        }
         String base = getBasePath();
         
         ArrayList urls = getClasspath(new File(base + "/WEB-INF/lib"),
@@ -1205,6 +1211,7 @@
                 event = new ServletContextEvent(this);
             }
             try {
+                // May add servlets/filters
                 listener.contextInitialized(event);
             } catch (Throwable t) {
                 log.log(Level.WARNING, "Context.init() contextInitialized() error:", t);
@@ -1214,6 +1221,8 @@
         
         initFilters();
         initServlets();
+        
+        startDone = true;
     }
 
     public UserSessionManager getManager() {
@@ -1392,57 +1401,151 @@
    public void setSessionTrackingModes(EnumSet<SessionTrackingMode> sessionTrackingModes)
{
    }
 
+   public void addFilter(String filterName, String filterClass, 
+                         Map params) {
+       FilterConfigImpl fc = new FilterConfigImpl(this);
+       fc.setData(filterName, filterClass, params);
+       filters.put(filterName, fc);
+   }
+   
    @Override
    public Dynamic addFilter(String filterName, String className) {
-       return null;
+       FilterConfigImpl fc = new FilterConfigImpl(this);
+       fc.setData(filterName, className, new HashMap());
+       filters.put(filterName, fc);
+       return fc.getDynamic();
    }
 
    @Override
    public Dynamic addFilter(String filterName, Filter filter) {
-       return null;
+       FilterConfigImpl fc = new FilterConfigImpl(this);
+       fc.setData(filterName, null, new HashMap());
+       fc.setFilter(filter);
+       filters.put(filterName, fc);
+       return fc.getDynamic();
    }
 
    @Override
    public Dynamic addFilter(String filterName, Class<? extends Filter> filterClass)
{
-       return null;
+       FilterConfigImpl fc = new FilterConfigImpl(this);
+       fc.setData(filterName, null, new HashMap());
+       fc.setFilterClass(filterClass);
+       filters.put(filterName, fc);
+       return fc.getDynamic();
    }
 
    @Override
    public javax.servlet.Registration.Dynamic addServlet(String servletName,
                                                         String className) {
-       return null;
+       ServletConfigImpl sc = new ServletConfigImpl(this, servletName, className);
+       addServletConfig(sc);
+       return sc.getDynamic();
    }
 
    @Override
-   public javax.servlet.Registration.Dynamic addServlet(
-                                                        String servletName,
+   public javax.servlet.Registration.Dynamic addServlet(String servletName,
                                                         Class<? extends Servlet> servletClass)
{
-       return null;
+       ServletConfigImpl sc = new ServletConfigImpl(this, servletName, servletClass.getName());
+       sc.setServletClass(servletClass);
+       addServletConfig(sc);
+       return sc.getDynamic();
    }
 
+   // That's tricky - this filter will have no name. We need to generate one 
+   // because our code relies on names.
+   AtomicInteger autoName = new AtomicInteger();
+   
    @Override
    public <T extends Filter> T createFilter(Class<T> c) throws ServletException
{
-       return null;
+       FilterConfigImpl fc = new FilterConfigImpl(this);
+       String filterName = "_tomcat_auto_filter_" + autoName.incrementAndGet();
+       fc.setData(filterName, null, new HashMap());
+       fc.setFilterClass(c);
+       filters.put(filterName, fc);
+
+       try {
+           return (T) fc.createFilter();
+       } catch (ClassCastException e) {
+           throw new ServletException(e);
+       } catch (ClassNotFoundException e) {
+           throw new ServletException(e);
+       } catch (IllegalAccessException e) {
+           throw new ServletException(e);
+       } catch (InstantiationException e) {
+           throw new ServletException(e);
+       }
    }
 
    @Override
    public <T extends Servlet> T createServlet(Class<T> c) throws ServletException
{
-       return null;
+       String filterName = "_tomcat_auto_servlet_" + autoName.incrementAndGet();
+       ServletConfigImpl fc = new ServletConfigImpl(this, filterName, null);
+       fc.setServletClass(c);
+       servlets.put(filterName, fc);
+
+       try {
+           return (T) fc.newInstance();
+       } catch (ClassCastException e) {
+           throw new ServletException(e);
+       }
    }
 
    @Override
    public FilterRegistration findFilterRegistration(String filterName) {
-       return null;
+       return filters.get(filterName);
    }
 
    @Override
    public ServletRegistration findServletRegistration(String servletName) {
-       return null;
+       return servlets.get(servletName);
    }
-
+   
    @Override
    public boolean setInitParameter(String name, String value) {
-       return false;
+       HashMap<String, String> params = contextConfig.contextParam;
+       return setInitParameter(this, params, name, value);
+   }
+   
+   static Set<String> setInitParameters(ServletContextImpl ctx, 
+           Map<String, String> params,
+           Map<String, String> initParameters)
+           throws IllegalArgumentException, IllegalStateException {
+       if (ctx.startDone) {
+           throw new IllegalStateException();
+       }
+       Set<String> result = new HashSet<String>();
+       for (String name: initParameters.keySet()) {
+           String value = initParameters.get(name);
+           if (name == null || value == null) {
+               throw new IllegalArgumentException();
+           }
+           if (!setInitParameter(ctx, params, name, value)) {
+               result.add(name);
+           }
+       }
+       return result;
+   }   
+
+   /**
+    * true if the context initialization parameter with the given name and value was set
successfully on this ServletContext, and false if it was not set because this ServletContext
already contains a context initialization parameter with a matching name
+    * Throws:
+    * java.lang.IllegalStateException - if this ServletContext has already been initialized
+    */
+   static boolean setInitParameter(ServletContextImpl ctx, Map<String, String> params,

+                                   String name, String value) {
+       if (name == null || value == null) {
+           throw new IllegalArgumentException();
+       }
+       if (ctx.startDone) {
+           throw new IllegalStateException();
+       }
+       String oldValue = params.get(name);
+       if (oldValue != null) {
+           return false;
+       } else {
+           params.put(name, value);
+           return true;
+       }
    }
 }
 

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java?rev=793797&r1=793796&r2=793797&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java
(original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java
Tue Jul 14 05:38:02 2009
@@ -1,5 +1,5 @@
 /*
- * ontentLicensed to the Apache Software Foundation (ASF) under one or more
+ * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/WebappFilterMapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/WebappFilterMapper.java?rev=793797&r1=793796&r2=793797&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/WebappFilterMapper.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/WebappFilterMapper.java Tue
Jul 14 05:38:02 2009
@@ -94,12 +94,16 @@
     public void addMapping(String filterName, 
                            String url, 
                            String servletName, 
-                           String type[]) {
+                           String type[], boolean isMatchAfter) {
         FilterMap map = new FilterMap();
         map.setURLPattern(url);
         map.setFilterName(filterName);
         map.setServletName(servletName);
-        filterMaps.add(map);
+        if (isMatchAfter) {
+            filterMaps.add(map);
+        } else {
+            filterMaps.add(0, map);
+        }
     }
 
     /**

Copied: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/ServletContextConfig.java
(from r793382, tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextConfig.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/ServletContextConfig.java?p2=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/ServletContextConfig.java&p1=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextConfig.java&r1=793382&r2=793797&rev=793797&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/ServletContextConfig.java
(original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/ServletContextConfig.java
Tue Jul 14 05:38:02 2009
@@ -1,14 +1,15 @@
 /**
  * 
  */
-package org.apache.tomcat.lite;
+package org.apache.tomcat.lite.webxml;
 
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
 
 /**
- * All the data in web.xml should be represented here.
+ * All the data in web.xml, annotations, etc should be represented 
+ * here. This class is serializable.
  * 
  * Public fields to make it easy to access it. 
  * Naming should match the web.xml element name.
@@ -84,11 +85,16 @@
         public String filterName;
     }
     
+    // Normalized
     public static class FilterMappingData implements Serializable {
         private static final long serialVersionUID = -4533568066713041994L;
         public String filterName;
+        
+        // Only one of the 2
         public String urlPattern;
         public String servletName;
+        
+        // REQUEST, FORWARD, INCLUDE, ERROR, ASYNC
         public ArrayList<String> dispatcher = new ArrayList<String>();
     }
     
@@ -119,12 +125,19 @@
         
     }
     
+    public static class WebResourceCollectionData implements Serializable {
+        public String webResourceName;
+        public ArrayList urlPattern = new ArrayList();
+        public ArrayList httpMethod = new ArrayList();
+    }    
+    
     public static class SecurityConstraintData  implements Serializable {
         private static final long serialVersionUID = -4780214921810871769L;
 
         public ArrayList<String> roleName = new ArrayList<String>(); //   auth-constraint/role
 
-        public ArrayList<String> webResourceCollection = new ArrayList<String>();
+        public ArrayList<WebResourceCollectionData> webResourceCollection = 
+            new ArrayList<WebResourceCollectionData>();
         public String transportGuarantee;
         
     }    

Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/WebXml.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/WebXml.java?rev=793797&r1=793796&r2=793797&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/WebXml.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/webxml/WebXml.java Tue Jul
14 05:38:02 2009
@@ -10,12 +10,12 @@
 
 import javax.servlet.ServletException;
 
-import org.apache.tomcat.lite.ServletContextConfig;
-import org.apache.tomcat.lite.ServletContextConfig.EnvEntryData;
-import org.apache.tomcat.lite.ServletContextConfig.FilterData;
-import org.apache.tomcat.lite.ServletContextConfig.FilterMappingData;
-import org.apache.tomcat.lite.ServletContextConfig.SecurityConstraintData;
-import org.apache.tomcat.lite.ServletContextConfig.ServletData;
+import org.apache.tomcat.lite.webxml.ServletContextConfig.EnvEntryData;
+import org.apache.tomcat.lite.webxml.ServletContextConfig.FilterData;
+import org.apache.tomcat.lite.webxml.ServletContextConfig.FilterMappingData;
+import org.apache.tomcat.lite.webxml.ServletContextConfig.SecurityConstraintData;
+import org.apache.tomcat.lite.webxml.ServletContextConfig.ServletData;
+import org.apache.tomcat.lite.webxml.ServletContextConfig.WebResourceCollectionData;
 import org.apache.tomcat.util.DomUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -252,7 +252,9 @@
                 scn = DomUtil.getNext(scn);
             }
             cn = DomUtil.getNext(cn);
+            sd.webResourceCollection.add(wrd);
         }
+        
         d.securityConstraint.add(sd);
     }
 



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


Mime
View raw message