vmassol     01/09/16 07:46:23

  Modified:    docs/framework/xdocs changes.xml todo.xml
               src/framework/servlet22/org/apache/cactus/server
                        HttpServletRequestWrapper.java
               src/framework/servlet23/org/apache/cactus/server
                        HttpServletRequestWrapper.java
               src/sample/share/org/apache/cactus/sample/unit
                        TestServletTestCase2.java
  Log:
  * added support for HttpServletRequest.getPathTranslated() (i.e. takes into account 
the simulated URL)
  * refactored HttpServletRequestWrapper
  
  Revision  Changes    Path
  1.50      +4 -0      jakarta-cactus/docs/framework/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/docs/framework/xdocs/changes.xml,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- changes.xml       2001/09/16 11:14:31     1.49
  +++ changes.xml       2001/09/16 14:46:23     1.50
  @@ -108,6 +108,10 @@
       </devs>
   
       <release version="1.2 in CVS">
  +      <action dev="VMA" type="add">
  +        <code>HttpServletRequestWrapper.getPathTranslated()</code> now takes
  +        into account any path info set up in <code>WebRequest.setURL()</code>.
  +      </action>
         <action dev="VMA" type="fix">
           Transform the <code>WebResponse.getText()</code> and
           <code>WebResponse.getTestAsArray()</code> so that they can be called
  
  
  
  1.54      +1 -7      jakarta-cactus/docs/framework/xdocs/todo.xml
  
  Index: todo.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/docs/framework/xdocs/todo.xml,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- todo.xml  2001/09/15 14:21:30     1.53
  +++ todo.xml  2001/09/16 14:46:23     1.54
  @@ -50,7 +50,7 @@
           ([EMAIL PROTECTED]) on the jakarta-commons mailing list (Subject
           "[cactus] Using Cactus with JBoss-2.2.1 with Embedded Tomcat"). The
           scripts need to be reworked so that the deployed test war is deployed
  -        within the <code>out</code> output directory and not to where
  +        within the <code>target</code> output directory and not to where
           JBoss/Tomcat is installed.
         </action>
         <action assigned-to="Vincent Massol">
  @@ -65,12 +65,6 @@
         <action assigned-to="Jari Worsley, Nicholas Lesiecki">
           Continue support for JSP Taglib. Possibly add some heper classes to
           help implement unit test for taglibs.
  -      </action>
  -      <action>
  -        Handle <code>getRealPath()</code>, <code>getPathTranslated()</code> in
  -        the <code>ServletRedirectorRequest</code> class. With the current
  -        version if you use these API, it will return the native path for the
  -        Servlet Redirector and not for your servlet being tested
         </action>
       </category>
   
  
  
  
  1.8       +4 -453    
jakarta-cactus/src/framework/servlet22/org/apache/cactus/server/HttpServletRequestWrapper.java
  
  Index: HttpServletRequestWrapper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/src/framework/servlet22/org/apache/cactus/server/HttpServletRequestWrapper.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HttpServletRequestWrapper.java    2001/09/14 20:11:21     1.7
  +++ HttpServletRequestWrapper.java    2001/09/16 14:46:23     1.8
  @@ -77,472 +77,23 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
    *
  - * @version $Id: HttpServletRequestWrapper.java,v 1.7 2001/09/14 20:11:21 pier Exp $
  + * @version $Id: HttpServletRequestWrapper.java,v 1.8 2001/09/16 14:46:23 vmassol 
