Author: costin
Date: Mon Aug 21 08:20:40 2006
New Revision: 433260

URL: http://svn.apache.org/viewvc?rev=433260&view=rev
Log:
More refactoring - lite directory cleaned up of most functionality that could 
go to a module, all modules
transformed into filter/servlets or listeners. 
Finally implemented a new  web.xml reader, and support saving the processed 
result in .ser.

Starting to make the old valves/etc general purpose filters with no dep on 
lite, user-space possible

Added:
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/TomcatLite.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ctxmap/
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ctxmap/WebappContextMapper.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/http/
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/http/CoyoteAdapter.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/webmap/
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/webmap/WebappFilterMapper.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/webmap/WebappServletMapper.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/config/
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/config/EnvEntryData.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/config/FilterData.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/config/FilterMappingData.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/config/SecurityConstraintData.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/config/ServletData.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/config/WebAppData.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/config/WebResourceCollectionData.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/deploy/
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/deploy/InitServlet.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/deploy/ReloadServlet.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/deploy/WebAnnotation.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/deploy/WebXml.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/session/
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/session/HttpSessionImpl.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/session/SessionManagerServlet.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/util/RandomGenerator.java
    tomcat/sandbox/tomcat-lite/resources/tomcat-lite.MF   (with props)
    tomcat/sandbox/tomcat-lite/webapps/ROOT/
    tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/
    tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/classes   (with props)
    tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/lib/
    tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/lib/moneydance.jar   (with 
props)
    tomcat/sandbox/tomcat-lite/webapps/ROOT/dav/
    tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html
    tomcat/sandbox/tomcat-lite/webapps/__x_deploy/
    tomcat/sandbox/tomcat-lite/webapps/__x_deploy/WEB-INF/
    tomcat/sandbox/tomcat-lite/webapps/__x_deploy/WEB-INF/web.xml
    tomcat/sandbox/tomcat-lite/webapps/__x_engine/
    tomcat/sandbox/tomcat-lite/webapps/__x_engine/WEB-INF/
    tomcat/sandbox/tomcat-lite/webapps/__x_engine/WEB-INF/web.xml
    tomcat/sandbox/tomcat-lite/webapps/__x_protocol/
    tomcat/sandbox/tomcat-lite/webapps/__x_protocol/WEB-INF/
    tomcat/sandbox/tomcat-lite/webapps/__x_protocol/WEB-INF/web.xml
Removed:
    tomcat/sandbox/tomcat-lite/java/org/apache/coyote/
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/CoyoteAdapter.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/Host.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/HttpSessionImpl.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/Main.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletFacade.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/WebappContextMapper.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/WebappFilterMapper.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/WebappServletMapper.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/WebappSessionManager.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/servlets/ReloadServlet.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/webxml/
    tomcat/sandbox/tomcat-lite/resources/coyote-servlet.MF
Modified:
    tomcat/sandbox/tomcat-lite/build.xml
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterChainImpl.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/RequestDispatcherImpl.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletConfigImpl.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletContextImpl.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletRequestImpl.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletRequestWrapperImpl.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseImpl.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/ServletResponseWrapperImpl.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/jmx/JmxListener.java
    tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/package.html
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/util/CharsetMapper.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/util/ParameterMap.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/http11/Http11Processor.java
    
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/nio/NioEndpoint.java

Modified: tomcat/sandbox/tomcat-lite/build.xml
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/build.xml?rev=433260&r1=433259&r2=433260&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-lite/build.xml (original)
+++ tomcat/sandbox/tomcat-lite/build.xml Mon Aug 21 08:20:40 2006
@@ -74,10 +74,10 @@
   <target name="tomcat-lite.jar" depends="compile,pack_tomcat-lite.jar"/>
   
   <target name="pack_tomcat-lite.jar" >
-    <jar destfile="tomcat-lite.jar" manifest="resources/coyote-servlet.MF">
+    <jar destfile="tomcat-lite.jar" manifest="resources/tomcat-lite.MF">
       <fileset dir="${sandbox.home}/classes" >
         <include name="org/apache/commons/logging/*.class"/>
-        <include name="org/apache/coyote/servlet/**"/>
+        <include name="org/apache/tomcat/lite/**"/>
         <include name="org/apache/tomcat/servlets/**"/>
         <include name="org/apache/tomcat/util/buf/**"/>
         <include name="org/apache/tomcat/util/loader/**"/>

