vmassol     2003/06/07 03:08:04

  Modified:    samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit
                        TestSetURL.java
               framework/src/test/share/org/apache/cactus
                        TestServletURL.java
               framework/src/java/share/org/apache/cactus ServletURL.java
               framework/src/java/share/org/apache/cactus/server
                        AbstractHttpServletRequestWrapper.java
  Log:
  Verify that the servlet path used in the simulation URL has the correct format.
  
  Revision  Changes    Path
  1.6       +11 -7     
jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestSetURL.java
  
  Index: TestSetURL.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestSetURL.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestSetURL.java   7 Jun 2003 09:27:41 -0000       1.5
  +++ TestSetURL.java   7 Jun 2003 10:08:04 -0000       1.6
  @@ -245,23 +245,27 @@
       //-------------------------------------------------------------------------
   
       /**
  -     * Verify that if the context path is null in <code>setURL()</code> the
  -     * real context path will be used.
  +     * Verify that if the context path and the servlet paths are null in 
  +     * <code>setURL()</code> the real values coming from the Servlet
  +     * Redirector will be used instead.
        *
        * @param theRequest the request object that serves to initialize the
        *                   HTTP connection to the server redirector.
        */
  -    public void beginSimulatedURLNullContextPath(WebRequest theRequest)
  +    public void beginSimulatedURLNullContextAndServletPaths(
  +        WebRequest theRequest)
       {
           theRequest.setURL(null, null, null, null, null);
       }
   
       /**
  -     * Verify that if the context path is null in <code>setURL()</code> the
  -     * real context path will be used.
  +     * Verify that if the context path and the servlet paths are null in 
  +     * <code>setURL()</code> the real values coming from the Servlet
  +     * Redirector will be used instead.
        */
  -    public void testSimulatedURLNullContextPath()
  +    public void testSimulatedURLNullContextAndServletPaths()
       {
           assertNotNull(request.getContextPath());       
  +        assertNotNull(request.getServletPath());       
       }
   }
  
  
  
  1.11      +28 -1     
