You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/05/01 03:53:55 UTC

cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets DefaultServlet.java

craigmcc    00/04/30 18:53:55

  Modified:    proposals/catalina/src/share/org/apache/tomcat
                        HttpRequest.java
               proposals/catalina/src/share/org/apache/tomcat/core
                        ApplicationContext.java LocalStrings.properties
                        StandardContext.java StandardWrapperValve.java
               proposals/catalina/src/share/org/apache/tomcat/servlets
                        DefaultServlet.java
  Added:       proposals/catalina/src/share/org/apache/tomcat/core
                        ApplicationDispatcher.java WrappedRequest.java
  Log:
  Remove duplication method declaration from HttpRequest -- isSecure() is
  already declared in Request.
  
  Correct the context mapping for the default servlet -- the requested
  resource should be passed as getServletPath(), not getPathInfo().
  
  Comment out the now-redundant log() call in StandardWrapperValve.
  
  Add an initial implementation of RequestDispatcher -- not yet tested.
  
  Revision  Changes    Path
  1.3       +10 -20    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/HttpRequest.java
  
  Index: HttpRequest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/HttpRequest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpRequest.java	2000/04/16 05:13:35	1.2
  +++ HttpRequest.java	2000/05/01 01:53:53	1.3
  @@ -1,13 +1,13 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/HttpRequest.java,v 1.2 2000/04/16 05:13:35 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/04/16 05:13:35 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/HttpRequest.java,v 1.3 2000/05/01 01:53:53 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/05/01 01:53:53 $
    *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -15,7 +15,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -23,15 +23,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowlegement may appear in the software itself,
    *    if and wherever such third-party acknowlegements normally appear.
    *
    * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  + *    from this software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache"
  @@ -59,7 +59,7 @@
    *
    * [Additional notices, if required by prior licensing conditions]
    *
  - */ 
  + */
   
   
   package org.apache.tomcat;
  @@ -76,7 +76,7 @@
    * produce the corresponding <code>HttpResponse</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/04/16 05:13:35 $
  + * @version $Revision: 1.3 $ $Date: 2000/05/01 01:53:53 $
    */
   
   public interface HttpRequest extends Request {
  @@ -194,16 +194,6 @@
        * @param uri The request URI
        */
       public void setRequestURI(String uri);
  -
  -
  -    /**
  -     * Set the flag indicating whether this Request was received on a secure
  -     * communications link or not.  This will normally be called by the HTTP
  -     * Connector, when it parses the request headers.
  -     *
  -     * @param secure The new secure flag
  -     */
  -    public void setSecure(boolean secure);
   
   
       /**
  
  
  
  1.6       +64 -13    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationContext.java
  
  Index: ApplicationContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ApplicationContext.java	2000/04/27 05:55:14	1.5
  +++ ApplicationContext.java	2000/05/01 01:53:53	1.6
  @@ -1,13 +1,13 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationContext.java,v 1.5 2000/04/27 05:55:14 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/04/27 05:55:14 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationContext.java,v 1.6 2000/05/01 01:53:53 craigmcc Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/05/01 01:53:53 $
    *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -15,7 +15,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -23,15 +23,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowlegement may appear in the software itself,
    *    if and wherever such third-party acknowlegements normally appear.
    *
    * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  + *    from this software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache"
  @@ -59,7 +59,7 @@
    *
    * [Additional notices, if required by prior licensing conditions]
    *
  - */ 
  + */
   
   
   package org.apache.tomcat.core;
  @@ -74,12 +74,15 @@
   import javax.servlet.RequestDispatcher;
   import javax.servlet.Servlet;
   import javax.servlet.ServletContext;
  +import javax.servlet.http.HttpServletRequest;
   import org.apache.tomcat.Container;
   import org.apache.tomcat.Context;
   import org.apache.tomcat.Host;
   import org.apache.tomcat.Logger;
   import org.apache.tomcat.Resources;
   import org.apache.tomcat.Wrapper;
  +import org.apache.tomcat.connector.HttpRequestBase;
  +import org.apache.tomcat.util.StringManager;
   
   
   /**
  @@ -88,7 +91,7 @@
    * associated with each instance of <code>StandardContext</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.5 $ $Date: 2000/04/27 05:55:14 $
  + * @version $Revision: 1.6 $ $Date: 2000/05/01 01:53:53 $
    */
   
   final class ApplicationContext
  @@ -127,6 +130,13 @@
       private StandardContext context = null;
   
   
  +    /**
  +     * The string manager for this package.
  +     */
  +    private static final StringManager sm =
  +      StringManager.getManager(Constants.Package);
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -268,8 +278,17 @@
        */
       public RequestDispatcher getNamedDispatcher(String name) {
   
  +	// Validate the name argument
  +	if (name == null)
  +	    return (null);
  +
   	// Create and return a corresponding request dispatcher
  -	return (null);	// FIXME - getNamedDispatcher()
  +	Wrapper wrapper = (Wrapper) context.findChild(name);
  +	if (wrapper == null)
  +	    return (null);
  +	ApplicationDispatcher dispatcher =
  +	  new ApplicationDispatcher(wrapper, null, null, null);
  +	return ((RequestDispatcher) dispatcher);
   
       }
   
  @@ -321,8 +340,40 @@
        */
       public RequestDispatcher getRequestDispatcher(String path) {
   
  -	// Create and return a corresponding request dispatcher
  -	return (null);	// FIXME - getRequestDispatcher()
  +	// Validate the path argument
  +	if (path == null)
  +	    return (null);
  +	if (!path.startsWith("/"))
  +	    throw new IllegalArgumentException
  +	      (sm.getString("applicationContext.requestDispatcher.iae", path));
  +
  +	// Construct a "fake" request to be mapped by our Context
  +	String contextPath = context.getPath();
  +	if (contextPath == null)
  +	    contextPath = "";
  +	String relativeURI = path;
  +	String queryString = null;
  +	int question = path.indexOf("?");
  +	if (question >= 0) {
  +	    relativeURI = path.substring(0, question);
  +	    queryString = path.substring(question + 1);
  +	}
  +	HttpRequestBase request = new HttpRequestBase();
  +	request.setContext(context);
  +	request.setRequestURI(contextPath + relativeURI);
  +	request.setQueryString(queryString);
  +	Wrapper wrapper = context.map(request, true);
  +	if (wrapper == null)
  +	    return (null);
  +
  +	// Construct a RequestDispatcher to process this request
  +	HttpServletRequest hrequest = (HttpServletRequest) request.getRequest();
  +	ApplicationDispatcher dispatcher =
  +	  new ApplicationDispatcher(wrapper,
  +	  			    hrequest.getServletPath(),
  +	  			    hrequest.getPathInfo(),
  +	  			    hrequest.getQueryString());
  +	return ((RequestDispatcher) dispatcher);
   
       }
   
  
  
  
  1.11      +4 -0      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/LocalStrings.properties,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- LocalStrings.properties	2000/04/29 05:59:53	1.10
  +++ LocalStrings.properties	2000/05/01 01:53:54	1.11
  @@ -1,3 +1,7 @@
  +applicationContext.requestDispatcher.iae=Path {0} does not start with a "/" character
  +applicationDispatcher.forward.ise=Cannot forward after response has been committed
  +applicationDispatcher.forward.throw=Forwarded resource threw an exception
  +applicationDispatcher.include.throw=Included resource threw an exception
   containerBase.alreadyStarted=Container has already been started
   containerBase.notConfigured=No basic Valve has been configured
   containerBase.notStarted=Container has not been started
  
  
  
  1.14      +6 -6      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java
  
  Index: StandardContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StandardContext.java	2000/04/29 23:20:32	1.13
  +++ StandardContext.java	2000/05/01 01:53:54	1.14
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java,v 1.13 2000/04/29 23:20:32 craigmcc Exp $
  - * $Revision: 1.13 $
  - * $Date: 2000/04/29 23:20:32 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardContext.java,v 1.14 2000/05/01 01:53:54 craigmcc Exp $
  + * $Revision: 1.14 $
  + * $Date: 2000/05/01 01:53:54 $
    *
    * ====================================================================
    *
  @@ -92,7 +92,7 @@
    * requests directed to a particular servlet.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.13 $ $Date: 2000/04/29 23:20:32 $
  + * @version $Revision: 1.14 $ $Date: 2000/05/01 01:53:54 $
    */
   
   public final class StandardContext
  @@ -1156,8 +1156,8 @@
   	    if (name != null)
   		wrapper = (Wrapper) findChild(name);
   	    if (wrapper != null) {
  -		servletPath = "";
  -		pathInfo = relativeURI;
  +		servletPath = relativeURI;
  +		pathInfo = null;
   	    }
   	}
   
  
  
  
  1.8       +7 -7      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java
  
  Index: StandardWrapperValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StandardWrapperValve.java	2000/04/30 01:23:22	1.7
  +++ StandardWrapperValve.java	2000/05/01 01:53:54	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v 1.7 2000/04/30 01:23:22 craigmcc Exp $
  - * $Revision: 1.7 $
  - * $Date: 2000/04/30 01:23:22 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v 1.8 2000/05/01 01:53:54 craigmcc Exp $
  + * $Revision: 1.8 $
  + * $Date: 2000/05/01 01:53:54 $
    *
    * ====================================================================
    *
  @@ -89,7 +89,7 @@
    * <code>StandardWrapper</code> container implementation.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.7 $ $Date: 2000/04/30 01:23:22 $
  + * @version $Revision: 1.8 $ $Date: 2000/05/01 01:53:54 $
    */
   
   final class StandardWrapperValve
  @@ -136,8 +136,8 @@
   	    if ((servlet instanceof HttpServlet) &&
   		(sreq instanceof HttpServletRequest) &&
   		(sres instanceof HttpServletResponse)) {
  -		log("Processing request " + ((HttpServletRequest) sreq).getMethod() +
  -		    " " + ((HttpServletRequest) sreq).getRequestURI());
  +//		log("Processing request " + ((HttpServletRequest) sreq).getMethod() +
  +//		    " " + ((HttpServletRequest) sreq).getRequestURI());
   		((HttpServlet) servlet).service((HttpServletRequest) sreq,
   						(HttpServletResponse) sres);
   	    } else {
  @@ -158,8 +158,8 @@
   		    ;
   		}
   	    } catch (IllegalStateException e) {
  -		ServletOutputStream stream = sres.getOutputStream();
   		try {
  +		    ServletOutputStream stream = sres.getOutputStream();
   		    stream.flush();
   		    stream.close();
   		} catch (Throwable t) {
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java
  
  Index: ApplicationDispatcher.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v 1.1 2000/05/01 01:53:54 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/05/01 01:53:54 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.tomcat.core;
  
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Hashtable;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.tomcat.Context;
  import org.apache.tomcat.HttpRequest;
  import org.apache.tomcat.HttpResponse;
  import org.apache.tomcat.Logger;
  import org.apache.tomcat.Request;
  import org.apache.tomcat.Response;
  import org.apache.tomcat.Wrapper;
  import org.apache.tomcat.util.StringManager;
  
  
  /**
   * Standard implementation of <code>RequestDispatcher</code> that allows a
   * request to be forwarded to a different resource to create the ultimate
   * response, or to include the output of another resource in the response
   * from this resource.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/05/01 01:53:54 $
   */
  
  final class ApplicationDispatcher
      implements RequestDispatcher {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new instance of this class, configured according to the
       * specified parameters.  If both servletPath and pathInfo are
       * <code>null</code>, it will be assumed that this RequestDispatcher
       * was acquired by name, rather than by path.
       *
       * @param wrapper The Wrapper associated with the resource that will
       *  be forwarded to or included
       * @param servletPath The revised servlet path to this resource
       * @param pathInfo The revised extra path information to this resource
       * @param queryString Query string parameters included with this request
       */
      public ApplicationDispatcher(Wrapper wrapper,
      			         String servletPath, String pathInfo,
      			         String queryString) {
  
  	super();
  	this.wrapper = wrapper;
  	this.context = (Context) wrapper.getParent();
  	this.logger = wrapper.getLogger();
  	this.servletPath = servletPath;
  	this.pathInfo = pathInfo;
  	this.queryString = queryString;
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The Context this RequestDispatcher is associated with.
       */
      private Context context = null;
  
  
      /**
       * The Logger we can use to log debugging messages.
       */
      private Logger logger = null;
  
  
      /**
       * The extra path information for this RequestDispatcher.
       */
      private String pathInfo = null;
  
  
      /**
       * The query string parameters for this RequestDispatcher.
       */
      private String queryString = null;
  
  
      /**
       * The servlet path for this RequestDispatcher.
       */
      private String servletPath = null;
  
  
      /**
       * The StringManager for this package.
       */
      private static final StringManager sm =
        StringManager.getManager(Constants.Package);
  
  
      /**
       * The Wrapper associated with the resource that will be forwarded to
       * or included.
       */
      private Wrapper wrapper = null;
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Forward this request and response to another resource for processing.
       *
       * @param request The servlet request to be forwarded
       * @param response The servlet response to be forwarded
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public void forward(ServletRequest request, ServletResponse response)
          throws IOException, ServletException {
  
  	// Reset any output that has already been buffered
  	if (response.isCommitted())
  	    throw new IllegalStateException
  	      (sm.getString("applicationDispatcher.forward.ise"));
  	response.reset();
  
  	// Cast the servlet request and response to our internal objects
  	// FIXME - Depends on internal objects not being separated
  	Request srequest = (Request) request;
  	Response sresponse = (Response) response;
  	HttpRequest hrequest = null;
  	if (request instanceof HttpRequest)
  	    hrequest = (HttpRequest) request;
  	HttpResponse hresponse = null;
  	if (response instanceof HttpResponse)
  	    hresponse = (HttpResponse) response;
  
  	// Handle a non-HTTP forward by passing on the existing request and response
  	if ((hrequest == null) || (hresponse == null)) {
  	    try {
  		wrapper.invoke(srequest, sresponse);
  	    } catch (IOException e) {
  		throw e;
  	    } catch (ServletException e) {
  		throw e;
  	    } catch (Throwable t) {
  		throw new ServletException
  		  (sm.getString("applicationDispatcher.forward.throw"), t);
  	    }
  	}
  
  	// Handle an HTTP named dispatcher include (no wrapping is required)
          else if ((servletPath == null) && (pathInfo == null)) {
  	    try {
  		wrapper.invoke(hrequest, hresponse);
  	    } catch (IOException e) {
  		throw e;
  	    } catch (ServletException e) {
  		throw e;
  	    } catch (Throwable t) {
  		throw new ServletException
  		  (sm.getString("applicationDispatcher.forward.throw"), t);
  	    }
  	}
  
  	// Handle an HTTP path-based dispatcher include (with request wrapping)
  	else {
  	    WrappedRequest wrequest = new WrappedRequest(hrequest, queryString);
  	    StringBuffer sb = new StringBuffer();
  	    if (context.getPath() != null)
  	        sb.append(context.getPath());
  	    if (servletPath != null)
  	        sb.append(servletPath);
  	    if (pathInfo != null)
  	        sb.append(pathInfo);
  	    String requestURI = sb.toString();
  	    wrequest.setRequestURI(requestURI);
  	    wrequest.setServletPath(servletPath);
  	    wrequest.setPathInfo(pathInfo);
  	    wrequest.setQueryString(queryString);
  	    try {
  		wrapper.invoke(wrequest, hresponse);
  	    } catch (IOException e) {
  		throw e;
  	    } catch (ServletException e) {
  		throw e;
  	    } catch (Throwable t) {
  		throw new ServletException
  		  (sm.getString("applicationDispatcher.forward.throw"), t);
  	    }
  	}
  
  
  	// Flush and close the output stream or writer
  	PrintWriter writer = null;
  	try {
  	    writer = response.getWriter();
  	    try {
  		writer.flush();
  		writer.close();
  	    } catch (Throwable t) {
  		;
  	    }
  	} catch (IllegalStateException e) {
  	    try {
  		ServletOutputStream stream = response.getOutputStream();
  		stream.flush();
  		stream.close();
  	    } catch (Throwable t) {
  		;
  	    }
  	}
  
      }
  
  
      /**
       * Include the response from another resource in the current response.
       *
       * @param request The servlet request that is including this one
       * @param response The servlet response to be appended to
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public void include(ServletRequest request, ServletResponse response)
          throws IOException, ServletException {
  
  	// Flush the response to avoid allowing the included resource
  	// to set headers
  	response.flushBuffer();
  
  	// Cast the servlet request and response to our internal objects
  	// FIXME - Depends on internal objects not being separated
  	Request srequest = (Request) request;
  	Response sresponse = (Response) response;
  	HttpRequest hrequest = null;
  	if (request instanceof HttpRequest)
  	    hrequest = (HttpRequest) request;
  	HttpResponse hresponse = null;
  	if (response instanceof HttpResponse)
  	    hresponse = (HttpResponse) response;
  
  	// Handle a non-HTTP include by passing on the existing request and response
  	if ((hrequest == null) || (hresponse == null)) {
  	    try {
  		wrapper.invoke(srequest, sresponse);
  	    } catch (IOException e) {
  		throw e;
  	    } catch (ServletException e) {
  		throw e;
  	    } catch (Throwable t) {
  		throw new ServletException
  		  (sm.getString("applicationDispatcher.include.throw"), t);
  	    }
  	    return;
  	}
  
  	// Handle an HTTP named dispatcher include (no wrapping is required)
  	if ((servletPath == null) && (pathInfo == null)) {
  	    try {
  		wrapper.invoke(hrequest, hresponse);
  	    } catch (IOException e) {
  		throw e;
  	    } catch (ServletException e) {
  		throw e;
  	    } catch (Throwable t) {
  		throw new ServletException
  		  (sm.getString("applicationDispatcher.include.throw"), t);
  	    }
  	    return;
  	}
  
  	// Handle an HTTP path-based dispatcher include (with request wrapping)
  	WrappedRequest wrequest = new WrappedRequest(hrequest, queryString);
  	String contextPath = context.getPath();
  	StringBuffer sb = new StringBuffer();
  	if (contextPath != null)
  	    sb.append(contextPath);
  	if (servletPath != null)
  	    sb.append(servletPath);
  	if (pathInfo != null)
  	    sb.append(pathInfo);
  	ServletRequest sr = wrequest.getRequest();
  	if (sb.length() > 0)
  	    sr.setAttribute("javax.servlet.include.request_uri", sb.toString());
  	if (contextPath != null)
  	    sr.setAttribute("javax.servlet.include.context_path", sb.toString());
  	if (servletPath != null)
  	    sr.setAttribute("javax.servlet.include.servlet_path", sb.toString());
  	if (pathInfo != null)
  	    sr.setAttribute("javax.servlet.include.path_info", sb.toString());
  	if (queryString != null)
  	    sr.setAttribute("javax.servlet.include.query_string", sb.toString());
  
  	try {
  	    wrapper.invoke(wrequest, hresponse);
  	} catch (IOException e) {
  	    throw e;
  	} catch (ServletException e) {
  	    throw e;
  	} catch (Throwable t) {
  	    throw new ServletException
  	      (sm.getString("applicationDispatcher.include.throw"), t);
  	}
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/WrappedRequest.java
  
  Index: WrappedRequest.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/WrappedRequest.java,v 1.1 2000/05/01 01:53:54 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/05/01 01:53:54 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.tomcat.core;
  
  
  import java.io.BufferedReader;
  import java.io.InputStream;
  import java.io.IOException;
  import java.security.Principal;
  import java.util.Enumeration;
  import java.util.Hashtable;
  import java.util.Locale;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.ServletInputStream;
  import javax.servlet.ServletRequest;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  import javax.servlet.http.HttpUtils;
  import org.apache.tomcat.Connector;
  import org.apache.tomcat.Context;
  import org.apache.tomcat.HttpRequest;
  import org.apache.tomcat.Request;
  import org.apache.tomcat.Response;
  import org.apache.tomcat.Wrapper;
  import org.apache.tomcat.util.StringManager;
  
  
  /**
   * Wrapped HttpRequest suitable for use in implementations of
   * RequestDispatcher.  The components that are wrapped by this
   * implementation are:
   * <ul>
   * <li>The request attributes (because they will be augmented on an HTTP
   *     path-based include)
   * <li>The request parameters (because they will be merged on an HTTP
   *     path-based include)
   * <li>The request path elements (because they will be modified on an HTTP
   *     path-based forward)
   * </ul>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/05/01 01:53:54 $
   */
  
  final class WrappedRequest
      implements HttpRequest, HttpServletRequest, ServletRequest {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new instance of this class, wrapping the specified request.
       *
       * @param request The HTTP request we are wrapping
       * @param queryString Optional query string with parameters to merge
       */
      public WrappedRequest(HttpRequest request, String queryString) {
  
  	super();
  	this.request = request;
  	this.context = request.getContext();
  	ServletRequest srequest = request.getRequest();
  
  	// Initialize our attributes from the wrapped request
  	Enumeration names = srequest.getAttributeNames();
  	while (names.hasMoreElements()) {
  	    String name = (String) names.nextElement();
  	    Object value = srequest.getAttribute(name);
  	    attributes.put(name, value);
  	}
  	if (srequest instanceof HttpServletRequest) {
  	    HttpServletRequest hrequest = (HttpServletRequest) srequest;
  	    requestURI = hrequest.getRequestURI();
  	    servletPath = hrequest.getServletPath();
  	    pathInfo = hrequest.getPathInfo();
  	}
  	this.queryString = queryString;
  
  	// Initialize our parameters from the wrapped request.
  	names = srequest.getParameterNames();
  	while (names.hasMoreElements()) {
  	    String name = (String) names.nextElement();
  	    String values[] = srequest.getParameterValues(name);
  	    parameters.put(name, values);
  	}
  
  	// Merge the additional query parameters (if any)
  	if (queryString == null)
  	    return;
  	Hashtable newParams = HttpUtils.parseQueryString(queryString);
  	if (newParams == null)
  	    return;
  	names = newParams.keys();
  	while (names.hasMoreElements()) {
  	    String name = (String) names.nextElement();
  	    String oldValues[] = (String[]) parameters.get(name);
  	    if (oldValues == null)
  	        oldValues = new String[0];
  	    String newValues[] = null;
  	    Object newValue = newParams.get(name);
  	    if (newValue instanceof String) {
  		newValues = new String[1];
  		newValues[0] = (String) newValue;
  	    } else if (newValue instanceof String[])
  	        newValues = (String[]) newValue;
  	    else
  	        newValues = new String[0];
  	    String mergedValues[] = new String[oldValues.length + newValues.length];
  	    for (int i = 0; i < newValues.length; i++)
  	        mergedValues[i] = newValues[i];
  	    for (int i = newValues.length; i < mergedValues.length; i++)
  	        mergedValues[i] = oldValues[i - newValues.length];
  	    parameters.put(name, mergedValues);
  	}
  
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The attributes for this wrapped request (initialized from the underlying
       * request, but possibly amended).
       */
      private Hashtable attributes = new Hashtable();
  
  
      /**
       * The Context within which this request is being processed.
       */
      private Context context = null;
  
  
      /**
       * Descriptive information about this implementation.
       */
      private static final String info =
        "org.apache.tomcat.core.WrappedRequest/1.0";
  
  
      /**
       * The parameters for this wrapped request (initialized from the underlying
       * request, but possibly amended).
       */
      private Hashtable parameters = new Hashtable();
  
  
      /**
       * The extra path information for this request.
       */
      private String pathInfo = null;
  
  
      /**
       * The query string for this request.
       */
      private String queryString = null;
  
  
      /**
       * The HttpRequest we are wrapping.
       */
      private HttpRequest request = null;
  
  
      /**
       * The request URI for this request.
       */
      private String requestURI = null;
  
  
      /**
       * The servlet path for this request;
       */
      private String servletPath = null;
  
  
      // ---------------------------------------------------- HttpRequest Methods
  
  
      /**
       * Add a Cookie to the set of Cookies associated with this Request.
       *
       * @param cookie The new cookie
       */
      public void addCookie(Cookie cookie) {
  	request.addCookie(cookie);
      }
  
  
      /**
       * Add a Header to the set of Headers associated with this Request.
       *
       * @param name The new header name
       * @param value The new header value
       */
      public void addHeader(String name, String value) {
  	request.addHeader(name, value);
      }
  
  
      /**
       * Add a Locale to the set of preferred Locales for this Request.  The
       * first added Locale will be the first one returned by getLocales().
       *
       * @param locale The new preferred Locale
       */
      public void addLocale(Locale locale) {
  	request.addLocale(locale);
      }
  
  
      /**
       * Set the authentication type used for this request, if any; otherwise
       * set the type to <code>null</code>.  Typical values are "BASIC",
       * "DIGEST", or "SSL".
       *
       * @param type The authentication type used
       */
      public void setAuthType(String type) {
  	request.setAuthType(type);
      }
  
  
      /**
       * Set the context path for this Request.  This will normally be called
       * when the associated Context is mapping the Request to a particular
       * Wrapper.
       *
       * @param path The context path
       */
      public void setContextPath(String path) {
  	request.setContextPath(path);
      }
  
  
      /**
       * Set the HTTP request method used for this Request.
       *
       * @param method The request method
       */
      public void setMethod(String method) {
  	request.setMethod(method);
      }
  
  
      /**
       * Set the query string for this Request.  This will normally be called
       * by the HTTP Connector, when it parses the request headers.
       *
       * @param query The query string
       */
      public void setQueryString(String query) {
  	this.queryString = query;
      }
  
  
      /**
       * Set the path information for this Request.  This will normally be called
       * when the associated Context is mapping the Request to a particular
       * Wrapper.
       *
       * @param path The path information
       */
      public void setPathInfo(String path) {
  	this.pathInfo = path;
      }
  
  
      /**
       * Set a flag indicating whether or not the requested session ID for this
       * request came in through a cookie.  This is normally called by the
       * HTTP Connector, when it parses the request headers.
       *
       * @param flag The new flag
       */
      public void setRequestedSessionCookie(boolean flag) {
  	request.setRequestedSessionCookie(flag);
      }
  
  
      /**
       * Set the requested session ID for this request.  This is normally called
       * by the HTTP Connector, when it parses the request headers.
       *
       * @param id The new session id
       */
      public void setRequestedSessionId(String id) {
  	request.setRequestedSessionId(id);
      }
  
  
      /**
       * Set a flag indicating whether or not the requested session ID for this
       * request came in through a URL.  This is normally called by the
       * HTTP Connector, when it parses the request headers.
       *
       * @param flag The new flag
       */
      public void setRequestedSessionURL(boolean flag) {
  	request.setRequestedSessionURL(flag);
      }
  
  
      /**
       * Set the unparsed request URI for this Request.  This will normally be
       * called by the HTTP Connector, when it parses the request headers.
       *
       * @param uri The request URI
       */
      public void setRequestURI(String uri) {
  	this.requestURI = uri;
      }
  
  
      /**
       * Set the servlet path for this Request.  This will normally be called
       * when the associated Context is mapping the Request to a particular
       * Wrapper.
       *
       * @param path The servlet path
       */
      public void setServletPath(String path) {
  	this.servletPath = path;
      }
  
  
      /**
       * Set the Principal who has been authenticated for this Request.  This
       * value is also used to calculate the value to be returned by the
       * <code>getRemoteUser()</code> method.
       *
       * @param principal The user Principal
       */
      public void setUserPrincipal(Principal principal) {
  	request.setUserPrincipal(principal);
      }
  
  
      // -------------------------------------------- HttpServletRequest Methods
  
  
      /**
       * Return the authentication type used for this Request.
       */
      public String getAuthType() {
  	return (((HttpServletRequest) request.getRequest()).getAuthType());
      }
  
  
      /**
       * Return the portion of the request URI used to select the Context
       * of the Request.
       */
      public String getContextPath() {
  	return (((HttpServletRequest) request.getRequest()).getContextPath());
      }
  
  
      /**
       * Return the set of Cookies received with this Request.
       */
      public Cookie[] getCookies() {
  	return (((HttpServletRequest) request.getRequest()).getCookies());
      }
  
  
      /**
       * Return the value of the specified date header, if any; otherwise
       * return -1.
       *
       * @param name Name of the requested date header
       *
       * @exception IllegalArgumentException if the specified header value
       *  cannot be converted to a date
       */
      public long getDateHeader(String name) {
  	return (((HttpServletRequest) request.getRequest()).getDateHeader(name));
      }
  
  
      /**
       * Return the first value of the specified header, if any; otherwise,
       * return <code>null</code>
       *
       * @param name Name of the requested header
       */
      public String getHeader(String name) {
  	return (((HttpServletRequest) request.getRequest()).getHeader(name));
      }
  
  
      /**
       * Return all of the values of the specified header, if any; otherwise,
       * return <code>null</code>.
       *
       * @param name Name of the requested header
       */
      public Enumeration getHeaders(String name) {
  	return (((HttpServletRequest) request.getRequest()).getHeaders(name));
      }
  
  
      /**
       * Return the names of all headers received with this request.
       */
      public Enumeration getHeaderNames() {
  	return (((HttpServletRequest) request.getRequest()).getHeaderNames());
      }
  
  
      /**
       * Return the value of the specified header as an integer, or -1 if there
       * is no such header for this request.
       *
       * @param name Name of the requested header
       *
       * @exception IllegalArgumentException if the specified header value
       *  cannot be converted to an integer
       */
      public int getIntHeader(String name) {
  	return (((HttpServletRequest) request.getRequest()).getIntHeader(name));
      }
  
  
      /**
       * Return the HTTP request method used in this Request.
       */
      public String getMethod() {
  	return (((HttpServletRequest) request.getRequest()).getMethod());
      }
  
  
      /**
       * Return the path information associated with this Request.
       */
      public String getPathInfo() {
  	return (this.pathInfo);
      }
  
  
      /**
       * Return the extra path information for this request, translated
       * to a real path.
       */
      public String getPathTranslated() {
  	if (pathInfo == null)
  	    return (null);
  	else
  	    return (context.getServletContext().getRealPath(pathInfo));
      }
  
  
      /**
       * Return the query string associated with this request.
       */
      public String getQueryString() {
  	return (this.queryString);
      }
  
  
      /**
       * Return the name of the remote user that has been authenticated
       * for this Request.
       */
      public String getRemoteUser() {
  	return (((HttpServletRequest) request.getRequest()).getRemoteUser());
      }
  
  
      /**
       * Return the session identifier included in this request, if any.
       */
      public String getRequestedSessionId() {
  	return (((HttpServletRequest) request.getRequest()).getRequestedSessionId());
      }
  
  
      /**
       * Return the request URI for this request.
       */
      public String getRequestURI() {
  	return (this.requestURI);
      }
  
  
      /**
       * Return the portion of the request URI used to select the servlet
       * that will process this request.
       */
      public String getServletPath() {
  	return (this.servletPath);
      }
  
  
      /**
       * Return the session associated with this Request, creating one
       * if necessary.
       */
      public HttpSession getSession() {
  	return (((HttpServletRequest) request.getRequest()).getSession());
      }
  
  
      /**
       * Return the session associated with this Request, creating one
       * if necessary and requested.
       *
       * @param create Create a new session if one does not exist
       */
      public HttpSession getSession(boolean create) {
  	return (((HttpServletRequest) request.getRequest()).getSession(create));
      }
  
  
      /**
       * Return <code>true</code> if the session identifier included in this
       * request came from a cookie.
       */
      public boolean isRequestedSessionIdFromCookie() {
  	return (((HttpServletRequest) request.getRequest()).isRequestedSessionIdFromCookie());
      }
  
  
      /**
       * Return <code>true</code> if the session identifier included in this
       * request came from the request URI.
       */
      public boolean isRequestedSessionIdFromURL() {
  	return (((HttpServletRequest) request.getRequest()).isRequestedSessionIdFromURL());
      }
  
  
      /**
       * Return <code>true</code> if the session identifier included in this
       * request came from the request URI.
       *
       * @deprecated As of Version 2.1 of the Java Servlet API, use
       *  <code>isRequestedSessionIdFromURL()</code> instead.
       */
      public boolean isRequestedSessionIdFromUrl() {
  	return (((HttpServletRequest) request.getRequest()).isRequestedSessionIdFromUrl());
      }
  
  
      /**
       * Return <code>true</code> if the session identifier included in this
       * request identifies a valid session.
       */
      public boolean isRequestedSessionIdValid() {
  	return (((HttpServletRequest) request.getRequest()).isRequestedSessionIdValid());
      }
  
  
      /**
       * Return <code>true</code> if the authenticated user principal
       * possesses the specified role name.
       *
       * @param role Role name to be validated
       */
      public boolean isUserInRole(String role) {
  	return (((HttpServletRequest) request.getRequest()).isUserInRole(role));
      }
  
  
      /**
       * Return the principal that has been authenticated for this Request.
       */
      public Principal getUserPrincipal() {
  	return (((HttpServletRequest) request.getRequest()).getUserPrincipal());
      }
  
  
      // -------------------------------------------------------- Request Methods
  
  
      /**
       * Return the Connector through which this Request was received.
       */
      public Connector getConnector() {
  	return (request.getConnector());
      }
  
  
      /**
       * Set the Connector through which this Request was received.
       *
       * @param connector The new connector
       */
      public void setConnector(Connector connector) {
  	request.setConnector(connector);
      }
  
  
      /**
       * Return the Context within which this Request is being processed.
       */
      public Context getContext() {
  	return (request.getContext());
      }
  
  
      /**
       * Set the Context within which this Request is being processed.  This
       * must be called as soon as the appropriate Context is identified, because
       * it identifies the value to be returned by <code>getContextPath()</code>,
       * and thus enables parsing of the request URI.
       *
       * @param context The newly associated Context
       */
      public void setContext(Context context) {
  	request.setContext(context);
      }
  
  
      /**
       * Return descriptive information about this Request implementation and
       * the corresponding version number, in the format
       * <code>&lt;description&gt;/&lt;version&gt;</code>.
       */
      public String getInfo() {
  	return (info);
      }
  
  
      /**
       * Return the <code>ServletRequest</code> for which this object
       * is the facade.
       */
      public ServletRequest getRequest() {
  	return ((ServletRequest) this);
      }
  
  
      /**
       * Return the Response with which this Request is associated.
       */
      public Response getResponse() {
  	return (request.getResponse());
      }
  
  
      /**
       * Set the Response with which this Request is associated.
       *
       * @param response The new associated response
       */
      public void setResponse(Response response) {
  	request.setResponse(response);
      }
  
  
      /**
       * Return the input stream associated with this Request.
       */
      public InputStream getStream() {
  	return (request.getStream());
      }
  
  
      /**
       * Set the input stream associated with this Request.
       *
       * @param stream The new input stream
       */
      public void setStream(InputStream stream) {
  	request.setStream(stream);
      }
  
  
      /**
       * Return the Wrapper within which this Request is being processed.
       */
      public Wrapper getWrapper() {
  	return (request.getWrapper());
      }
  
  
      /**
       * Set the Wrapper within which this Request is being processed.  This
       * must be called as soon as the appropriate Wrapper is identified, and
       * before the Request is ultimately passed to an application servlet.
       *
       * @param wrapper The newly associated Wrapper
       */
      public void setWrapper(Wrapper wrapper) {
  	request.setWrapper(wrapper);
      }
  
  
      /**
       * Create and return a ServletInputStream to read the content
       * associated with this Request.
       *
       * @exception IOException if an input/output error occurs
       */
      public ServletInputStream createInputStream() throws IOException {
  	return (request.createInputStream());
      }
  
  
      /**
       * Release all object references, and initialize instance variables, in
       * preparation for reuse of this object.
       */
      public void recycle() {
  	;	// This object will not be recycled
      }
  
  
      /**
       * Set the content length associated with this Request.
       *
       * @param length The new content length
       */
      public void setContentLength(int length) {
  	request.setContentLength(length);
      }
  
  
      /**
       * Set the content type (and optionally the character encoding)
       * associated with this Request.  For example,
       * <code>text/html; charset=ISO-8859-4</code>.
       *
       * @param type The new content type
       */
      public void setContentType(String type) {
  	request.setContentType(type);
      }
  
  
      /**
       * Set the protocol name and version associated with this Request.
       *
       * @param protocol Protocol name and version
       */
      public void setProtocol(String protocol) {
  	request.setProtocol(protocol);
      }
  
  
      /**
       * Set the remote IP address associated with this Request.  NOTE:  This
       * value will be used to resolve the value for <code>getRemoteHost()</code>
       * if that method is called.
       *
       * @param remote The remote IP address
       */
      public void setRemoteAddr(String remote) {
  	request.setRemoteAddr(remote);
      }
  
  
      /**
       * Set the name of the scheme associated with this request.  Typical values
       * are <code>http</code>, <code>https</code>, and <code>ftp</code>.
       *
       * @param scheme The scheme
       */
      public void setScheme(String scheme) {
  	request.setScheme(scheme);
      }
  
  
      /**
       * Set the value to be returned by <code>isSecure()</code>
       * for this Request.
       *
       * @param secure The new isSecure value
       */
      public void setSecure(boolean secure) {
  	request.setSecure(secure);
      }
  
  
      /**
       * Set the name of the server (virtual host) to process this request.
       *
       * @param name The server name
       */
      public void setServerName(String name) {
  	request.setServerName(name);
      }
  
  
      /**
       * Set the port number of the server to process this request.
       *
       * @param port The server port
       */
      public void setServerPort(int port) {
  	request.setServerPort(port);
      }
  
  
      // ------------------------------------------------- ServletRequest Methods
  
  
      /**
       * Return the specified request attribute if it exists; otherwise, return
       * <code>null</code>.
       *
       * @param name Name of the request attribute to return
       */
      public Object getAttribute(String name) {
  	return (attributes.get(name));
      }
  
  
      /**
       * Return the names of all request attributes for this Request, or an
       * empty <code>Enumeration</code> if there are none.
       */
      public Enumeration getAttributeNames() {
  	return (attributes.keys());
      }
  
  
      /**
       * Return the character encoding for this Request.
       */
      public String getCharacterEncoding() {
  	return (request.getRequest().getCharacterEncoding());
      }
  
  
      /**
       * Return the content length for this Request.
       */
      public int getContentLength() {
  	return (request.getRequest().getContentLength());
      }
  
  
      /**
       * Return the content type for this Request.
       */
      public String getContentType() {
  	return (request.getRequest().getContentType());
      }
  
  
      /**
       * Return the servlet input stream for this Request.  The default
       * implementation returns a servlet input stream created by
       * <code>createInputStream()</code>.
       *
       * @exception IllegalStateException if <code>getReader()</code> has
       *  already been called for this request
       * @exception IOException if an input/output error occurs
       */
      public ServletInputStream getInputStream() throws IOException {
  	return (request.getRequest().getInputStream());
      }
  
  
      /**
       * Return the preferred Locale that the client will accept content in,
       * based on the value for the first <code>Accept-Language</code> header
       * that was encountered.  If the request did not specify a preferred
       * language, the server's default Locale is returned.
       */
      public Locale getLocale() {
  	return (request.getRequest().getLocale());
      }
  
  
      /**
       * Return the set of preferred Locales that the client will accept
       * content in, based on the values for any <code>Accept-Language</code>
       * headers that were encountered.  If the request did not specify a
       * preferred language, the server's default Locale is returned.
       */
      public Enumeration getLocales() {
  	return (request.getRequest().getLocales());
      }
  
  
      /**
       * Return the value of the specified request parameter, if any; otherwise,
       * return <code>null</code>.  If there is more than one value defined,
       * return only the first one.
       *
       * @param name Name of the desired request parameter
       */
      public String getParameter(String name) {
  	String values[] = (String[]) parameters.get(name);
  	if (values != null)
  	    return (values[0]);
  	else
  	    return (null);
      }
  
  
      /**
       * Return the names of all defined request parameters for this request.
       */
      public Enumeration getParameterNames() {
  	return (parameters.keys());
      }
  
  
      /**
       * Return the defined values for the specified request parameter, if any;
       * otherwise, return <code>null</code>.
       *
       * @param name Name of the desired request parameter
       */
      public String[] getParameterValues(String name) {
  	return ((String[]) parameters.get(name));
      }
  
  
      /**
       * Return the protocol and version used to make this Request.
       */
      public String getProtocol() {
  	return (request.getRequest().getProtocol());
      }
  
  
      /**
       * Read the Reader wrapping the input stream for this Request.  The
       * default implementation wraps a <code>BufferedReader</code> around the
       * servlet input stream returned by <code>createInputStream()</code>.
       *
       * @exception IllegalStateException if <code>getInputStream()</code>
       *  has already been called for this request
       * @exception IOException if an input/output error occurs
       */
      public BufferedReader getReader() throws IOException {
  	return (request.getRequest().getReader());
      }
  
  
      /**
       * Return the real path of the specified virtual path.
       *
       * @param path Path to be translated
       *
       * @deprecated As of version 2.1 of the Java Servlet API, use
       *  <code>ServletContext.getRealPath()</code>.
       */
      public String getRealPath(String path) {
  	return (request.getRequest().getRealPath(path));
      }
  
  
      /**
       * Return the remote IP address making this Request.
       */
      public String getRemoteAddr() {
  	return (request.getRequest().getRemoteAddr());
      }
  
  
      /**
       * Return the remote host name making this Request.
       */
      public String getRemoteHost() {
  	return (request.getRequest().getRemoteHost());
      }
  
  
      /**
       * Return a RequestDispatcher that wraps the resource at the specified
       * path, which may be interpreted as relative to the current request path.
       *
       * @param path Path of the resource to be wrapped
       */
      public RequestDispatcher getRequestDispatcher(String path) {
  	return (request.getRequest().getRequestDispatcher(path));
      }
  
  
      /**
       * Return the scheme used to make this Request.
       */
      public String getScheme() {
  	return (request.getRequest().getScheme());
      }
  
  
      /**
       * Return the server name responding to this Request.
       */
      public String getServerName() {
  	return (request.getRequest().getServerName());
      }
  
  
      /**
       * Return the server port responding to this Request.
       */
      public int getServerPort() {
  	return (request.getRequest().getServerPort());
      }
  
  
      /**
       * Was this request received on a secure connection?
       */
      public boolean isSecure() {
  	return (request.getRequest().isSecure());
      }
  
  
      /**
       * Remove the specified request attribute if it exists.
       *
       * @param name Name of the request attribute to remove
       */
      public void removeAttribute(String name) {
  	attributes.remove(name);
      }
  
  
      /**
       * Set the specified request attribute to the specified value.
       *
       * @param name Name of the request attribute to set
       * @param value The associated value
       */
      public void setAttribute(String name, Object value) {
  	attributes.put(name, value);
      }
  
  
  }
  
  
  
  1.4       +14 -14    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/DefaultServlet.java
  
  Index: DefaultServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/DefaultServlet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultServlet.java	2000/04/29 20:25:19	1.3
  +++ DefaultServlet.java	2000/05/01 01:53:55	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/DefaultServlet.java,v 1.3 2000/04/29 20:25:19 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/04/29 20:25:19 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets/DefaultServlet.java,v 1.4 2000/05/01 01:53:55 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/05/01 01:53:55 $
    *
    * ====================================================================
    *
  @@ -91,7 +91,7 @@
    * used to serve static resources such as HTML pages and images.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2000/04/29 20:25:19 $
  + * @version $Revision: 1.4 $ $Date: 2000/05/01 01:53:55 $
    */
   
   public final class DefaultServlet
  @@ -455,37 +455,37 @@
   	throws IOException, ServletException {
   
   	// Identify the requested resource path
  -	String pathInfo = request.getPathInfo();
  -	if (pathInfo == null)
  -	    pathInfo = "/";
  +	String servletPath = request.getServletPath();
  +	if (servletPath == null)
  +	    servletPath = "/";
   	if (debug > 0) {
   	    if (content)
   		log("DefaultServlet.serveResource:  Serving resource '" +
  -		    pathInfo + "' headers and data");
  +		    servletPath + "' headers and data");
   	    else
   		log("DefaultServlet.serveResource:  Serving resource '" +
  -		    pathInfo + "' headers only");
  +		    servletPath + "' headers only");
   	}
  -	if (pathInfo == null) {
  +	if (servletPath == null) {
   	    response.sendError(HttpServletResponse.SC_BAD_REQUEST);
   	    return;
   	}
   
   	// Exclude any resource in the /WEB-INF subdirectory
  -	if (pathInfo.startsWith("/WEB-INF")) {
  -	    response.sendError(HttpServletResponse.SC_NOT_FOUND, pathInfo);
  +	if (servletPath.startsWith("/WEB-INF")) {
  +	    response.sendError(HttpServletResponse.SC_NOT_FOUND, servletPath);
   	    return;
   	}
   
   	// Convert the resource path to a URL
   	URL resourceURL = null;
   	try {
  -	    resourceURL = getServletContext().getResource(pathInfo);
  +	    resourceURL = getServletContext().getResource(servletPath);
   	} catch (MalformedURLException e) {
   	    ;
   	}
   	if (resourceURL == null) {
  -	    response.sendError(HttpServletResponse.SC_NOT_FOUND, pathInfo);
  +	    response.sendError(HttpServletResponse.SC_NOT_FOUND, servletPath);
   	    return;
   	}
   	if (debug > 0)
  
  
  

[Catalina] Servlet Path + Session store

Posted by Remy Maucherat <re...@exoffice.com>.
> For the root context, context path should be "" (a zero-length string).
The
> context path matches the "path=" attribute of your <Context> element in
> conf/server.xml.

Ok, this is correct then. I thought it would match the url pattern from
web.xml. My mistake.

> However, it looks like this is still wrong -- your servlet should see:
>
>     Servlet path: /servlet/org.exolab.slide.webdav.Webdav
>     Path info: null
>
> in this scenario.  I will take a look at that problem.

Thanks for the fix !

Some Exoffice people are contributing to a Gnu db clone, called jdbm. I
guess it could be used for session object storage.
http://sourceforge.net/project/?group_id=4155

Remy


Re: [Catalina] Re: cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets DefaultServlet.java

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Remy Maucherat wrote:

> > craigmcc    00/04/30 18:53:55
> >
> >   Modified:    proposals/catalina/src/share/org/apache/tomcat
> >                         HttpRequest.java
> >                proposals/catalina/src/share/org/apache/tomcat/core
> >                         ApplicationContext.java LocalStrings.properties
> >                         StandardContext.java StandardWrapperValve.java
> >                proposals/catalina/src/share/org/apache/tomcat/servlets
> >                         DefaultServlet.java
> >   Added:       proposals/catalina/src/share/org/apache/tomcat/core
> >                         ApplicationDispatcher.java WrappedRequest.java
> >   Log:
> >   Remove duplication method declaration from HttpRequest -- isSecure() is
> >   already declared in Request.
> >
> >   Correct the context mapping for the default servlet -- the requested
> >   resource should be passed as getServletPath(), not getPathInfo().
>
> It seems broken for servlet invocation.
> When I invoke http://127.0.0.1/servlet/org.exolab.slide.webdav.Webdav
>
> SlideDAV Request Info
>
> Encoding : ISO-8859-1
> Length : 0
> Type : null
>
> Parameters
>
> Protocol : HTTP/1.1
> Address : 127.0.0.1
> Host : 127.0.0.1
> Scheme : http
> Server Name : 127.0.0.1
> Server Port : 80
>
> Attributes
>
> HTTP Header Info
>
> Authentication Type : null
> HTTP Method : OPTIONS
> Path Info : null
> Path translated : null
> Query string : null
> Remote user : null
> Requested session id : null
> Request URI : /servlet
> Context path :
> Servlet path : /servlet
> User principal : null
>
> Servlet path and Request URI are incorrect.
> Context path should be equal to "/servlet", right ?
>

For the root context, context path should be "" (a zero-length string).  The
context path matches the "path=" attribute of your <Context> element in
conf/server.xml.

However, it looks like this is still wrong -- your servlet should see:

    Servlet path: /servlet/org.exolab.slide.webdav.Webdav
    Path info: null

in this scenario.  I will take a look at that problem.

>
> Remy
>

Craig


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


[Catalina] Re: cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/servlets DefaultServlet.java

Posted by Remy Maucherat <re...@exoffice.com>.
> craigmcc    00/04/30 18:53:55
> 
>   Modified:    proposals/catalina/src/share/org/apache/tomcat
>                         HttpRequest.java
>                proposals/catalina/src/share/org/apache/tomcat/core
>                         ApplicationContext.java LocalStrings.properties
>                         StandardContext.java StandardWrapperValve.java
>                proposals/catalina/src/share/org/apache/tomcat/servlets
>                         DefaultServlet.java
>   Added:       proposals/catalina/src/share/org/apache/tomcat/core
>                         ApplicationDispatcher.java WrappedRequest.java
>   Log:
>   Remove duplication method declaration from HttpRequest -- isSecure() is
>   already declared in Request.
>   
>   Correct the context mapping for the default servlet -- the requested
>   resource should be passed as getServletPath(), not getPathInfo().

It seems broken for servlet invocation.
When I invoke http://127.0.0.1/servlet/org.exolab.slide.webdav.Webdav

SlideDAV Request Info

Encoding : ISO-8859-1
Length : 0
Type : null

Parameters

Protocol : HTTP/1.1
Address : 127.0.0.1
Host : 127.0.0.1
Scheme : http
Server Name : 127.0.0.1
Server Port : 80

Attributes


HTTP Header Info

Authentication Type : null
HTTP Method : OPTIONS
Path Info : null
Path translated : null
Query string : null
Remote user : null
Requested session id : null
Request URI : /servlet
Context path :
Servlet path : /servlet
User principal : null

Servlet path and Request URI are incorrect.
Context path should be equal to "/servlet", right ?

Remy