You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2002/05/22 21:53:51 UTC

cvs commit: jakarta-cactus/sample-servlet/src/unit/share/org/apache/cactus/unit TestServletTestCase2.java

vmassol     02/05/22 12:53:51

  Modified:    documentation/docs/xdocs changes.xml
               framework/src/java/share/org/apache/cactus
                        WebTestResult.java
               framework/src/java/share/org/apache/cactus/server
                        AbstractHttpServletRequestWrapper.java
               sample-servlet/src/unit/share/org/apache/cactus/unit
                        TestServletTestCase2.java
  Log:
  fixed bug with non-serializable object put in servlet context (reported by Patrick Lightbody [plightbo@hotmail.com]) and added feature to be able to simulate remote host ip address and name (asked by Brette, Marc [Marc.Brette@mkms.xerox.com]).
  
  Revision  Changes    Path
  1.17      +11 -0     jakarta-cactus/documentation/docs/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/documentation/docs/xdocs/changes.xml,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- changes.xml	19 May 2002 20:34:14 -0000	1.16
  +++ changes.xml	22 May 2002 19:53:51 -0000	1.17
  @@ -48,6 +48,17 @@
       </devs>
   
       <release version="1.4 in CVS">
  +      <action dev="VMA" type="fix" due-to="Patrick Lightbody" due-to-email="plightbo@hotmail.com">
  +        Fixed bug where the Test Result object which is put in the Servlet
  +        Context was not serializable. This might cause some trouble with some
  +        containers.
  +      </action>
  +      <action dev="VMA" type="add" due-to="Marc Brette" due-to-email="Marc.Brette@mkms.xerox.com">
  +        Added simulation of Remote IP address and Remote Host Name, i.e. you
  +        can now control what <code>request.getRemoteAddr()</code> and
  +        <code>request.getRemoteHost()</code> will return. That is useful if
  +        your code depends on these values.
  +      </action>
         <action dev="VMA" type="update">
           It is now possible to specify the Cactus properties as System
           properties (the property names are the same as the ones in
  
  
  
  1.3       +3 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/WebTestResult.java
  
  Index: WebTestResult.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/WebTestResult.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WebTestResult.java	21 Apr 2002 12:45:44 -0000	1.2
  +++ WebTestResult.java	22 May 2002 19:53:51 -0000	1.3
  @@ -58,6 +58,7 @@
   
   import java.io.PrintWriter;
   import java.io.StringWriter;
  +import java.io.Serializable;
   
   /**
    * Represent the result of the execution of the Test class by the
  @@ -66,9 +67,9 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: WebTestResult.java,v 1.2 2002/04/21 12:45:44 vmassol Exp $
  + * @version $Id: WebTestResult.java,v 1.3 2002/05/22 19:53:51 vmassol Exp $
    */
  -public class WebTestResult
  +public class WebTestResult implements Serializable
   {
       /**
        * Name of the exception class if an error occurred
  
  
  
  1.3       +69 -17    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractHttpServletRequestWrapper.java	28 Mar 2002 15:35:49 -0000	1.2
  +++ AbstractHttpServletRequestWrapper.java	22 May 2002 19:53:51 -0000	1.3
  @@ -78,7 +78,7 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: AbstractHttpServletRequestWrapper.java,v 1.2 2002/03/28 15:35:49 vmassol Exp $
  + * @version $Id: AbstractHttpServletRequestWrapper.java,v 1.3 2002/05/22 19:53:51 vmassol Exp $
    */
   public abstract class AbstractHttpServletRequestWrapper
           implements HttpServletRequest
  @@ -94,12 +94,26 @@
       protected ServletURL url;
   
       /**
  +     * Remote IP address to simulate (if any)
  +     * @see #setRemoteIPAddress(String)
  +     */
  +    protected String remoteIPAddress;
  +
  +    /**
  +     * Remote Host name to simulate (if any)
  +     * @see #setRemoteHostName(String)
  +     */
  +    protected String remoteHostName;
  +
  +    /**
        * The logger
        */
       private static final Log LOGGER =
           LogService.getInstance().
           getLog(AbstractHttpServletRequestWrapper.class.getName());
   
  +    // New methods not in the interface --------------------------------------
  +
       /**
        * Construct an <code>HttpServletRequest</code> instance that delegates
        * it's method calls to the request object passed as parameter and that
  @@ -124,6 +138,28 @@
           return this.request;
       }
   
  +    /**
  +     * Simulates the remote IP address (i.e. the client IP address).
  +     *
  +     * @param theRemoteIPAddress the simulated IP address in string format.
  +     *        Exemple : "127.0.0.1"
  +     */
  +    public void setRemoteIPAddress(String theRemoteIPAddress)
  +    {
  +        this.remoteIPAddress = theRemoteIPAddress;
  +    }
  +
  +    /**
  +     * Simulates the remote host name(i.e. the client host name).
  +     *
  +     * @param theRemoteHostName the simulated host name in string format.
  +     *        Exemple : "atlantis"
  +     */
  +    public void setRemoteHostName(String theRemoteHostName)
  +    {
  +        this.remoteHostName = theRemoteHostName;
  +    }
  +
       // Modified methods ------------------------------------------------------
   
       /**
  @@ -381,6 +417,38 @@
           return theLookupPath + "/" + thePath;
       }
   
  +    /**
  +     * @return the simulated remote IP address if any or the real one.
  +     *
  +     * @see HttpServletRequest#getRemoteAddr()
  +     */
  +    public String getRemoteAddr()
  +    {
  +        String remoteIPAddress;
  +        if (this.remoteIPAddress != null) {
  +            remoteIPAddress = this.remoteIPAddress;
  +        } else {
  +            remoteIPAddress = this.request.getRemoteAddr();
  +        }
  +        return remoteIPAddress;
  +    }
  +
  +    /**
  +     * @return the simulated remote host name if any or the real one.
  +     *
  +     * @see HttpServletRequest#getRemoteHost()
  +     */
  +    public String getRemoteHost()
  +    {
  +        String remoteHostName;
  +        if (this.remoteHostName != null) {
  +            remoteHostName = this.remoteHostName;
  +        } else {
  +            remoteHostName = this.request.getRemoteHost();
  +        }
  +        return remoteHostName;
  +    }
  +
       // Not modified methods --------------------------------------------------
   
       /**
  @@ -496,14 +564,6 @@
       }
   
       /**
  -     * @see HttpServletRequest#getRemoteHost()
  -     */
  -    public String getRemoteHost()
  -    {
  -        return this.request.getRemoteHost();
  -    }
  -
  -    /**
        * @see HttpServletRequest#getReader()
        */
       public BufferedReader getReader() throws IOException
  @@ -581,14 +641,6 @@
       public boolean isSecure()
       {
           return this.request.isSecure();
  -    }
  -
  -    /**
  -     * @see HttpServletRequest#getRemoteAddr()
  -     */
  -    public String getRemoteAddr()
  -    {
  -        return this.request.getRemoteAddr();
       }
   
       /**
  
  
  
  1.4       +16 -1     jakarta-cactus/sample-servlet/src/unit/share/org/apache/cactus/unit/TestServletTestCase2.java
  
  Index: TestServletTestCase2.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/sample-servlet/src/unit/share/org/apache/cactus/unit/TestServletTestCase2.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestServletTestCase2.java	10 Apr 2002 00:26:20 -0000	1.3
  +++ TestServletTestCase2.java	22 May 2002 19:53:51 -0000	1.4
  @@ -86,7 +86,7 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: TestServletTestCase2.java,v 1.3 2002/04/10 00:26:20 vmassol Exp $
  + * @version $Id: TestServletTestCase2.java,v 1.4 2002/05/22 19:53:51 vmassol Exp $
    */
   public class TestServletTestCase2 extends ServletTestCase
   {
  @@ -733,6 +733,21 @@
       public void testSetContentTypeHeader()
       {
           assertEquals("text/xml", request.getContentType());
  +    }
  +
  +    //-------------------------------------------------------------------------
  +
  +    /**
  +     * Verify that we can simulate the client remote IP address and the client
  +     * remote host name.
  +     */
  +    public void testRemoteClientCheck()
  +    {
  +        request.setRemoteIPAddress("192.168.0.1");
  +        request.setRemoteHostName("atlantis");
  +
  +        assertEquals("192.168.0.2", request.getRemoteAddr());
  +        assertEquals("xxx", request.getRemoteHost());
       }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>