Modified: 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterChainImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterChainImpl.java?rev=433260&r1=433259&r2=433260&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterChainImpl.java 
(original)
+++ tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterChainImpl.java 
Mon Aug 21 08:20:40 2006
@@ -27,8 +27,6 @@
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
-import org.apache.tomcat.util.res.StringManager;
-
 // Not thread safe !!
 
 /**
@@ -39,9 +37,7 @@
  * method itself.
  *
  * @author Craig R. McClanahan
- * @version $Revision: 303523 $ $Date: 2004-11-22 08:35:18 -0800 (Mon, 22 Nov 
2004) $
  */
-
 public final class FilterChainImpl implements FilterChain {
 
     public static final int INCREMENT = 8;
@@ -79,13 +75,6 @@
     private ServletConfigImpl wrapper;
 
 
-    /**
-     * The string manager for our package.
-     */
-    private static final StringManager sm =
-      StringManager.getManager("org.apache.coyote.servlet");
-
-
     // ---------------------------------------------------- FilterChain Methods
 
 
@@ -119,8 +108,7 @@
                 throw e;
             } catch (Throwable e) {
                 e.printStackTrace();
-                throw new ServletException
-                  (sm.getString("filterChain.filter"), e);
+                throw new ServletException("Throwable", e);
             }
             return;
         }
@@ -136,8 +124,7 @@
         } catch (RuntimeException e) {
             throw e;
         } catch (Throwable e) {
-            throw new ServletException
-              (sm.getString("filterChain.servlet"), e);
+            throw new ServletException("Throwable", e);
         }
     }
 
@@ -165,7 +152,7 @@
     /**
      * Release references to the filters and wrapper executed by this chain.
      */