jakarta-cactus/framework/src/test/share/org/apache/cactus/TestServletURL.java
  
  Index: TestServletURL.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestServletURL.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestServletURL.java       7 Jun 2003 09:27:41 -0000       1.10
  +++ TestServletURL.java       7 Jun 2003 10:08:04 -0000       1.11
  @@ -132,6 +132,33 @@
       }
   
       /**
  +     * Verify that if the servlet path is not empty or null it must start with
  +     * a "/" character.
  +     */
  +    public void testSetServletPathFirstCharacterNotForwardSlash()
  +    {
  +        try 
  +        {
  +            new ServletURL(null, null, "invalidservletpath", null, null);
  +            fail("The servlet path must start with a \"/\" character");
  +        }
  +        catch (IllegalArgumentException expected)
  +        {
  +            assertEquals("The Servlet Path must start with a \"/\" character.", 
  +                expected.getMessage());
  +        }       
  +    }
  +
  +    /**
  +     * Verify that the servlet path can be an empty string.
  +     */
  +    public void testSetServletPathEmptyString()
  +    {
  +        ServletURL servletURL = new ServletURL(null, null, "", null, null);
  +        assertEquals("", servletURL.getServletPath());
  +    }
  +
  +    /**
        * Verify that the <code>getHost()</code> method is returning the correct
        * host when a port is specified and that the <code>getPort()</code>
        * method returns the specified port.
  
  
  
  1.13      +19 -6     
jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletURL.java
  
  Index: ServletURL.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletURL.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ServletURL.java   7 Jun 2003 09:27:41 -0000       1.12
  +++ ServletURL.java   7 Jun 2003 10:08:04 -0000       1.13
  @@ -223,13 +223,15 @@
        *                      i.e. this is the name that will be returned by the
        *                      <code>HttpServletRequest.getContextPath()</code>.
        *                      Can be null. If null, then the context from the
  -     *                      Servlet Redirector will be returned.
  +     *                      Servlet Redirector will be used.
        *                      Format: "/" + name or an empty string for the 
        *                      default context. Must not end with a "/" character.
        * @param theServletPath the servlet path in the URL to simulate,
        *                      i.e. this is the name that will be returned by the
        *                      <code>HttpServletRequest.getServletPath()</code>.
  -     *                      Can be null. Format : "/" + name.
  +     *                      Can be null. If null, then the servlet path from 
  +     *                      the Servlet Redirector will be used.
  +     *                      Format : "/" + name or an empty string.
        * @param thePathInfo   the path info in the URL to simulate, i.e. this is
        *                      the name that will be returned by the
        *                      <code>HttpServletRequest.getPathInfo()</code>. Can
  @@ -264,13 +266,15 @@
        *                      i.e. this is the name that will be returned by the
        *                      <code>HttpServletRequest.getContextPath()</code>.
        *                      Can be null. If null, then the context from the
  -     *                      Servlet Redirector will be returned.
  +     *                      Servlet Redirector will be used.
        *                      Format: "/" + name or an empty string for the 
        *                      default context. Must not end with a "/" character.
        * @param theServletPath the servlet path in the URL to simulate,
        *                      i.e. this is the name that will be returned by the
        *                      <code>HttpServletRequest.getServletPath()</code>.
  -     *                      Can be null. Format : "/" + name.
  +     *                      Can be null. If null, then the servlet path from 
  +     *                      the Servlet Redirector will be used.
  +     *                      Format : "/" + name or an empty string.
        * @param thePathInfo   the path info in the URL to simulate, i.e. this is
        *                      the name that will be returned by the
        *                      <code>HttpServletRequest.getPathInfo()</code>. Can
  @@ -469,12 +473,21 @@
        * Sets the servlet path in the URL to simulate, ie this is the name that
        * will be returned by the <code>HttpServletRequest.getServletPath()</code>.
        * If not set, the servlet path from the Servlet Redirector will be
  -     * returned. Format : "/" + name.
  +     * returned. Format : "/" + name or an empty string.
        *
        * @param theServletPath the servlet path to simulate
        */
       public void setServletPath(String theServletPath)
       {
  +        if ((theServletPath != null) && (theServletPath.length() > 0))
  +        {
  +            if (!theServletPath.startsWith("/"))
  +            {
  +                throw new IllegalArgumentException("The Servlet Path must"
  +                    + " start with a \"/\" character.");
  +            }            
  +        }
  +
           this.servletPath = theServletPath;
       }
   
  
  
  
  1.14      +8 -10     
jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractHttpServletRequestWrapper.java
  
  Index: AbstractHttpServletRequestWrapper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractHttpServletRequestWrapper.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AbstractHttpServletRequestWrapper.java    7 Jun 2003 09:27:41 -0000       1.13
  +++ AbstractHttpServletRequestWrapper.java    7 Jun 2003 10:08:04 -0000       1.14
  @@ -167,8 +167,8 @@
       /**
        * @return the context path from the simulated URL or the real context path
        *         if a simulation URL has not been defined. The real context path
  -     *         will be returned if the simulated URL as defined a null value
  -     *         for the context path.
  +     *         will be returned if the context path defined in the simulated 
  +     *         URL has a null value.
        */
       public String getContextPath()
       {
  @@ -273,20 +273,18 @@
   
       /**
        * @return the servlet path from the simulated URL or the real servlet path
  -     *         if a simulation URL has not been defined.
  +     *         if a simulation URL has not been defined. The real servlet path
  +     *         will be returned if the servlet path defined in the simulated 
  +     *         URL has a null value.
        */
       public String getServletPath()
       {
  -        String result;
  +        String result = this.request.getServletPath();
   
  -        if (this.url != null)
  +        if ((this.url != null) && (this.url.getServletPath() != null))
           {
               result = this.url.getServletPath();
               LOGGER.debug("Using simulated servlet path : [" + result + "]");
  -        }
  -        else
  -        {
  -            result = this.request.getServletPath();
           }
   
           return result;
  
  
  

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

Reply via email to