Exp $
    */
  -public class HttpServletRequestWrapper implements HttpServletRequest
  +public class HttpServletRequestWrapper extends AbstractHttpServletRequestWrapper
   {
       /**
  -     * The real HTTP request
  -     */
  -    private HttpServletRequest request;
  -
  -    /**
  -     * The URL to simulate
  -     */
  -    private ServletURL url;
  -
  -    /**
  -     * The logger
  -     */
  -    private static Log logger =
  -        LogService.getInstance().
  -        getLog(HttpServletRequestWrapper.class.getName());
  -
  -    /**
        * Construct an <code>HttpServletRequest</code> instance that delegates
        * it's method calls to the request object passed as parameter and that
        * uses the URL passed as parameter to simulate a URL from which the request
        * would come from.
        *
        * @param theRequest the real HTTP request
  -     * @param theURL     the URL to simulate or <code>null</code> if none
  +     * @param theURL the URL to simulate or <code>null</code> if none
        */
       public HttpServletRequestWrapper(HttpServletRequest theRequest,
           ServletURL theURL)
  -    {
  -        this.request = theRequest;
  -        this.url = theURL;
  -    }
  -
  -    public HttpServletRequest getOriginalRequest()
  -    {
  -        return this.request;
  -    }
  -
  -    public boolean isRequestedSessionIdFromURL()
  -    {
  -        return this.request.isRequestedSessionIdFromURL();
  -    }
  -
  -    public Enumeration getLocales()
  -    {
  -        return this.request.getLocales();
  -    }
  -
  -    public String getHeader(String theName)
  -    {
  -        return this.request.getHeader(theName);
  -    }
  -
  -    /**
  -     * @return the context path from the simulated URL or the real context path
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getContextPath()
  -    {
  -        logger.entry("getContextPath()");
  -
  -        String result = this.request.getContextPath();
  -
  -        if (this.url != null) {
  -            if (this.url.getContextPath() != null) {
  -                result = this.url.getContextPath();
  -                logger.debug("Using simulated context : [" + result + "]");
  -            }
  -        }
  -
  -        logger.exit("getContextPath");
  -        return result;
  -    }
  -
  -    public String getScheme()
  -    {
  -        return this.request.getScheme();
  -    }
  -
  -    /**
  -     * @return the path info from the simulated URL or the real path info
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getPathInfo()
  -    {
  -        logger.entry("getPathInfo()");
  -
  -        String result = this.request.getPathInfo();
  -
  -        if (this.url != null) {
  -            result = this.url.getPathInfo();
  -            logger.debug("Using simulated PathInfo : [" + result + "]");
  -        }
  -
  -        logger.exit("getPathInfo");
  -        return result;
  -    }
  -
  -    public String getAuthType()
  -    {
  -        return this.request.getAuthType();
  -    }
  -
  -    /**
  -     * @return the server name from the simulated URL or the real server name
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getServerName()
  -    {
  -        logger.entry("getServerName()");
  -
  -        String result = this.request.getServerName();
  -
  -        if (this.url != null) {
  -            if (this.url.getServerName() != null) {
  -                result = this.url.getHost();
  -                logger.debug("Using simulated server name : [" + result +
  -                    "]");
  -            }
  -        }
  -
  -        logger.exit("getServerName");
  -        return result;
  -    }
  -
  -    public String getRealPath(String thePath)
  -    {
  -        return this.request.getRealPath(thePath);
  -    }
  -
  -    public HttpSession getSession()
  -    {
  -        return this.request.getSession();
  -    }
  -
  -    public HttpSession getSession(boolean isCreate)
  -    {
  -        return this.request.getSession(isCreate);
  -    }
  -
  -    public String getRemoteHost()
  -    {
  -        return this.request.getRemoteHost();
  -    }
  -
  -    public Enumeration getHeaderNames()
  -    {
  -        return this.request.getHeaderNames();
  -    }
  -
  -    public boolean isUserInRole(String theRole)
  -    {
  -        return this.request.isUserInRole(theRole);
  -    }
  -
  -    /**
  -     * @return the server port number from the simulated URL or the real server
  -     *         port number if a simulation URL has not been defined. If not
  -     *         port is defined, then port 80 is returned.
  -     */
  -    public int getServerPort()
  -    {
  -        logger.entry("getServerPort()");
  -
  -        int result = this.request.getServerPort();
  -
  -        if (this.url != null) {
  -            result = (this.url.getPort() == -1) ? 80 : this.url.getPort();
  -            logger.debug("Using simulated server port : [" + result + "]");
  -        }
  -
  -        logger.exit("getServerPort");
  -        return result;
  -    }
  -
  -    public BufferedReader getReader() throws IOException
  -    {
  -        return this.request.getReader();
  -    }
  -
  -    public int getContentLength()
  -    {
  -        return this.request.getContentLength();
  -    }
  -
  -    /**
  -     * @return the URI from the simulated URL or the real URI
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getRequestURI()
  -    {
  -        logger.entry("getRequestURI()");
  -
  -        String result = this.request.getRequestURI();
  -
  -        if (this.url != null) {
  -
  -            result = getContextPath() + 
  -                ((getServletPath() == null) ? "" : getServletPath()) + 
  -                ((getPathInfo() == null) ? "" : getPathInfo());
  -
  -            logger.debug("Using simulated request URI : [" + result + "]");
  -        }
  -
  -        logger.exit("getRequestURI");
  -        return result;
  -    }
  -
  -    public String[] getParameterValues(String theName)
  -    {
  -        return this.request.getParameterValues(theName);
  -    }
  -
  -    public boolean isRequestedSessionIdFromUrl()
  -    {
  -        return this.request.isRequestedSessionIdFromUrl();
  -    }
  -
  -    public String getContentType()
  -    {
  -        return this.request.getContentType();
  -    }
  -
  -    public Locale getLocale()
  -    {
  -        return this.request.getLocale();
  -    }
  -
  -    public void removeAttribute(String theName)
  -    {
  -        this.request.removeAttribute(theName);
  -    }
  -
  -    public String getParameter(String theName)
  -    {
  -        return this.request.getParameter(theName);
  -    }
  -
  -    /**
  -     * @return the servlet path from the simulated URL or the real servlet path
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getServletPath()
  -    {
  -        logger.entry("getServletPath()");
  -
  -        String result = this.request.getServletPath();
  -
  -        if (this.url != null) {
  -            result = this.url.getServletPath();
  -            logger.debug("Using simulated servlet path : [" + result +
  -                "]");
  -        }
  -
  -        logger.exit("getServletPath");
  -        return result;
  -    }
  -
  -    public boolean isRequestedSessionIdFromCookie()
  -    {
  -        return this.request.isRequestedSessionIdFromCookie();
  -    }
  -
  -    public ServletInputStream getInputStream() throws IOException
  -    {
  -        return this.request.getInputStream();
  -    }
  -
  -    public Principal getUserPrincipal()
  -    {
  -        return this.request.getUserPrincipal();
  -    }
  -
  -    public boolean isSecure()
  -    {
  -        return this.request.isSecure();
  -    }
  -
  -    public String getPathTranslated()
  -    {
  -        return this.request.getPathTranslated();
  -    }
  -
  -    public String getRemoteAddr()
  -    {
  -        return this.request.getRemoteAddr();
  -    }
  -
  -    public String getCharacterEncoding()
  -    {
  -        return this.request.getCharacterEncoding();
  -    }
  -
  -    public Enumeration getParameterNames()
  -    {
  -        return this.request.getParameterNames();
  -    }
  -
  -    public String getMethod()
  -    {
  -        return this.request.getMethod();
  -    }
  -
  -    public void setAttribute(String theName, Object theAttribute)
  -    {
  -        this.request.setAttribute(theName, theAttribute);
  -    }
  -
  -    public Object getAttribute(String theName)
  -    {
  -        return this.request.getAttribute(theName);
  -    }
  -
  -    public int getIntHeader(String theName)
  -    {
  -        return this.request.getIntHeader(theName);
  -    }
  -
  -    public boolean isRequestedSessionIdValid()
  -    {
  -        return this.request.isRequestedSessionIdValid();
  -    }
  -
  -    /**
  -     * @return the query string from the simulated URL or the real query
  -     *         string if a simulation URL has not been defined.
  -     */
  -    public String getQueryString()
  -    {
  -        logger.entry("getQueryString()");
  -
  -        String result = this.request.getQueryString();
  -
  -        if (this.url != null) {
  -            result = this.url.getQueryString();
  -            logger.debug("Using simulated query string : [" + result +
  -                "]");
  -        }
  -
  -        logger.exit("getQueryString");
  -        return result;
  -    }
  -
  -    public long getDateHeader(String theName)
  -    {
  -        return this.request.getDateHeader(theName);
  -    }
  -
  -    public Enumeration getAttributeNames()
  -    {
  -        return this.request.getAttributeNames();
  -    }
  -
  -    public String getRemoteUser()
  -    {
  -        return this.request.getRemoteUser();
  -    }
  -
  -    public String getProtocol()
  -    {
  -        return this.request.getProtocol();
  -    }
  -
  -    public Enumeration getHeaders(String theName)
  -    {
  -        return this.request.getHeaders(theName);
  -    }
  -
  -    public String getRequestedSessionId()
  -    {
  -        return this.request.getRequestedSessionId();
  -    }
  -
  -    /**
  -     * @return a wrapped request dispatcher instead of the real one, so that
  -     *         forward() and include() calls will use the wrapped dispatcher
  -     *         passing it the *original* request [this is needed for some
  -     *         servlet engine like Tomcat 3.x which do not support the new
  -     *         mechanism introduced by Servlet 2.3 Filters].
  -     */
  -    public RequestDispatcher getRequestDispatcher(String thePath)
  -    {
  -        logger.entry("getRequestDispatcher([" + thePath + "])");
  -
  -        // I hate it, but we have to write some logic here ! Ideally we
  -        // shouldn't have to do this as it is supposed to be done by the servlet
  -        // engine. However as we are simulating the request URL, we have to
  -        // provide it ... This is where we can see the limitation of Cactus
  -        // (it has to mock some parts of the servlet engine) !
  -
  -        if (thePath == null) {
  -            logger.exit("getRequestDispatcher");
  -            return null;
  -        }
  -
  -        RequestDispatcher dispatcher = null;
  -        String fullPath;
  -
  -        // The spec says that the path can be relative, in which case it will
  -        // be relative to the request. So for relative paths, we need to take 
  -        // into account the simulated URL (ServletURL).
  -        if (thePath.startsWith("/")) {
  -
  -            fullPath = thePath;
  -
  -        } else {
  -
  -         String pI = getPathInfo();
  -         if (pI == null) {
  -                fullPath = catPath(getServletPath(), thePath);
  -            } else {
  -                 fullPath = catPath(getServletPath() + pI, thePath);
  -            }
  -
  -             if (fullPath == null) {
  -                logger.exit("getRequestDispatcher");
  -                return null;
  -            }
  -        }
  -                
  -        logger.debug("Computed full path : [" + fullPath + "]");
  -
  -        dispatcher = new RequestDispatcherWrapper(
  -            this.request.getRequestDispatcher(fullPath));
  -
  -        logger.exit("getRequestDispatcher");
  -        return dispatcher;
  -    }
  -
  -    /**
  -     * Will concatenate 2 paths, dealing with ..
  -     * ( /a/b/c + d = /a/b/d, /a/b/c + ../d = /a/d ). Code borrowed from 
  -     * Tomcat 3.2.2 !
  -     *
  -     * @return null if error occurs
  -     */
  -    private String catPath(String lookupPath, String path)
  -    {
  -     // Cut off the last slash and everything beyond
  -         int index = lookupPath.lastIndexOf("/");
  -         lookupPath = lookupPath.substring(0, index);
  -     
  -         // Deal with .. by chopping dirs off the lookup path
  -         while (path.startsWith("../")) { 
  -             if (lookupPath.length() > 0) {
  -                     index = lookupPath.lastIndexOf("/");
  -                     lookupPath = lookupPath.substring(0, index);
  -             } else {
  -             // More ..'s than dirs, return null
  -             return null;
  -             }
  -         
  -         index = path.indexOf("../") + 3;
  -             path = path.substring(index);
  -         }
  -     
  -         return lookupPath + "/" + path;
  -    }
  -
  -    public javax.servlet.http.Cookie[] getCookies()
       {
  -        return this.request.getCookies();
  +        super(theRequest, theURL);
       }
   
   }
  
  
  
  1.9       +5 -452    
