markt       2005/04/10 11:22:56

  Modified:    catalina/src/share/org/apache/catalina/core
                        ApplicationDispatcher.java
                        ApplicationHttpRequest.java
  Log:
  Fix bug 22013. RequestDispatcher.forward doesn't work with a relative path on
  a forwarded request
  - Patch supplied by Cedric Benazech
  
  Revision  Changes    Path
  1.33      +3 -2      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java
  
  Index: ApplicationDispatcher.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- ApplicationDispatcher.java        26 Aug 2004 21:31:21 -0000      1.32
  +++ ApplicationDispatcher.java        10 Apr 2005 18:22:56 -0000      1.33
  @@ -861,7 +861,8 @@
           if ((current instanceof ApplicationHttpRequest) ||
               (current instanceof HttpRequest) ||
               (current instanceof HttpServletRequest))
  -            wrapper = new ApplicationHttpRequest((HttpServletRequest) 
current);
  +            wrapper = new ApplicationHttpRequest(
  +                    (HttpServletRequest) current, context);
           else
               wrapper = new ApplicationRequest(current);
           if (previous == null)
  
  
  
  1.16      +51 -8     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java
  
  Index: ApplicationHttpRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ApplicationHttpRequest.java       15 Jan 2005 20:27:05 -0000      1.15
  +++ ApplicationHttpRequest.java       10 Apr 2005 18:22:56 -0000      1.16
  @@ -23,8 +23,12 @@
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
  +
  +import javax.servlet.RequestDispatcher;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletRequestWrapper;
  +
  +import org.apache.catalina.Context;
   import org.apache.catalina.Globals;
   import org.apache.catalina.util.Enumerator;
   import org.apache.catalina.util.RequestUtil;
  @@ -49,7 +53,6 @@
   
   class ApplicationHttpRequest extends HttpServletRequestWrapper {
   
  -
       // ------------------------------------------------------- Static 
Variables
   
   
  @@ -62,24 +65,28 @@
         Globals.QUERY_STRING_ATTR };
   
   
  -    // ----------------------------------------------------------- 
Constructors
   
  +    // ----------------------------------------------------------- 
Constructors
   
       /**
  -     * Construct a new wrapped request around the specified servlet request.
  +     * Construct a new wrapped request around the specified servlet request 
in
  +     * the specified context.
        *
        * @param request The servlet request being wrapped
  +     * @param context The Context this ApplicationHttpRequest is associated 
with
        */
  -    public ApplicationHttpRequest(HttpServletRequest request) {
  -
  +    public ApplicationHttpRequest(HttpServletRequest request, Context 
context) {
           super(request);
           setRequest(request);
  -
  +        this.context = context;
       }
   
  -
       // ----------------------------------------------------- Instance 
Variables
   
  +    /**
  +     * The Context this ApplicationHttpRequest is associated with.
  +     */
  +    protected Context context;
   
       /**
        * The request attributes for this request.  This is initialized from the
  @@ -377,6 +384,42 @@
   
   
       /**
  +     * 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) {
  +
  +        if (context == null)
  +            return (null);
  +
  +        // If the path is already context-relative, just pass it through
  +        if (path == null)
  +            return (null);
  +        else if (path.startsWith("/"))
  +            return (context.getServletContext().getRequestDispatcher(path));
  +
  +        // Convert a request-relative path to a context-relative one
  +        String servletPath = (String) 
getAttribute(Globals.SERVLET_PATH_ATTR);
  +        if (servletPath == null)
  +            servletPath = getServletPath();
  +
  +        int pos = servletPath.lastIndexOf('/');
  +        String relative = null;
  +        if (pos >= 0) {
  +            relative = RequestUtil.normalize
  +                (servletPath.substring(0, pos + 1) + path);
  +        } else {
  +            relative = RequestUtil.normalize(servletPath + path);
  +        }
  +
  +        return (context.getServletContext().getRequestDispatcher(relative));
  +
  +    }
  +    
  +    
  +    /**
        * Perform a shallow copy of the specified Map, and return the result.
        *
        * @param orig Origin Map to be copied
  
  
  

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

Reply via email to