-    void release() {
+    public void release() {
         n = 0;
         pos = 0;
         servlet = null;

Modified: 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java?rev=433260&r1=433259&r2=433260&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java 
(original)
+++ 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/FilterConfigImpl.java 
Mon Aug 21 08:20:40 2006
@@ -18,10 +18,8 @@
 package org.apache.tomcat.lite;
 
 
-import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.Filter;
@@ -29,8 +27,8 @@
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
+import org.apache.tomcat.servlets.config.FilterData;
 import org.apache.tomcat.servlets.util.Enumerator;
-import org.apache.tomcat.util.log.SystemLogHandler;
 
 
 /** 
@@ -39,64 +37,37 @@
  *  - className - used to instantiate the filter
  *  - init params
  *  - other things not used in the servlet container ( icon, descr, etc )
- *  
- *  
  */
-public final class FilterConfigImpl implements FilterConfig, Serializable {
+public final class FilterConfigImpl implements FilterConfig {
 
     public FilterConfigImpl(ServletContextImpl context) {
         super();
         this.context = context;
     }
 
+    private FilterData data;
+    
     /**
      * The Context with which we are associated.
      */
     private ServletContextImpl context = null;
 
-    private Map parameters = new HashMap();
-
     /**
      * The application Filter we are configured for.
      */
     private transient Filter filter = null;
 
-    private String filterName = null;
-
-    private String filterClass = null;
-
-    void setFilterName(String filterName) {
-        this.filterName = filterName;
+    public void setData(FilterData data) {
+        this.data = data;
     }
     
-    public Map getParameterMap() {
-        return (this.parameters);
-    }
-
-    public void setParameterMap(Map initParams) {
-        parameters = initParams;
-    }
-
-    public String getFilterClass() {
-        return (this.filterClass);
-    }
-
-    public void setFilterClass(String filterClass) {
-        this.filterClass = filterClass;
-    }
-
-    // --------------------------------------------------- FilterConfig Methods
-
     public String getFilterName() {
-        return (this.filterName);
+        return data.filterName;
     }
 
     public String getInitParameter(String name) {
-        Map map = getParameterMap();
-        if (map == null)
-            return (null);
-        else
-            return ((String) map.get(name));
+        if (data.initParams == null) return null;
+        return ((String) data.initParams.get(name));
     }
 
 
@@ -105,13 +76,11 @@
      * parameters for this Filter.
      */
     public Enumeration getInitParameterNames() {
-
-        Map map = getParameterMap();
+        Map map = data.initParams;
         if (map == null)
             return (new Enumerator(new ArrayList()));
         else
             return (new Enumerator(map.keySet()));
-
     }
 
 
@@ -124,55 +93,31 @@
 
     /**
      * Return the application Filter we are configured for.
-     *
-     * @exception ClassCastException if the specified class does not implement
-     *  the <code>javax.servlet.Filter</code> interface
-     * @exception ClassNotFoundException if the filter class cannot be found
-     * @exception IllegalAccessException if the filter class cannot be
-     *  publicly instantiated
-     * @exception InstantiationException if an exception occurs while
-     *  instantiating the filter object
-     * @exception ServletException if thrown by the filter's init() method
      */
-    Filter getFilter() throws ClassCastException, ClassNotFoundException,
+    public Filter getFilter() throws ClassCastException, 
ClassNotFoundException,
         IllegalAccessException, InstantiationException, ServletException {
 
         // Return the existing filter instance, if any
-        if (this.filter != null)
-            return (this.filter);
+        if (filter != null)
+            return filter;
 
         // Identify the class loader we will be using
-        String filterClass = getFilterClass();
         ClassLoader classLoader = null;
-        if (filterClass.startsWith("org.apache.tomcat.servlet."))
-            classLoader = this.getClass().getClassLoader();
-        else
-            classLoader = context.getClassLoader();
+        
+        classLoader = context.getClassLoader();
 
         ClassLoader oldCtxClassLoader =
             Thread.currentThread().getContextClassLoader();
-
-        // Instantiate a new instance of this filter and return it
-        Class clazz = classLoader.loadClass(filterClass);
-        
-        
-        this.filter = (Filter) clazz.newInstance();
-        if (context instanceof ServletContextImpl &&
-            ((ServletContextImpl)context).getSwallowOutput()) {
-            try {
-                SystemLogHandler.startCapture();
-                filter.init(this);
-            } finally {
-                String log = SystemLogHandler.stopCapture();
-                if (log != null && log.length() > 0) {
-                    getServletContext().log(log);
-                }
-            }
-        } else {
-            filter.init(this);
+        Thread.currentThread().setContextClassLoader(classLoader);
+        try {
+            Class clazz = classLoader.loadClass(data.filterClass);
+            this.filter = (Filter) clazz.newInstance();
+        } finally {        
+           Thread.currentThread().setContextClassLoader(oldCtxClassLoader);
         }
+        
+        filter.init(this);
         return (this.filter);
-
     }
 
 
@@ -180,17 +125,10 @@
      * Release the Filter instance associated with this FilterConfig,
      * if there is one.
      */
-    void release() {
-
+    public void release() {
         if (this.filter != null){
-                filter.destroy();
+            filter.destroy();
         }
         this.filter = null;
-
      }
-
-
-    // -------------------------------------------------------- Private Methods
-
-
 }

Modified: 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/RequestDispatcherImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/RequestDispatcherImpl.java?rev=433260&r1=433259&r2=433260&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/RequestDispatcherImpl.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/RequestDispatcherImpl.java
 Mon Aug 21 08:20:40 2006
@@ -19,9 +19,6 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.Servlet;
@@ -35,14 +32,9 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-//import org.apache.catalina.Globals;
-//import org.apache.catalina.InstanceEvent;
-//import org.apache.catalina.connector.ClientAbortException;
-//import org.apache.catalina.util.InstanceSupport;
-//import org.apache.catalina.util.StringManager;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.tomcat.lite.webmap.WebappFilterMapper;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -61,6 +53,13 @@
 
 final class RequestDispatcherImpl implements RequestDispatcher {
 
+    public RequestDispatcherImpl(ServletConfigImpl wrapper, String name) {
+        this.wrapper = wrapper;
+        this.name = name;
+        this.context = (ServletContextImpl) wrapper.getParent();
+
+    }
+    
     /**
      * Construct a new instance of this class, configured according to the
      * specified parameters.  If both servletPath and pathInfo are
@@ -78,13 +77,9 @@
      * @param name Servlet name (if a named dispatcher was created)
      *  else <code>null</code>
      */
-    public RequestDispatcherImpl
-        (ServletConfigImpl wrapper, String requestURI, String servletPath,
-         String pathInfo, String queryString, String name) {
-
-        super();
-
-        // Save all of our configuration parameters
+    public RequestDispatcherImpl(ServletConfigImpl wrapper, 
+                                 String requestURI, String servletPath,
+                                 String pathInfo, String queryString) {
         this.wrapper = wrapper;
         this.context = (ServletContextImpl) wrapper.getParent();
         this.requestURI = requestURI;
@@ -92,17 +87,6 @@
         this.origServletPath = servletPath;
         this.pathInfo = pathInfo;
         this.queryString = queryString;
-        this.name = name;
-//        if (wrapper instanceof StandardWrapper)
-//            this.support = ((StandardWrapper) wrapper).getInstanceSupport();
-//        else
-//            this.support = new InstanceSupport(wrapper);
-
-        if ( log.isDebugEnabled() )
-            log.debug("servletPath=" + this.servletPath + ", pathInfo=" +
-                this.pathInfo + ", queryString=" + queryString +
-                ", name=" + this.name);
-
     }
 
     /**
@@ -203,126 +187,85 @@
     private static Log log = LogFactory.getLog(RequestDispatcherImpl.class);
 
     /**
-     * The request specified by the dispatching application.
-     */
-    private ServletRequest appRequest = null;
-
-
-    /**
-     * The response specified by the dispatching application.
-     */
-    private ServletResponse appResponse = null;
-
-
-    /**
      * The Context this RequestDispatcher is associated with.
      */
     private ServletContextImpl context = null;
 
-
-    /**
-     * Are we performing an include() instead of a forward()?
-     */
-    private boolean including = false;
-
-
-    /**
-     * Descriptive information about this implementation.
-     */
-    private static final String info =
-        "org.apache.catalina.core.ApplicationDispatcher/1.0";
-
-
     /**
      * The servlet name for a named dispatcher.
      */
     private String name = null;
 
-
+    /*
+      OrigRequest(ServletRequestImpl) -> include/forward * -> this include
+      
+      On the path: user-defined RequestWrapper or our ServletRequestWrapper
+
+      include() is called with a RequestWrapper(->...->origRequest) or 
origRequest
+      
+      Based on params, etc -> we wrap the req / response in 
ServletRequestWrapper,
+       call filters+servlet. Inside, the req can be wrapped again in 
+       userReqWrapper, and other include called. 
+       
+      
+     */
+    
     /**
      * The outermost request that will be passed on to the invoked servlet.
      */
     private ServletRequest outerRequest = null;
 
-
     /**
      * The outermost response that will be passed on to the invoked servlet.
      */
     private ServletResponse outerResponse = null;
 
+    /**
+     * The request wrapper we have created and installed (if any).
+     */
+    private ServletRequest wrapRequest = null;
+
+    /**
+     * The response wrapper we have created and installed (if any).
+     */
+    private ServletResponse wrapResponse = null;
 
+    // Parameters used when constructing the dispatcvher 
     /**
      * The extra path information for this RequestDispatcher.
      */
     private String pathInfo = null;
-
-
     /**
      * The query string parameters for this RequestDispatcher.
      */
     private String queryString = null;
-
-
     /**
      * The request URI for this RequestDispatcher.
      */
     private String requestURI = null;
-
     /**
      * The servlet path for this RequestDispatcher.
      */
     private String servletPath = null;
 
+    //
     private String origServletPath = null;
     
     /**
      * The StringManager for this package.
      */
     private static final StringManager sm =
-      StringManager.getManager("org.apache.coyote.servlet");
-
-
-    /**
-     * The InstanceSupport instance associated with our Wrapper (used to
-     * send "before dispatch" and "after dispatch" events.
-     */
-    //private InstanceSupport support = null;
-
+      StringManager.getManager("org.apache.tomcat.lite");
 
     /**
      * The Wrapper associated with the resource that will be forwarded to
      * or included.
      */
     private ServletConfigImpl wrapper = null;
+    
+    private Servlet servlet; 
 
 
-    /**
-     * The request wrapper we have created and installed (if any).
-     */
-    private ServletRequest wrapRequest = null;
-
-
-    /**
-     * The response wrapper we have created and installed (if any).
-     */
-    private ServletResponse wrapResponse = null;
-
-
-    // ------------------------------------------------------------- Properties
-
-
-    /**
-     * Return the descriptive information about this implementation.
-     */
-    public String getInfo() {
-
-        return (info);
-
-    }
-
-
-    // --------------------------------------------------------- Public Methods
-
 
     /**
      * Forward this request and response to another resource for processing.
@@ -345,6 +288,7 @@
             throw new IllegalStateException
                 (sm.getString("applicationDispatcher.forward.ise"));
         }
+        
         try {
             response.resetBuffer();
         } catch (IllegalStateException e) {
@@ -358,28 +302,12 @@
 
         // Identify the HTTP-specific request and response objects (if any)
         HttpServletRequest hrequest = null;
-        if (request instanceof HttpServletRequest)
-            hrequest = (HttpServletRequest) request;
+        hrequest = (HttpServletRequest) request;
         HttpServletResponse hresponse = null;
-        if (response instanceof HttpServletResponse)
-            hresponse = (HttpServletResponse) response;
-
-        // Handle a non-HTTP forward by passing the existing request/response
-        if ((hrequest == null) || (hresponse == null)) {
+        hresponse = (HttpServletResponse) response;
 
-            if ( log.isDebugEnabled() )
-                log.debug(" Non-HTTP Forward");
-            
-            processRequest(hrequest,hresponse);
-
-        }
-
-        // Handle an HTTP named dispatcher forward
-        else if ((servletPath == null) && (pathInfo == null)) {
-
-            if ( log.isDebugEnabled() )
-                log.debug(" Named Dispatcher Forward");
-            
+        // Handle a nn-HTTP forward by passing the existing request/response
+        if ((servletPath == null) && (pathInfo == null)) {
             ServletRequestWrapperImpl wrequest =
                 (ServletRequestWrapperImpl) wrapRequest();
             wrequest.setRequestURI(hrequest.getRequestURI());
@@ -392,19 +320,11 @@
 
             wrequest.recycle();
             unwrapRequest();
-
-        }
-
-        // Handle an HTTP path-based forward
-        else {
-
-            if ( log.isDebugEnabled() )
-                log.debug(" Path Based Forward");
-
+        } else { // path based
             ServletRequestWrapperImpl wrequest =
                 (ServletRequestWrapperImpl) wrapRequest();
-            String contextPath = context.getContextPath();
 
+            String contextPath = context.getContextPath();
             if (hrequest.getAttribute(FORWARD_REQUEST_URI_ATTR) == null) {
                 wrequest.setAttribute(FORWARD_REQUEST_URI_ATTR,
                                       hrequest.getRequestURI());
@@ -469,38 +389,6 @@
     }
 
     
-
-    /**
-     * Prepare the request based on the filter configuration.
-     * @param request The servlet request we are processing
-     * @param response The servlet response we are creating
-     *
-     * @exception IOException if an input/output error occurs
-     * @exception ServletException if a servlet error occurs
-     */
-    private void processRequest(ServletRequest request, 
-                                ServletResponse response)
-        throws IOException, ServletException {
-                
-        Integer disInt = (Integer) request.getAttribute
-            (WebappFilterMapper.DISPATCHER_TYPE_ATTR);
-        if (disInt != null) {
-            if (disInt.intValue() != WebappFilterMapper.ERROR) {
-                outerRequest.setAttribute
-                    (WebappFilterMapper.DISPATCHER_REQUEST_PATH_ATTR,
-                     origServletPath);
-                outerRequest.setAttribute
-                    (WebappFilterMapper.DISPATCHER_TYPE_ATTR,
-                     new Integer(WebappFilterMapper.FORWARD));
-                invoke(outerRequest, response);
-            } else {
-                invoke(outerRequest, response);
-            }
-        }
-
-    }
-    
-    
     
     /**
      * Include the response from another resource in the current response.
@@ -521,8 +409,7 @@
         setup(request, response, true);
 
         // Create a wrapped response to use for this request
-        // ServletResponse wresponse = null;
-        ServletResponse wresponse = wrapResponse();
+        ServletResponse wresponse = wrapResponse(true);
 
         // Handle a non-HTTP include
         if (!(request instanceof HttpServletRequest) ||
@@ -550,7 +437,7 @@
             wrequest.setAttribute(WebappFilterMapper.DISPATCHER_TYPE_ATTR,
                                              new 
Integer(WebappFilterMapper.INCLUDE));
             
wrequest.setAttribute(WebappFilterMapper.DISPATCHER_REQUEST_PATH_ATTR, 
origServletPath);
-            invoke(outerRequest, outerResponse);
+            invoke(outerRequest, wresponse);
 
             wrequest.recycle();
         }
@@ -585,11 +472,12 @@
             wrequest.setAttribute(WebappFilterMapper.DISPATCHER_TYPE_ATTR,
                                              new 
Integer(WebappFilterMapper.INCLUDE));
             
wrequest.setAttribute(WebappFilterMapper.DISPATCHER_REQUEST_PATH_ATTR, 
origServletPath);
-            invoke(outerRequest, outerResponse);
+            invoke(outerRequest, wresponse);
 
             wrequest.recycle();
         }
 
+        
     }
 
 
@@ -597,6 +485,35 @@
 
 
     /**
+     * Prepare the request based on the filter configuration.
+     * @param request The servlet request we are processing
+     * @param response The servlet response we are creating
+     *
+     * @exception IOException if an input/output error occurs
+     * @exception ServletException if a servlet error occurs
+     */
+    private void processRequest(ServletRequest request, 
+                                ServletResponse response)
+            throws IOException, ServletException {
+        Integer disInt = 
+            (Integer) 
request.getAttribute(WebappFilterMapper.DISPATCHER_TYPE_ATTR);
+        if (disInt != null) {
+            if (disInt.intValue() != WebappFilterMapper.ERROR) {
+                outerRequest.setAttribute
+                    (WebappFilterMapper.DISPATCHER_REQUEST_PATH_ATTR,
+                     origServletPath);
+                outerRequest.setAttribute
+                    (WebappFilterMapper.DISPATCHER_TYPE_ATTR,
+                     new Integer(WebappFilterMapper.FORWARD));
+            }
+            invoke(outerRequest, response);
+        }
+
+    }
+    
+    
+
+    /**
      * Ask the resource represented by this RequestDispatcher to process
      * the associated request, and create (or append to) the associated
      * response.
@@ -627,52 +544,20 @@
         }
 
         // Initialize local variables we may need
-        HttpServletRequest hrequest = (HttpServletRequest) request;
         HttpServletResponse hresponse = (HttpServletResponse) response;
-        Servlet servlet = null;
         IOException ioException = null;
         ServletException servletException = null;
         RuntimeException runtimeException = null;
-        boolean unavailable = false;
-
-        // Check for the servlet being marked unavailable
-        if (wrapper.isUnavailable()) {
-            wrapper.getLogger().warn(
-                    sm.getString("applicationDispatcher.isUnavailable", 
-                    wrapper.getName()));
-            long available = wrapper.getAvailable();
-            if ((available > 0L) && (available < Long.MAX_VALUE))
-                hresponse.setDateHeader("Retry-After", available);
-            hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, sm
-                    .getString("applicationDispatcher.isUnavailable", wrapper
-                            .getName()));
-            unavailable = true;
-        }
-
-        // Allocate a servlet instance to process this request
-        try {
-            if (!unavailable) {
-                servlet = wrapper.allocate();
-            }
-        } catch (ServletException e) {
-            
wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
-                             wrapper.getName()), 
ServletConfigImpl.getRootCause(e));
-            servletException = e;
-            servlet = null;
-        } catch (Throwable e) {
-            
wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
-                             wrapper.getName()), e);
-            servletException = new ServletException
-                (sm.getString("applicationDispatcher.allocateException",
-                              wrapper.getName()), e);
-            servlet = null;
-        }
+        
+        servletException = allocateServlet(hresponse, servletException);
                 
         // Get the FilterChain Here
         WebappFilterMapper factory = 
             
((ServletContextImpl)wrapper.getServletContext()).getFilterMapper();
         FilterChainImpl filterChain = factory.createFilterChain(request,
-                                                                
wrapper,servlet);
+                                                                wrapper,
+                                                                servlet);
+
         // Call the service() method for the allocated servlet instance
         try {
             String jspFile = wrapper.getJspFile();
@@ -680,54 +565,27 @@
                 request.setAttribute(JSP_FILE_ATTR, jspFile);
             else
                 request.removeAttribute(JSP_FILE_ATTR);
-//            support.fireInstanceEvent(InstanceEvent.BEFORE_DISPATCH_EVENT,
-//                                      servlet, request, response);
             // for includes/forwards
             if ((servlet != null) && (filterChain != null)) {
                filterChain.doFilter(request, response);
              }
-            // Servlet Service Method is called by the FilterChain
-            request.removeAttribute(JSP_FILE_ATTR);
-//            support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
-//                                      servlet, request, response);
-//        } catch (ClientAbortException e) {
-//            request.removeAttribute(Globals.JSP_FILE_ATTR);
-//            support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
-//                                      servlet, request, response);
-//            ioException = e;
         } catch (IOException e) {
-            request.removeAttribute(JSP_FILE_ATTR);
-//            support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
-//                                      servlet, request, response);
             
wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
-                             wrapper.getName()), e);
+                             wrapper.getServletName()), e);
             ioException = e;
         } catch (UnavailableException e) {
-            request.removeAttribute(JSP_FILE_ATTR);
-//            support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
-//                                      servlet, request, response);
             
wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
-                             wrapper.getName()), e);
+                             wrapper.getServletName()), e);
             servletException = e;
             wrapper.unavailable(e);
         } catch (ServletException e) {
-            request.removeAttribute(JSP_FILE_ATTR);
-//            support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
-//                                      servlet, request, response);
-            Throwable rootCause = ServletConfigImpl.getRootCause(e);
-//            if (!(rootCause instanceof ClientAbortException)) {
-//                
wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
-//                        wrapper.getName()), rootCause);
-//            }
             servletException = e;
         } catch (RuntimeException e) {
-            request.removeAttribute(JSP_FILE_ATTR);
-//            support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
-//                                      servlet, request, response);
             
wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
-                             wrapper.getName()), e);
+                             wrapper.getServletName()), e);
             runtimeException = e;
         }
+        request.removeAttribute(JSP_FILE_ATTR);
 
         // Release the filter chain (if any) for this request
         try {
@@ -735,33 +593,16 @@
                 filterChain.release();
         } catch (Throwable e) {
             log.error(sm.getString("standardWrapper.releaseFilters",
-                             wrapper.getName()), e);
-          //FIXME Exception handling needs to be simpiler to what is in the 
StandardWrapperValue
+                             wrapper.getServletName()), e);
         }
 
-        // Deallocate the allocated servlet instance
-        try {
-            if (servlet != null) {
-                wrapper.deallocate(servlet);
-            }
-        } catch (ServletException e) {
-            
wrapper.getLogger().error(sm.getString("applicationDispatcher.deallocateException",
-                             wrapper.getName()), e);
-            servletException = e;
-        } catch (Throwable e) {
-            
wrapper.getLogger().error(sm.getString("applicationDispatcher.deallocateException",
-                             wrapper.getName()), e);
-            servletException = new ServletException
-                (sm.getString("applicationDispatcher.deallocateException",
-                              wrapper.getName()), e);
-        }
+        servletException = servletDealocate(servletException);
 
         // Reset the old context class loader
         if (oldCCL != null)
             Thread.currentThread().setContextClassLoader(oldCCL);
         
         // Unwrap request/response if needed
-        // See Bugzilla 30949
         unwrapRequest();
         unwrapResponse();
 
@@ -775,6 +616,67 @@
 
     }
 
+    private ServletException servletDealocate(ServletException 
servletException)
+    {
+        try {
+            if (servlet != null) {
+                wrapper.deallocate(servlet);
+            }
+        } catch (ServletException e) {
+            
wrapper.getLogger().error(sm.getString("applicationDispatcher.deallocateException",
+                             wrapper.getServletName()), e);
+            servletException = e;
+        } catch (Throwable e) {
+            
wrapper.getLogger().error(sm.getString("applicationDispatcher.deallocateException",
+                             wrapper.getServletName()), e);
+            servletException = new ServletException
+                (sm.getString("applicationDispatcher.deallocateException",
+                              wrapper.getServletName()), e);
+        }
+        return servletException;
+    }
+
+    private ServletException allocateServlet(HttpServletResponse hresponse,
+                                             ServletException servletException)
+        throws IOException
+    {
+        boolean unavailable = false;
+
+        // Check for the servlet being marked unavailable
+        if (wrapper.isUnavailable()) {
+            wrapper.getLogger().warn(
+                    sm.getString("applicationDispatcher.isUnavailable", 
+                    wrapper.getServletName()));
+            long available = wrapper.getAvailable();
+            if ((available > 0L) && (available < Long.MAX_VALUE))
+                hresponse.setDateHeader("Retry-After", available);
+            hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, sm
+                    .getString("applicationDispatcher.isUnavailable", 
+                               wrapper.getServletName()));
+            unavailable = true;
+        }
+
+        // Allocate a servlet instance to process this request
+        try {
+            if (!unavailable) {
+                servlet = wrapper.allocate();
+            }
+        } catch (ServletException e) {
+            
wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
+                             wrapper.getServletName()), 
ServletConfigImpl.getRootCause(e));
+            servletException = e;
+            servlet = null;
+        } catch (Throwable e) {
+            
wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
+                             wrapper.getServletName()), e);
+            servletException = new ServletException
+                (sm.getString("applicationDispatcher.allocateException",
+                              wrapper.getServletName()), e);
+            servlet = null;
+        }
+        return servletException;
+    }
+
 
     /**
      * Set up to handle the specified request and response
@@ -787,27 +689,22 @@
     private void setup(ServletRequest request, ServletResponse response,
                        boolean including) {
 
-        this.appRequest = request;
-        this.appResponse = response;
         this.outerRequest = request;
         this.outerResponse = response;
-        this.including = including;
-
     }
 
 
     /**
-     * Unwrap the request if we have wrapped it.
+     * Unwrap the request if we have wrapped it. Not sure how it could end
+     * up in the middle. 
      */
     private void unwrapRequest() {
-
         if (wrapRequest == null)
             return;
 
         ServletRequest previous = null;
         ServletRequest current = outerRequest;
         while (current != null) {
-
             // If we run into the container request we are done
             if (current instanceof ServletRequestImpl)
                 break;
@@ -826,9 +723,7 @@
             // Advance to the next request in the chain
             previous = current;
             current = ((ServletRequestWrapper) current).getRequest();
-
         }
-
     }
 
 
@@ -836,14 +731,12 @@
      * Unwrap the response if we have wrapped it.
      */
     private void unwrapResponse() {
-
         if (wrapResponse == null)
             return;
 
         ServletResponse previous = null;
         ServletResponse current = outerResponse;
         while (current != null) {
-
             // If we run into the container response we are done
             if (current instanceof ServletResponseImpl)
                 break;
@@ -858,13 +751,10 @@
                     ((ServletResponseWrapper) previous).setResponse(next);
                 break;
             }
-
             // Advance to the next response in the chain
             previous = current;
             current = ((ServletResponseWrapper) current).getResponse();
-
         }
-
     }
 
 
@@ -873,20 +763,14 @@
      * appropriate spot in the request chain.
      */
     private ServletRequest wrapRequest() {
-
         // Locate the request we should insert in front of
         ServletRequest previous = null;
         ServletRequest current = outerRequest;
         while (current != null) {
-            if ("org.apache.catalina.servlets.InvokerHttpRequest".
-                equals(current.getClass().getName()))
-                break; // KLUDGE - Make nested RD.forward() using invoker work
             if (!(current instanceof ServletRequestWrapper))
                 break;
             if (current instanceof ServletRequestWrapperImpl)
                 break;
-//            if (current instanceof ApplicationRequest)
-//                break;
             if (current instanceof ServletRequestImpl)
                 break;
             previous = current;
@@ -895,37 +779,38 @@
 
         // Instantiate a new wrapper at this point and insert it in the chain
         ServletRequest wrapper = null;
-//        if ((current instanceof ApplicationHttpRequest) ||
-//            (current instanceof Request) ||
-//            (current instanceof HttpServletRequest)) {
-            // Compute a crossContext flag
-            HttpServletRequest hcurrent = (HttpServletRequest) current;
-            boolean crossContext = false;
-            if ((outerRequest instanceof ServletRequestWrapperImpl) ||
-                (outerRequest instanceof ServletRequestImpl) ||
-                (outerRequest instanceof HttpServletRequest)) {
-                HttpServletRequest houterRequest = 
-                    (HttpServletRequest) outerRequest;
-                Object contextPath = houterRequest.getAttribute
-                    (INCLUDE_CONTEXT_PATH_ATTR);
-                if (contextPath == null) {
-                    // Forward
-                    contextPath = houterRequest.getContextPath();
-                }
-                crossContext = !(context.getContextPath().equals(contextPath));
-            }
-            wrapper = new ServletRequestWrapperImpl
-                (hcurrent, context, crossContext);
-//        } else {
-//            wrapper = new ApplicationRequest(current);
-//        }
+        
+        // Compute a crossContext flag
+        HttpServletRequest hcurrent = (HttpServletRequest) current;
+        boolean crossContext = isCrossContext();
+
+        wrapper = 
+            new ServletRequestWrapperImpl(hcurrent, context, crossContext);
+
         if (previous == null)
             outerRequest = wrapper;
         else
             ((ServletRequestWrapper) previous).setRequest(wrapper);
         wrapRequest = wrapper;
         return (wrapper);
+    }
 
+    private boolean isCrossContext() {
+        boolean crossContext = false;
+        if ((outerRequest instanceof ServletRequestWrapperImpl) ||
+                (outerRequest instanceof ServletRequestImpl) ||
+                (outerRequest instanceof HttpServletRequest)) {
+            HttpServletRequest houterRequest = 
+                (HttpServletRequest) outerRequest;
+            Object contextPath = 
+                houterRequest.getAttribute(INCLUDE_CONTEXT_PATH_ATTR);
+            if (contextPath == null) {
+                // Forward
+                contextPath = houterRequest.getContextPath();
+            }
+            crossContext = !(context.getContextPath().equals(contextPath));
+        }
+        return crossContext;
     }
 
 
@@ -933,8 +818,7 @@
      * Create and return a response wrapper that has been inserted in the
      * appropriate spot in the response chain.
      */
-    private ServletResponse wrapResponse() {
-
+    private ServletResponse wrapResponse(boolean including) {
         // Locate the response we should insert in front of
         ServletResponse previous = null;
         ServletResponse current = outerResponse;
@@ -943,8 +827,6 @@
                 break;
             if (current instanceof ServletResponseWrapperImpl)
                 break;
-//            if (current instanceof ApplicationResponse)
-//                break;
             if (current instanceof ServletResponseImpl)
                 break;
             previous = current;
@@ -953,14 +835,9 @@
 
         // Instantiate a new wrapper at this point and insert it in the chain
         ServletResponse wrapper = null;
-//        if ((current instanceof ApplicationHttpResponse) ||
-//            (current instanceof Response) ||
-//            (current instanceof HttpServletResponse))
             wrapper =
                 new ServletResponseWrapperImpl((HttpServletResponse) current,
                                             including);
-//        else
-//            wrapper = new ApplicationResponse(current, including);
         if (previous == null)
             outerResponse = wrapper;
         else



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to