jakarta-cactus/src/framework/servlet23/org/apache/cactus/server/HttpServletRequestWrapper.java
  
  Index: HttpServletRequestWrapper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/src/framework/servlet23/org/apache/cactus/server/HttpServletRequestWrapper.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HttpServletRequestWrapper.java    2001/09/14 20:13:34     1.8
  +++ HttpServletRequestWrapper.java    2001/09/16 14:46:23     1.9
  @@ -76,488 +76,41 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
    *
  - * @version $Id: HttpServletRequestWrapper.java,v 1.8 2001/09/14 20:13:34 pier Exp $
  + * @version $Id: HttpServletRequestWrapper.java,v 1.9 2001/09/16 14:46:23 vmassol 
Exp $
    */
  -public class HttpServletRequestWrapper implements HttpServletRequest
  +public class HttpServletRequestWrapper extends AbstractHttpServletRequestWrapper
   {
       /**
  -     * The real HTTP request
  -     */
  -    private HttpServletRequest request;
  -
  -    /**
  -     * The URL to simulate
  -     */
  -    private ServletURL url;
  -
  -    /**
  -     * The logger
  -     */
  -    private static Log logger =
  -        LogService.getInstance().
  -        getLog(HttpServletRequestWrapper.class.getName());
  -
  -    /**
        * Construct an <code>HttpServletRequest</code> instance that delegates
        * it's method calls to the request object passed as parameter and that
        * uses the URL passed as parameter to simulate a URL from which the request
        * would come from.
        *
        * @param theRequest the real HTTP request
  -     * @param theURL     the URL to simulate or <code>null</code> if none
  +     * @param theURL the URL to simulate or <code>null</code> if none
        */
       public HttpServletRequestWrapper(HttpServletRequest theRequest,
           ServletURL theURL)
  -    {
  -        this.request = theRequest;
  -        this.url = theURL;
  -    }
  -
  -    public HttpServletRequest getOriginalRequest()
  -    {
  -        return this.request;
  -    }
  -
  -    public boolean isUserInRole(String theRole)
  -    {
  -        return this.request.isUserInRole(theRole);
  -    }
  -
  -    public boolean isRequestedSessionIdValid()
  -    {
  -        return this.request.isRequestedSessionIdValid();
  -    }
  -    public boolean isRequestedSessionIdFromUrl()
  -    {
  -        return this.request.isRequestedSessionIdFromUrl();
  -    }
  -
  -    public boolean isRequestedSessionIdFromURL()
  -    {
  -        return this.request.isRequestedSessionIdFromURL();
  -    }
  -
  -    public boolean isRequestedSessionIdFromCookie()
       {
  -        return this.request.isRequestedSessionIdFromCookie();
  +        super(theRequest, theURL);
       }
   
  -    public Principal getUserPrincipal()
  -    {
  -        return this.request.getUserPrincipal();
  -    }
  -
  -    public HttpSession getSession(boolean isCreate)
  -    {
  -        return this.request.getSession(isCreate);
  -    }
  -
  -    public HttpSession getSession()
  -    {
  -        return this.request.getSession();
  -    }
  -
  -    /**
  -     * @return the servlet path from the simulated URL or the real servlet path
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getServletPath()
  -    {
  -        logger.entry("getServletPath()");
  -
  -        String result = this.request.getServletPath();
  +    // Not modified methods --------------------------------------------------
   
  -        if (this.url != null) {
  -            result = this.url.getServletPath();
  -            logger.debug("Using simulated servlet path : [" + result +
  -                "]");
  -        }
  -
  -        logger.exit("getServletPath");
  -        return result;
  -    }
  -
  -    public String getRequestedSessionId()
  -    {
  -        return this.request.getRequestedSessionId();
  -    }
  -
       public StringBuffer getRequestURL()
       {
           return this.request.getRequestURL();
       }
   
  -    /**
  -     * @return the URI from the simulated URL or the real URI
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getRequestURI()
  -    {
  -        logger.entry("getRequestURI()");
  -
  -        String result = this.request.getRequestURI();
  -
  -        if (this.url != null) {
  -
  -            result = getContextPath() + 
  -                ((getServletPath() == null) ? "" : getServletPath()) + 
  -                ((getPathInfo() == null) ? "" : getPathInfo());
  -
  -            logger.debug("Using simulated request URI : [" + result + "]");
  -        }
  -
  -        logger.exit("getRequestURI");
  -        return result;
  -    }
  -
  -    public String getRemoteUser()
  -    {
  -        return this.request.getRemoteUser();
  -    }
  -
  -    /**
  -     * @return the query string from the simulated URL or the real query
  -     *         string if a simulation URL has not been defined.
  -     */
  -    public String getQueryString()
  -    {
  -        logger.entry("getQueryString()");
  -
  -        String result = this.request.getQueryString();
  -
  -        if (this.url != null) {
  -            result = this.url.getQueryString();
  -            logger.debug("Using simulated query string : [" + result +
  -                "]");
  -        }
  -
  -        logger.exit("getQueryString");
  -        return result;
  -    }
  -
  -    public String getPathTranslated()
  -    {
  -        return this.request.getPathTranslated();
  -    }
  -
  -    /**
  -     * @return the path info from the simulated URL or the real path info
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getPathInfo()
  -    {
  -        logger.entry("getPathInfo()");
  -
  -        String result = this.request.getPathInfo();
  -
  -        if (this.url != null) {
  -            result = this.url.getPathInfo();
  -            logger.debug("Using simulated PathInfo : [" + result + "]");
  -        }
  -
  -        logger.exit("getPathInfo");
  -        return result;
  -    }
  -
  -    public String getMethod()
  -    {
  -        return this.request.getMethod();
  -    }
  -
  -    public int getIntHeader(String theName)
  -    {
  -        return this.request.getIntHeader(theName);
  -    }
  -
  -    public Enumeration getHeaders(String theName)
  -    {
  -        return this.request.getHeaders(theName);
  -    }
  -
  -    public Enumeration getHeaderNames()
  -    {
  -        return this.request.getHeaderNames();
  -    }
  -
  -    public String getHeader(String theName)
  -    {
  -        return this.request.getHeader(theName);
  -    }
  -
  -    public long getDateHeader(String theName)
  -    {
  -        return this.request.getDateHeader(theName);
  -    }
  -
  -    public javax.servlet.http.Cookie[] getCookies()
  -    {
  -        return this.request.getCookies();
  -    }
  -
  -    /**
  -     * @return the context path from the simulated URL or the real context path
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getContextPath()
  -    {
  -        logger.entry("getContextPath()");
  -
  -        String result = this.request.getContextPath();
  -
  -        if (this.url != null) {
  -            if (this.url.getContextPath() != null) {
  -                result = this.url.getContextPath();
  -                logger.debug("Using simulated context : [" + result + "]");
  -            }
  -        }
  -
  -        logger.exit("getContextPath");
  -        return result;
  -    }
  -
  -    public String getAuthType()
  -    {
  -        return this.request.getAuthType();
  -    }
  -
       public void setCharacterEncoding(String env)
           throws UnsupportedEncodingException
       {
           this.request.setCharacterEncoding(env);
       }
   
  -    public void setAttribute(String theName, Object theAttribute)
  -    {
  -        this.request.setAttribute(theName, theAttribute);
  -    }
  -
  -    public void removeAttribute(String theName)
  -    {
  -        this.request.removeAttribute(theName);
  -    }
  -
  -    public boolean isSecure()
  -    {
  -        return this.request.isSecure();
  -    }
  -
  -    /**
  -     * @return the server port number from the simulated URL or the real server
  -     *         port number if a simulation URL has not been defined. If not
  -     *         port is defined, then port 80 is returned.
  -     */
  -    public int getServerPort()
  -    {
  -        logger.entry("getServerPort()");
  -
  -        int result = this.request.getServerPort();
  -
  -        if (this.url != null) {
  -            result = (this.url.getPort() == -1) ? 80 : this.url.getPort();
  -            logger.debug("Using simulated server port : [" + result + "]");
  -        }
  -
  -        logger.exit("getServerPort");
  -        return result;
  -    }
  -
  -    /**
  -     * @return the server name from the simulated URL or the real server name
  -     *         if a simulation URL has not been defined.
  -     */
  -    public String getServerName()
  -    {
  -        logger.entry("getServerName()");
  -
  -        String result = this.request.getServerName();
  -
  -        if (this.url != null) {
  -            if (this.url.getServerName() != null) {
  -                result = this.url.getHost();
  -                logger.debug("Using simulated server name : [" + result +
  -                    "]");
  -            }
  -        }
  -
  -        logger.exit("getServerName");
  -        return result;
  -    }
  -
  -    public String getScheme()
  -    {
  -        return this.request.getScheme();
  -    }
  -
  -    /**
  -     * @return a wrapped request dispatcher instead of the real one, so that
  -     *         forward() and include() calls will use the wrapped dispatcher
  -     *         passing it the *original* request [this is needed for some
  -     *         servlet engine like Tomcat 3.x which do not support the new
  -     *         mechanism introduced by Servlet 2.3 Filters].
  -     */
  -    public RequestDispatcher getRequestDispatcher(String thePath)
  -    {
  -        logger.entry("getRequestDispatcher([" + thePath + "])");
  -
  -        // I hate it, but we have to write some logic here ! Ideally we
  -        // shouldn't have to do this as it is supposed to be done by the servlet
  -        // engine. However as we are simulating the request URL, we have to
  -        // provide it ... This is where we can see the limitation of Cactus
  -        // (it has to mock some parts of the servlet engine) !
  -
  -        if (thePath == null) {
  -            logger.exit("getRequestDispatcher");
  -            return null;
  -        }
  -
  -        RequestDispatcher dispatcher = null;
  -        String fullPath;
  -
  -        // The spec says that the path can be relative, in which case it will
  -        // be relative to the request. So for relative paths, we need to take 
  -        // into account the simulated URL (ServletURL).
  -        if (thePath.startsWith("/")) {
  -
  -            fullPath = thePath;
  -
  -        } else {
  -
  -         String pI = getPathInfo();
  -         if (pI == null) {
  -                fullPath = catPath(getServletPath(), thePath);
  -            } else {
  -                 fullPath = catPath(getServletPath() + pI, thePath);
  -            }
  -
  -             if (fullPath == null) {
  -                logger.exit("getRequestDispatcher");
  -                return null;
  -            }
  -
  -        }
  -                
  -        logger.debug("Computed full path : [" + fullPath + "]");
  -
  -        dispatcher = new RequestDispatcherWrapper(
  -            this.request.getRequestDispatcher(fullPath));
  -
  -        logger.exit("getRequestDispatcher");
  -        return dispatcher;
  -    }
  -
  -    /**
  -     * Will concatenate 2 paths, dealing with ..
  -     * ( /a/b/c + d = /a/b/d, /a/b/c + ../d = /a/d ). Code borrowed from 
  -     * Tomcat 3.2.2 !
  -     *
  -     * @return null if error occurs
  -     */
  -    private String catPath(String lookupPath, String path)
  -    {
  -     // Cut off the last slash and everything beyond
  -         int index = lookupPath.lastIndexOf("/");
  -         lookupPath = lookupPath.substring(0, index);
  -     
  -         // Deal with .. by chopping dirs off the lookup path
  -         while (path.startsWith("../")) { 
  -             if (lookupPath.length() > 0) {
  -                     index = lookupPath.lastIndexOf("/");
  -                     lookupPath = lookupPath.substring(0, index);
  -             } else {
  -             // More ..'s than dirs, return null
  -             return null;
  -             }
  -         
  -         index = path.indexOf("../") + 3;
  -             path = path.substring(index);
  -         }
  -     
  -         return lookupPath + "/" + path;
  -    }
  -
  -    public String getRemoteHost()
  -    {
  -        return this.request.getRemoteHost();
  -    }
  -
  -    public String getRemoteAddr()
  -    {
  -        return this.request.getRemoteAddr();
  -    }
  -
  -    public String getRealPath(String thePath)
  -    {
  -        return this.request.getRealPath(thePath);
  -    }
  -
  -    public BufferedReader getReader() throws IOException
  -    {
  -        return this.request.getReader();
  -    }
  -
  -    public String getProtocol()
  -    {
  -        return this.request.getProtocol();
  -    }
  -
  -    public String[] getParameterValues(String theName)
  -    {
  -        return this.request.getParameterValues(theName);
  -    }
  -
  -    public Enumeration getParameterNames()
  -    {
  -        return this.request.getParameterNames();
  -    }
  -
       public Map getParameterMap()
       {
           return this.request.getParameterMap();
  -    }
  -
  -    public String getParameter(String theName)
  -    {
  -        return this.request.getParameter(theName);
  -    }
  -
  -    public Enumeration getLocales()
  -    {
  -        return this.request.getLocales();
  -    }
  -
  -    public Locale getLocale()
  -    {
  -        return this.request.getLocale();
  -    }
  -
  -    public ServletInputStream getInputStream() throws IOException
  -    {
  -        return this.request.getInputStream();
  -    }
  -
  -    public String getContentType()
  -    {
  -        return this.request.getContentType();
  -    }
  -
  -    public int getContentLength()
  -    {
  -        return this.request.getContentLength();
  -    }
  -
  -    public String getCharacterEncoding()
  -    {
  -        return this.request.getCharacterEncoding();
  -    }
  -
  -    public Enumeration getAttributeNames()
  -    {
  -        return this.request.getAttributeNames();
  -    }
  -
  -    public Object getAttribute(String theName)
  -    {
  -        return this.request.getAttribute(theName);
       }
   
   }
  
  
  
  1.16      +42 -10    
jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase2.java
  
  Index: TestServletTestCase2.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase2.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TestServletTestCase2.java 2001/09/16 11:11:03     1.15
  +++ TestServletTestCase2.java 2001/09/16 14:46:23     1.16
  @@ -77,7 +77,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
    *
  - * @version $Id: TestServletTestCase2.java,v 1.15 2001/09/16 11:11:03 vmassol Exp $
  + * @version $Id: TestServletTestCase2.java,v 1.16 2001/09/16 14:46:23 vmassol Exp $
    */
   public class TestServletTestCase2 extends ServletTestCase
   {
  @@ -266,15 +266,15 @@
           // [...]
           // Multiple message-header fields with the same field-name MAY be
           // present in a message if and only if the entire field-value for that
  -        // header field is defined as a comma-separated list [i.e., #(values)]. 
  -        // It MUST be possible to combine the multiple header fields into one 
  -        // "field-name: field-value" pair, without changing the semantics of 
  -        // the message, by appending each subsequent field-value to the first, 
  -        // each separated by a comma. The order in which header fields with the 
  -        // same field-name are received is therefore significant to the 
  -        // interpretation of the combined field value, and thus a proxy MUST 
  -        // NOT change the order of these field values when a message is 
  -        // forwarded. 
  +        // header field is defined as a comma-separated list [i.e., #(values)].
  +        // It MUST be possible to combine the multiple header fields into one
  +        // "field-name: field-value" pair, without changing the semantics of
  +        // the message, by appending each subsequent field-value to the first,
  +        // each separated by a comma. The order in which header fields with the
  +        // same field-name are received is therefore significant to the
  +        // interpretation of the combined field value, and thus a proxy MUST
  +        // NOT change the order of these field values when a message is
  +        // forwarded.
   
           // ... so it should be ok ...
   
  @@ -550,6 +550,38 @@
       {
           assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY,
               theResponse.getConnection().getResponseCode());
  +    }
  +
  +    //-------------------------------------------------------------------------
  +
  +    /**
  +     * Verify that <code>HttpServletRequestWrapper.getPathTranslated()</code>
  +     * takes into account the simulated URL (if any).
  +     *
  +     * @param theRequest the request object that serves to initialize the
  +     *                   HTTP connection to the server redirector.
  +     */
  +    public void beginGetPathTranslated(WebRequest theRequest)
  +    {
  +        theRequest.setURL("jakarta.apache.org", "/mywebapp", "/myservlet",
  +            "/test1/test2", "PARAM1=value1");
  +    }
  +
  +    /**
  +     * Verify that <code>HttpServletRequestWrapper.getPathTranslated()</code>
  +     * takes into account the simulated URL (if any).
  +     */
  +    public void testGetPathTranslated()
  +    {
  +        String nativePathInfo = File.separator + "test1" + File.separator +
  +            "test2";
  +
  +        String pathTranslated = request.getPathTranslated();
  +
  +        assertNotNull("Should not be null", pathTranslated);
  +        assert("Should end with [" + nativePathInfo + "] but got [" +
  +            pathTranslated + "] instead",
  +            pathTranslated.endsWith(nativePathInfo));
       }
   
   }
  
  
  

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

Reply via email to