Hey Kevin,

Be patient ! :) That was the first step towards being able to send binary
data ... I'll work today on the second part, i.e. add
WebRequest.setData(InputStream).
Question for you: any special content type we should we set for binary data
or the standard application/x-www-form-urlencoded one ?

-Vincent

----- Original Message -----
From: "Kevin Jones" <[EMAIL PROTECTED]>
To: "Vincent Massol" <[EMAIL PROTECTED]>
Sent: Saturday, October 20, 2001 7:59 AM
Subject: RE: cvs commit:
jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit
TestServletTestCase2.java


> Hi again,
>
> thanks for committing these - however I still see no way of sending non
> url-form-encoded data to a servlet (I want to send text/xml) or am I
missing
> something in my understanding of how cactus works?
>
> Kevin Jones
> Developmentor
> www.develop.com
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > Sent: 20 October 2001 00:07
> > To: [EMAIL PROTECTED]
> > Subject: cvs commit:
> > jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit
> > TestServletTestCase2.java
> >
> >
> > vmassol     01/10/19 16:06:35
> >
> >   Modified:    conf/sample/conf/test/servlet22 cactus.properties web.xml
> >                conf/sample/conf/test/servlet23 cactus.properties web.xml
> >                docs/framework/xdocs changes.xml
> >                src/framework/share/org/apache/cactus
AbstractTestCase.java
> >                         ServletURL.java WebRequest.java
> >                src/framework/share/org/apache/cactus/client
> >                         HttpClientHelper.java
> >                src/sample/servlet22/org/apache/cactus TestAll.java
> >                src/sample/share/org/apache/cactus/sample
> >                         TestSampleServlet.java
> >                src/sample/share/org/apache/cactus/sample/unit
> >                         TestServletTestCase2.java
> >   Log:
> >   * Cactus now use GET method to pass parameters by default
> >   * A new WebRequest.addParameter(name, value, method) has been added
> >   * WebRequest.setMethod() has been removed
> >   * All internal Cactus parameters are now passed in the URL query
string
> >
> >   (note: because of a big in HttpURLConnection, we cannot test
> > anymore code that returns status code for errors - it will be
> > corrected when we move to httpclient for making the http connections)
> >
> >   Revision  Changes    Path
> >   1.2       +2 -2
> > jakarta-cactus/conf/sample/conf/test/servlet22/cactus.properties
> >
> >   Index: cactus.properties
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/conf/sample/conf/test/servlet22/cactus.pr
> > operties,v
> >   retrieving revision 1.1
> >   retrieving revision 1.2
> >   diff -u -r1.1 -r1.2
> >   --- cactus.properties 2001/09/07 16:09:23 1.1
> >   +++ cactus.properties 2001/10/19 23:06:34 1.2
> >   @@ -9,7 +9,7 @@
> >    # application. In the example below, the context is "test".
> >
> >    # Servlet Redirector. Used by ServletTestCase test cases.
> >   -cactus.servletRedirectorURL =
> > http://localhost:@test.port@/test/ServletRedirector/
> >   +cactus.servletRedirectorURL =
> > http://localhost:@test.port@/test/ServletRedirector
> >
> >    # JSP Redirector. Used by JspTestCase test cases.
> >   -cactus.jspRedirectorURL =
> > http://localhost:@test.port@/test/JspRedirector/
> >   +cactus.jspRedirectorURL =
> > http://localhost:@test.port@/test/JspRedirector
> >
> >
> >
> >   1.4       +2 -2
> > jakarta-cactus/conf/sample/conf/test/servlet22/web.xml
> >
> >   Index: web.xml
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/conf/sample/conf/test/servlet22/web.xml,v
> >   retrieving revision 1.3
> >   retrieving revision 1.4
> >   diff -u -r1.3 -r1.4
> >   --- web.xml 2001/09/16 11:17:56 1.3
> >   +++ web.xml 2001/10/19 23:06:34 1.4
> >   @@ -26,12 +26,12 @@
> >
> >        <servlet-mapping>
> >            <servlet-name>ServletRedirector</servlet-name>
> >   -        <url-pattern>/ServletRedirector/</url-pattern>
> >   +        <url-pattern>/ServletRedirector</url-pattern>
> >        </servlet-mapping>
> >
> >        <servlet-mapping>
> >            <servlet-name>JspRedirector</servlet-name>
> >   -        <url-pattern>/JspRedirector/</url-pattern>
> >   +        <url-pattern>/JspRedirector</url-pattern>
> >        </servlet-mapping>
> >
> >    </web-app>
> >
> >
> >
> >   1.3       +2 -2
> > jakarta-cactus/conf/sample/conf/test/servlet23/cactus.properties
> >
> >   Index: cactus.properties
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/conf/sample/conf/test/servlet23/cactus.pr
> > operties,v
> >   retrieving revision 1.2
> >   retrieving revision 1.3
> >   diff -u -r1.2 -r1.3
> >   --- cactus.properties 2001/09/16 11:17:56 1.2
> >   +++ cactus.properties 2001/10/19 23:06:34 1.3
> >   @@ -9,10 +9,10 @@
> >    # application. In the example below, the context is "test".
> >
> >    # Servlet Redirector. Used by ServletTestCase test cases.
> >   -cactus.servletRedirectorURL =
> > http://localhost:@test.port@/test/ServletRedirector/
> >   +cactus.servletRedirectorURL =
> > http://localhost:@test.port@/test/ServletRedirector
> >
> >    # JSP Redirector. Used by JspTestCase test cases.
> >   -cactus.jspRedirectorURL =
> > http://localhost:@test.port@/test/JspRedirector/
> >   +cactus.jspRedirectorURL =
> > http://localhost:@test.port@/test/JspRedirector
> >
> >    # Filter Redirector. Used by FilterTestCase test cases.
> >
> >
> >
> >
> >   1.4       +3 -3
> > jakarta-cactus/conf/sample/conf/test/servlet23/web.xml
> >
> >   Index: web.xml
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/conf/sample/conf/test/servlet23/web.xml,v
> >   retrieving revision 1.3
> >   retrieving revision 1.4
> >   diff -u -r1.3 -r1.4
> >   --- web.xml 2001/09/16 11:17:56 1.3
> >   +++ web.xml 2001/10/19 23:06:34 1.4
> >   @@ -19,7 +19,7 @@
> >                 are happy with just any mapping.
> >
> >                 For example, the following would work with Tomcat :
> >   -             <url-pattern>/FilterRedirector/</url-pattern> -->
> >   +             <url-pattern>/FilterRedirector</url-pattern> -->
> >            <url-pattern>/test/filterRedirector.jsp</url-pattern>
> >        </filter-mapping>
> >
> >   @@ -43,12 +43,12 @@
> >
> >        <servlet-mapping>
> >            <servlet-name>ServletRedirector</servlet-name>
> >   -        <url-pattern>/ServletRedirector/</url-pattern>
> >   +        <url-pattern>/ServletRedirector</url-pattern>
> >        </servlet-mapping>
> >
> >        <servlet-mapping>
> >            <servlet-name>JspRedirector</servlet-name>
> >   -        <url-pattern>/JspRedirector/</url-pattern>
> >   +        <url-pattern>/JspRedirector</url-pattern>
> >        </servlet-mapping>
> >
> >    </web-app>
> >
> >
> >
> >   1.55      +27 -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.54
> >   retrieving revision 1.55
> >   diff -u -r1.54 -r1.55
> >   --- changes.xml 2001/10/19 21:11:34 1.54
> >   +++ changes.xml 2001/10/19 23:06:34 1.55
> >   @@ -119,6 +119,33 @@
> >
> >        <release version="1.3 in CVS">
> >          <action dev="VMA" type="remove">
> >   +        The <code>WebRequest.setMethod()</code> has been
> > removed as deprecating
> >   +        it would have led to potential error difficult to
> > locate (as Cactus
> >   +        default behaviour is now to pass parameter using GET,
> > whereas before
> >   +        it was passing them using POST).
> >   +      </action>
> >   +      <action dev="VMA" type="update">
> >   +        The existing <code>WebRequest.addParameter(name,
> > value)</code> is
> >   +        now passing the parameter in the URL query string by
> > default (same as
> >   +        calling <code>WebRequest.addParameter(name, value,
> >   +        WebRequest.GET_METHOD)</code>.
> >   +      </action>
> >   +      <action dev="VMA" type="add">
> >   +        Added a new <code>WebRequest.addParameter(name, value,
> > method)</code>
> >   +        where method is either "GET" or "POST". This let you
> > choose on a fine
> >   +        grain level, which method you'd like to use to pass a
> > given parameter.
> >   +      </action>
> >   +      <action dev="VMA" type="update">
> >   +        Changed the way Cactus passes internal parameters to
> > the redirectors.
> >   +        They were previously passed as POST parameters (in the
> > request body).
> >   +        They are now passed in the query string of the URL.
> > This is to prepare
> >   +        the path for supporting unit testing binary data sent
> > to servlets
> >   +        (like files, ...). Thanks to
> >   +        <link href="mailto:[EMAIL PROTECTED]";>Kevin
> > Jones</link> for raising
> >   +        awareness of the issue and thanks to
> >   +        <link href="mailto:[EMAIL PROTECTED]";>Alvin</link> for
> > providing a fix.
> >   +      </action>
> >   +      <action dev="VMA" type="remove">
> >            Removed <code>ServletTestRequest</code>. It was
> > deprecated in version 1.2 and is now
> >            removed in 1.3. You should use <code>WebRequest</code>
instead.
> >          </action>
> >
> >
> >
> >   1.12      +10 -4
> >
jakarta-cactus/src/framework/share/org/apache/cactus/AbstractTestCase.java
> >
> >   Index: AbstractTestCase.java
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/Abs
> > tractTestCase.java,v
> >   retrieving revision 1.11
> >   retrieving revision 1.12
> >   diff -u -r1.11 -r1.12
> >   --- AbstractTestCase.java 2001/10/19 21:11:34 1.11
> >   +++ AbstractTestCase.java 2001/10/19 23:06:34 1.12
> >   @@ -72,7 +72,7 @@
> >     *
> >     * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
> >     *
> >   - * @version $Id: AbstractTestCase.java,v 1.11 2001/10/19
> > 21:11:34 vmassol Exp $
> >   + * @version $Id: AbstractTestCase.java,v 1.12 2001/10/19
> > 23:06:34 vmassol Exp $
> >     */
> >    public abstract class AbstractTestCase extends TestCase
> >    {
> >   @@ -405,11 +405,17 @@
> >
> >            // Add the class name, the method name, the URL to simulate
and
> >            // automatic session creation flag to the request
> >   +
> >   +        // Note: All these pareameters are passed in the URL.
> > This is to allow
> >   +        // the user to send whatever he wants in the request
> > body. For example
> >   +        // a file, ...
> >            request.addParameter(ServiceDefinition.CLASS_NAME_PARAM,
> >   -            this.getClass().getName());
> >   -
> > request.addParameter(ServiceDefinition.METHOD_NAME_PARAM, name());
> >   +            this.getClass().getName(), WebRequest.GET_METHOD);
> >   +
> > request.addParameter(ServiceDefinition.METHOD_NAME_PARAM, name(),
> >   +            WebRequest.GET_METHOD);
> >
request.addParameter(ServiceDefinition.AUTOSESSION_NAME_PARAM,
> >   -            new Boolean(request.getAutomaticSession()).toString());
> >   +            new Boolean(request.getAutomaticSession()).toString(),
> >   +            WebRequest.GET_METHOD);
> >
> >            // Add the simulated URL (if one has been defined)
> >            if (request.getURL() != null) {
> >
> >
> >
> >   1.8       +15 -6
> > jakarta-cactus/src/framework/share/org/apache/cactus/ServletURL.java
> >
> >   Index: ServletURL.java
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/Ser
> > vletURL.java,v
> >   retrieving revision 1.7
> >   retrieving revision 1.8
> >   diff -u -r1.7 -r1.8
> >   --- ServletURL.java 2001/09/14 20:19:52 1.7
> >   +++ ServletURL.java 2001/10/19 23:06:34 1.8
> >   @@ -83,7 +83,7 @@
> >     *
> >     * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
> >     *
> >   - * @version $Id: ServletURL.java,v 1.7 2001/09/14 20:19:52 pier Exp $
> >   + * @version $Id: ServletURL.java,v 1.8 2001/10/19 23:06:34
> > vmassol Exp $
> >     */
> >    public class ServletURL
> >    {
> >   @@ -306,20 +306,29 @@
> >         */
> >        public void saveToRequest(WebRequest theRequest)
> >        {
> >   +        // Note: All these pareameters are passed in the URL.
> > This is to allow
> >   +        // the user to send whatever he wants in the request
> > body. For example
> >   +        // a file, ...
> >   +
> >            if (getServerName() != null) {
> >   -            theRequest.addParameter(URL_SERVER_NAME_PARAM,
> > getServerName());
> >   +            theRequest.addParameter(URL_SERVER_NAME_PARAM,
> > getServerName(),
> >   +                WebRequest.GET_METHOD);
> >            }
> >            if (getContextPath() != null) {
> >   -            theRequest.addParameter(URL_CONTEXT_PATH_PARAM,
> > getContextPath());
> >   +            theRequest.addParameter(URL_CONTEXT_PATH_PARAM,
> > getContextPath(),
> >   +                WebRequest.GET_METHOD);
> >            }
> >            if (getServletPath() != null) {
> >   -            theRequest.addParameter(URL_SERVLET_PATH_PARAM,
> > getServletPath());
> >   +            theRequest.addParameter(URL_SERVLET_PATH_PARAM,
> > getServletPath(),
> >   +                WebRequest.GET_METHOD);
> >            }
> >            if (getPathInfo() != null) {
> >   -            theRequest.addParameter(URL_PATH_INFO_PARAM,
> > getPathInfo());
> >   +            theRequest.addParameter(URL_PATH_INFO_PARAM,
getPathInfo(),
> >   +                WebRequest.GET_METHOD);
> >            }
> >            if (getQueryString() != null) {
> >   -            theRequest.addParameter(URL_QUERY_STRING_PARAM,
> > getQueryString());
> >   +            theRequest.addParameter(URL_QUERY_STRING_PARAM,
> > getQueryString(),
> >   +                WebRequest.GET_METHOD);
> >            }
> >        }
> >
> >
> >
> >
> >   1.6       +200 -62
> > jakarta-cactus/src/framework/share/org/apache/cactus/WebRequest.java
> >
> >   Index: WebRequest.java
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/Web
> > Request.java,v
> >   retrieving revision 1.5
> >   retrieving revision 1.6
> >   diff -u -r1.5 -r1.6
> >   --- WebRequest.java 2001/09/14 20:21:23 1.5
> >   +++ WebRequest.java 2001/10/19 23:06:34 1.6
> >   @@ -55,6 +55,8 @@
> >
> >    import java.util.*;
> >
> >   +import org.apache.cactus.util.*;
> >   +
> >    /**
> >     * Contains all HTTP request data for a test case. It is the data
that
> >     * will be sent to the server redirector and that will be
> > available to the test
> >   @@ -79,14 +81,19 @@
> >     *
> >     * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
> >     *
> >   - * @version $Id: WebRequest.java,v 1.5 2001/09/14 20:21:23 pier Exp $
> >   + * @version $Id: WebRequest.java,v 1.6 2001/10/19 23:06:34
> > vmassol Exp $
> >     */
> >    public class WebRequest
> >    {
> >   +    /**
> >   +     * The request parameters that need to be sent in the body (POST)
> >   +     */
> >   +    private Hashtable parametersPost = new Hashtable();
> >   +
> >        /**
> >   -     * The request parameters.
> >   +     * The request parameters that need to be sent in the URL (GET)
> >         */
> >   -    private Hashtable parameters = new Hashtable();
> >   +    private Hashtable parametersGet = new Hashtable();
> >
> >        /**
> >         * GET Method identifier.
> >   @@ -119,31 +126,6 @@
> >        private boolean isAutomaticSession = true;
> >
> >        /**
> >   -     * The chosen method for posting data (GET or POST)
> >   -     */
> >   -    private String method = POST_METHOD;
> >   -
> >   -    /**
> >   -     * @param theMethod the method to use to post data (GET or POST)
> >   -     */
> >   -    public void setMethod(String theMethod)
> >   -    {
> >   -        if (theMethod.equalsIgnoreCase(GET_METHOD)) {
> >   -            this.method = GET_METHOD;
> >   -        } else if (theMethod.equalsIgnoreCase(POST_METHOD)) {
> >   -            this.method = POST_METHOD;
> >   -        }
> >   -    }
> >   -
> >   -    /**
> >   -     * @return the method to use for posting data to the
> > server redirector.
> >   -     */
> >   -    public String getMethod()
> >   -    {
> >   -        return this.method;
> >   -    }
> >   -
> >   -    /**
> >         * @param isAutomaticSession whether the redirector servlet will
> >         *        automatically create the HTTP session or not.
> > Default is true.
> >         */
> >   @@ -224,46 +206,96 @@
> >
> >        /**
> >         * Adds a parameter to the request. It is possible to add
> > several times the
> >   -     * the same parameter name (the same as for the
> >   +     * the same parameter name, but with different value (the
> > same as for the
> >         * <code>HttpServletRequest</code>).
> >         *
> >   -     * @param theName  the parameter's name
> >   +     * @param theName the parameter's name
> >         * @param theValue the parameter's value
> >   -     */
> >   -    public void addParameter(String theName, String theValue)
> >   -    {
> >   +     * @param theMethod GET_METHOD or POST_METHOD. If
> > GET_METHOD then the
> >   +     *        parameter will be sent in the query string of the URL.
If
> >   +     *        POST_METHOD, it will be sent as a parameter in
> > the request body.
> >   +     */
> >   +    public void addParameter(String theName, String theValue,
> > String theMethod)
> >   +    {
> >   +        Hashtable parameters;
> >   +
> >   +        // Decide if the parameter is to be sent using in the
> > url or not
> >   +        if (theMethod.equalsIgnoreCase(WebRequest.POST_METHOD)) {
> >   +            parameters = this.parametersPost;
> >   +        } else if (theMethod.equalsIgnoreCase(WebRequest.GET_METHOD))
{
> >   +            parameters = this.parametersGet;
> >   +        } else {
> >   +            throw new ChainedRuntimeException("The method need
> > to be either " +
> >   +                "\"POST\" or \"GET\"");
> >   +        }
> >   +
> >            // If there is already a parameter of the same name, add the
> >            // new value to the Vector. If not, create a Vector an
> > add it to the
> >            // hashtable
> >
> >   -        if (this.parameters.containsKey(theName)) {
> >   -            Vector v = (Vector)this.parameters.get(theName);
> >   +        if (parameters.containsKey(theName)) {
> >   +            Vector v = (Vector)parameters.get(theName);
> >                v.addElement(theValue);
> >            } else {
> >                Vector v = new Vector();
> >                v.addElement(theValue);
> >   -            this.parameters.put(theName, v);
> >   +            parameters.put(theName, v);
> >            }
> >        }
> >
> >        /**
> >   +     * Adds a parameter to the request. The parameter is added
> > to the query
> >   +     * string of the URL.
> >   +     *
> >   +     * @param theName  the parameter's name
> >   +     * @param theValue the parameter's value
> >   +     *
> >   +     * @see WebRequest.addParameter(String, String, String)
> >   +     */
> >   +    public void addParameter(String theName, String theValue)
> >   +    {
> >   +        addParameter(theName, theValue, WebRequest.GET_METHOD);
> >   +    }
> >   +
> >   +    /**
> >   +     * @return the parameter names that will be passed in the
> > request body
> >   +     * (POST)
> >   +     */
> >   +    public Enumeration getParameterNamesPost()
> >   +    {
> >   +        return getParameterNames(this.parametersPost);
> >   +    }
> >   +
> >   +    /**
> >   +     * @return the parameter names that will be passed in the URL
(GET)
> >   +     */
> >   +    public Enumeration getParameterNamesGet()
> >   +    {
> >   +        return getParameterNames(this.parametersGet);
> >   +    }
> >   +
> >   +    /**
> >   +     * Returns all the values in the passed hashtable of parameters.
> >   +     *
> >   +     * @param theParameters the hashtable of parameters
> >         * @return the parameter names
> >         */
> >   -    public Enumeration getParameterNames()
> >   +    private Enumeration getParameterNames(Hashtable theParameters)
> >        {
> >   -        return this.parameters.keys();
> >   +        return theParameters.keys();
> >        }
> >
> >        /**
> >   -     * Returns the first value corresponding to this parameter's
name.
> >   +     * Returns the first value corresponding to this
> > parameter's name (provided
> >   +     * this parameter is passed in the URL).
> >         *
> >   -     * @param  theName the parameter's name
> >   +     * @param theName the parameter's name
> >         * @return the first value corresponding to this
> > parameter's name or null
> >   -     *         if not found
> >   +     *         if not found in the list of parameters to be
> > sent in the URL
> >         */
> >   -    public String getParameter(String theName)
> >   +    public String getParameterGet(String theName)
> >        {
> >   -        String[] values = getParameterValues(theName);
> >   +        String[] values = getParameterValuesGet(theName);
> >
> >            if (values != null) {
> >                return values[0];
> >   @@ -273,17 +305,66 @@
> >        }
> >
> >        /**
> >   -     * Returns all the values associated with this parameter's name.
> >   +     * Returns the first value corresponding to this
> > parameter's name (provided
> >   +     * this parameter is passed in the request body - POST).
> >         *
> >   -     * @param  theName the parameter's name
> >   -     * @return the values corresponding to this parameter's
> > name or null if not
> >   -     *         found
> >   +     * @param theName the parameter's name
> >   +     * @return the first value corresponding to this
> > parameter's name or null
> >   +     *         if not found in the list of parameters to be
> > sent in the request
> >   +     *         body
> >   +     */
> >   +    public String getParameterPost(String theName)
> >   +    {
> >   +        String[] values = getParameterValuesPost(theName);
> >   +
> >   +        if (values != null) {
> >   +            return values[0];
> >   +        }
> >   +
> >   +        return null;
> >   +    }
> >   +
> >   +    /**
> >   +     * Returns all the values corresponding to this
> > parameter's name (provided
> >   +     * this parameter is passed in the URL).
> >   +     *
> >   +     * @param theName the parameter's name
> >   +     * @return the first value corresponding to this
> > parameter's name or null
> >   +     *         if not found in the list of parameters to be
> > sent in the URL
> >         */
> >   -    public String[] getParameterValues(String theName)
> >   +    public String[] getParameterValuesGet(String theName)
> >        {
> >   -        if (this.parameters.containsKey(theName)) {
> >   +        return getParameterValues(theName, this.parametersGet);
> >   +    }
> >   +
> >   +    /**
> >   +     * Returns all the values corresponding to this
> > parameter's name (provided
> >   +     * this parameter is passed in the request body - POST).
> >   +     *
> >   +     * @param theName the parameter's name
> >   +     * @return the first value corresponding to this
> > parameter's name or null
> >   +     *         if not found in the list of parameters to be
> > sent in the request
> >   +     *         body
> >   +     */
> >   +   public String[] getParameterValuesPost(String theName)
> >   +   {
> >   +       return getParameterValues(theName, this.parametersPost);
> >   +   }
> >   +
> >   +    /**
> >   +     * Returns all the values corresponding to this
> > parameter's name in the
> >   +     * provided hashtable.
> >   +     *
> >   +     * @param theName the parameter's name
> >   +     * @param theParameters the hashtable containing the parameters
> >   +     * @return the first value corresponding to this
> > parameter's name or null
> >   +     *         if not found in the passed hashtable
> >   +     */
> >   +    private String[] getParameterValues(String theName,
> > Hashtable theParameters)
> >   +    {
> >   +        if (theParameters.containsKey(theName)) {
> >
> >   -            Vector v = (Vector)this.parameters.get(theName);
> >   +            Vector v = (Vector)theParameters.get(theName);
> >
> >                Object[] objs = new Object[v.size()];
> >                v.copyInto(objs);
> >   @@ -478,15 +559,32 @@
> >
> >            // Append cookies
> >            buffer.append("cookies = [");
> >   -        Enumeration cookies = getCookies().elements();
> >   -        while (cookies.hasMoreElements()) {
> >   -            Cookie cookie = (Cookie)cookies.nextElement();
> >   -            buffer.append("[" + cookie + "]");
> >   -        }
> >   +        buffer.append(toStringAppendCookies());
> >            buffer.append("], ");
> >
> >            // Append headers
> >            buffer.append("headers = [");
> >   +        buffer.append(toStringAppendHeaders());
> >   +        buffer.append("], ");
> >   +
> >   +        // Append parameters
> >   +        buffer.append("GET parameters = [");
> >   +        buffer.append(toStringAppendParametersGet());
> >   +        buffer.append("], ");
> >   +        buffer.append("POST parameters = [");
> >   +        buffer.append(toStringAppendParametersPost());
> >   +        buffer.append("]");
> >   +
> >   +        return buffer.toString();
> >   +    }
> >   +
> >   +    /**
> >   +     * @return a string representation of the headers
> >   +     */
> >   +    private String toStringAppendHeaders()
> >   +    {
> >   +        StringBuffer buffer = new StringBuffer();
> >   +
> >            Enumeration headers = getHeaderNames();
> >            while (headers.hasMoreElements()) {
> >                buffer.append("[");
> >   @@ -499,18 +597,59 @@
> >                buffer.append("[" +
> > headerValues[headerValues.length - 1] + "]]");
> >                buffer.append("]");
> >            }
> >   -        buffer.append("], ");
> >
> >   -        buffer.append("method = [" + getMethod() + "], ");
> >   +        return buffer.toString();
> >   +    }
> >
> >   +    /**
> >   +     * @return a string representation of the cookies
> >   +     */
> >   +    private String toStringAppendCookies()
> >   +    {
> >   +        StringBuffer buffer = new StringBuffer();
> >
> >   -        // Append parameters
> >   -        buffer.append("parameters = [");
> >   -        Enumeration parameters = getParameterNames();
> >   +        Enumeration cookies = getCookies().elements();
> >   +        while (cookies.hasMoreElements()) {
> >   +            Cookie cookie = (Cookie)cookies.nextElement();
> >   +            buffer.append("[" + cookie + "]");
> >   +        }
> >   +
> >   +        return buffer.toString();
> >   +    }
> >   +
> >   +    /**
> >   +     * @return a string representation of the parameters to be
> > added in the
> >   +     *         request body
> >   +     */
> >   +    private String toStringAppendParametersPost()
> >   +    {
> >   +        return toStringAppendParameters(this.parametersPost);
> >   +    }
> >   +
> >   +    /**
> >   +     * @return a string representation of the parameters to be
> > added in the
> >   +     *         URL
> >   +     */
> >   +    private String toStringAppendParametersGet()
> >   +    {
> >   +        return toStringAppendParameters(this.parametersGet);
> >   +    }
> >   +
> >   +    /**
> >   +     * @param theParameters the HTTP parameters
> >   +     * @return a string representation of the HTTP parameters passed
as
> >   +     *         parameters
> >   +     */
> >   +    private String toStringAppendParameters(Hashtable theParameters)
> >   +    {
> >   +        StringBuffer buffer = new StringBuffer();
> >   +
> >   +        Enumeration parameters = getParameterNames(theParameters);
> >            while (parameters.hasMoreElements()) {
> >                buffer.append("[");
> >                String parameterName = (String)parameters.nextElement();
> >   -            String[] parameterValues =
> > getParameterValues(parameterName);
> >   +            String[] parameterValues =
> > getParameterValues(parameterName,
> >   +                theParameters);
> >                buffer.append("[" + parameterName + "] = [");
> >                for (int i = 0; i < parameterValues.length - 1; i++) {
> >                    buffer.append("[" + parameterValues[i] + "], ");
> >   @@ -519,7 +658,6 @@
> >                    "]]");
> >                buffer.append("]");
> >            }
> >   -        buffer.append("]");
> >
> >            return buffer.toString();
> >        }
> >
> >
> >
> >   1.12      +73 -68
> > jakarta-cactus/src/framework/share/org/apache/cactus/client/HttpCl
> > ientHelper.java
> >
> >   Index: HttpClientHelper.java
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/cli
> > ent/HttpClientHelper.java,v
> >   retrieving revision 1.11
> >   retrieving revision 1.12
> >   diff -u -r1.11 -r1.12
> >   --- HttpClientHelper.java 2001/10/05 18:01:21 1.11
> >   +++ HttpClientHelper.java 2001/10/19 23:06:35 1.12
> >   @@ -70,7 +70,7 @@
> >     *
> >     * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
> >     *
> >   - * @version $Id: HttpClientHelper.java,v 1.11 2001/10/05
> > 18:01:21 vmassol Exp $
> >   + * @version $Id: HttpClientHelper.java,v 1.12 2001/10/19
> > 23:06:35 vmassol Exp $
> >     */
> >    public class HttpClientHelper
> >    {
> >   @@ -107,28 +107,78 @@
> >        }
> >
> >        /**
> >   -     * Add the parameters to the request using a GET method.
> >   +     * Calls the Servlet Redirector.
> >   +     *
> >   +     * @param theRequest the request containing all data to pass to
the
> >   +     *                   server redirector.
> >         *
> >   +     * @exception Throwable if an unexpected error occured
> >   +     */
> >   +    public HttpURLConnection connect(WebRequest theRequest)
> >   +        throws Throwable
> >   +    {
> >   +        logger.entry("connect(" + theRequest + ")");
> >   +
> >   +        URL url = new URL(this.url);
> >   +
> >   +        // Add the parameters that need to be passed as part of the
URL
> >   +        url = addParametersGet(theRequest, url);
> >   +
> >   +        HttpURLConnection connection =
> > (HttpURLConnection)url.openConnection();
> >   +
> >   +        connection.setDoInput(true);
> >   +
> >   +        // Choose the method that we will use to post data :
> >   +        // - If at least one parameter is to be sent in the
> > request body, then
> >   +        //   we are doing a POST.
> >   +        if (theRequest.getParameterNamesPost().hasMoreElements()) {
> >   +            connection.setDoOutput(true);
> >   +        } else {
> >   +            connection.setDoOutput(false);
> >   +        }
> >   +
> >   +        connection.setUseCaches(false);
> >   +
> >   +        // Add the other header fields
> >   +        addHeaders(theRequest, connection);
> >   +
> >   +        // Add the cookies
> >   +        addCookies(theRequest, connection);
> >   +
> >   +        // Add the POST parameters
> >   +        addParametersPost(theRequest, connection);
> >   +
> >   +        // Open the connection and get the result
> >   +        connection.connect();
> >   +
> >   +        logger.exit("connect");
> >   +        return connection;
> >   +    }
> >   +
> >   +    /**
> >   +     * Add the HTTP parameters that need to be passed in the
> > query string of
> >   +     * the URL.
> >   +     *
> >         * @param theRequest the request containing all data to
> > pass to the server
> >         *        redirector.
> >         * @param theURL the URL used to connect to the server
redirector.
> >         * @return the new URL
> >         */
> >   -    private URL addParametersUsingGet(WebRequest theRequest,
> > URL theURL)
> >   +    private URL addParametersGet(WebRequest theRequest, URL theURL)
> >            throws Throwable
> >        {
> >            // If no parameters, then exit
> >   -        if (!theRequest.getParameterNames().hasMoreElements()) {
> >   +        if (!theRequest.getParameterNamesGet().hasMoreElements()) {
> >                return theURL;
> >            }
> >
> >            StringBuffer queryString = new StringBuffer();
> >
> >   -        Enumeration keys = theRequest.getParameterNames();
> >   +        Enumeration keys = theRequest.getParameterNamesGet();
> >
> >            if (keys.hasMoreElements()) {
> >                String key = (String)keys.nextElement();
> >   -            String[] values = theRequest.getParameterValues(key);
> >   +            String[] values = theRequest.getParameterValuesGet(key);
> >                queryString.append(key);
> >                queryString.append('=');
> >                queryString.append(URLEncoder.encode(values[0]));
> >   @@ -142,7 +192,7 @@
> >
> >            while (keys.hasMoreElements()) {
> >                String key = (String)keys.nextElement();
> >   -            String[] values = theRequest.getParameterValues(key);
> >   +            String[] values = theRequest.getParameterValuesGet(key);
> >                for (int i = 0; i < values.length; i++) {
> >                    queryString.append('&');
> >                    queryString.append(key);
> >   @@ -150,12 +200,18 @@
> >                    queryString.append(URLEncoder.encode(values[i]));
> >                }
> >            }
> >   +
> >   +        String file = theURL.getFile();
> >   +
> >   +        // Remove the trailing "/" if there is one
> >   +        if (file.endsWith("/")) {
> >   +            file = file.substring(0, file.length() - 1);
> >   +        }
> >
> >   -        String file;
> >            if (theURL.toString().indexOf("?") > 0) {
> >   -            file = theURL.getFile() + "&" + queryString.toString();
> >   +            file = file + "&" + queryString.toString();
> >            } else {
> >   -            file = theURL.getFile() + "?" + queryString.toString();
> >   +            file = file + "?" + queryString.toString();
> >            }
> >
> >            return new URL(theURL.getProtocol(), theURL.getHost(),
> >   @@ -163,17 +219,17 @@
> >        }
> >
> >        /**
> >   -     * Add the parameters to the request using a POST method.
> >   +     * Add the HTTP parameters that need to be passed in the
> > request body.
> >         *
> >         * @param theRequest the request containing all data to
> > pass to the server
> >         *        redirector.
> >         * @param theConnection the HTTP connection
> >         */
> >   -    private void addParametersUsingPost(WebRequest theRequest,
> >   +    private void addParametersPost(WebRequest theRequest,
> >            URLConnection theConnection) throws Throwable
> >        {
> >            // If no parameters, then exit
> >   -        if (!theRequest.getParameterNames().hasMoreElements()) {
> >   +        if (!theRequest.getParameterNamesPost().hasMoreElements()) {
> >                return;
> >            }
> >
> >   @@ -196,11 +252,11 @@
> >
> >            StringBuffer queryString = new StringBuffer();
> >
> >   -        Enumeration keys = theRequest.getParameterNames();
> >   +        Enumeration keys = theRequest.getParameterNamesPost();
> >
> >            if (keys.hasMoreElements()) {
> >                String key = (String)keys.nextElement();
> >   -            String[] values = theRequest.getParameterValues(key);
> >   +            String[] values = theRequest.getParameterValuesPost(key);
> >                queryString.append(key);
> >                queryString.append('=');
> >                queryString.append(URLEncoder.encode(values[0]));
> >   @@ -214,7 +270,7 @@
> >
> >            while (keys.hasMoreElements()) {
> >                String key = (String)keys.nextElement();
> >   -            String[] values = theRequest.getParameterValues(key);
> >   +            String[] values = theRequest.getParameterValuesPost(key);
> >                for (int i = 0; i < values.length; i++) {
> >                    queryString.append('&');
> >                    queryString.append(key);
> >   @@ -244,7 +300,7 @@
> >            if (!cookies.isEmpty()) {
> >
> >                // transform the Cactus cookies into HttpClient cookies
> >   -            org.apache.commons.httpclient.Cookie[] httpclientCookies
=
> >   +            org.apache.commons.httpclient.Cookie[] httpclientCookies
=
> >                    new
> > org.apache.commons.httpclient.Cookie[cookies.size()];
> >                for (int i = 0; i < cookies.size(); i++) {
> >                    org.apache.cactus.Cookie cactusCookie =
> >   @@ -400,57 +456,6 @@
> >                theConnection.setRequestProperty(key,
> > fullHeaderValue.toString());
> >
> >            }
> >   -    }
> >   -
> >   -    /**
> >   -     * Calls the Servlet Redirector.
> >   -     *
> >   -     * @param theRequest the request containing all data to pass to
the
> >   -     *                   server redirector.
> >   -     *
> >   -     * @exception Throwable if an unexpected error occured
> >   -     */
> >   -    public HttpURLConnection connect(WebRequest theRequest)
> >   -        throws Throwable
> >   -    {
> >   -        logger.entry("connect(" + theRequest + ")");
> >   -
> >   -        URL url = new URL(this.url);
> >   -
> >   -        // If the method is GET, add the parameters to the URL
> >   -        if (theRequest.getMethod().equals(theRequest.GET_METHOD)) {
> >   -            url = addParametersUsingGet(theRequest, url);
> >   -        }
> >   -
> >   -        HttpURLConnection connection =
> > (HttpURLConnection)url.openConnection();
> >   -
> >   -        connection.setDoInput(true);
> >   -
> >   -        // Choose the method that we will use to post data
> >   -        if (theRequest.getMethod().equals(theRequest.POST_METHOD)) {
> >   -            connection.setDoOutput(true);
> >   -        } else {
> >   -            connection.setDoOutput(false);
> >   -        }
> >   -
> >   -        connection.setUseCaches(false);
> >   -
> >   -        // Add the other header fields
> >   -        addHeaders(theRequest, connection);
> >   -
> >   -        // Add the cookies
> >   -        addCookies(theRequest, connection);
> >   -
> >   -        // Add the POST parameters
> >   -        if (theRequest.getMethod().equals(theRequest.POST_METHOD)) {
> >   -            addParametersUsingPost(theRequest, connection);
> >   -        }
> >   -
> >   -        // Open the connection and get the result
> >   -        connection.connect();
> >   -
> >   -        logger.exit("connect");
> >   -        return connection;
> >        }
> >
> >    }
> >
> >
> >
> >   1.5       +2 -1
> > jakarta-cactus/src/sample/servlet22/org/apache/cactus/TestAll.java
> >
> >   Index: TestAll.java
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/src/sample/servlet22/org/apache/cactus/Te
> > stAll.java,v
> >   retrieving revision 1.4
> >   retrieving revision 1.5
> >   diff -u -r1.4 -r1.5
> >   --- TestAll.java 2001/09/25 09:12:52 1.4
> >   +++ TestAll.java 2001/10/19 23:06:35 1.5
> >   @@ -61,7 +61,7 @@
> >     *
> >     * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
> >     *
> >   - * @version $Id: TestAll.java,v 1.4 2001/09/25 09:12:52 vmassol Exp $
> >   + * @version $Id: TestAll.java,v 1.5 2001/10/19 23:06:35 vmassol Exp $
> >     */
> >    public class TestAll extends TestCase
> >    {
> >   @@ -113,6 +113,7 @@
> >
> >
suite.addTest(org.apache.cactus.sample.unit.TestServletTestCase4.suite());
> >
> >
suite.addTest(org.apache.cactus.sample.unit.TestServletTestCase5.suite());
> >
> > suite.addTest(org.apache.cactus.sample.unit.TestServletTestCaseSpe
> > cific.suite());
> >   +//
> > suite.addTest(org.apache.cactus.sample.unit.TestServletTestCase_Ht
> > tpUnit.suite());
> >
> >            // JspTestCase tests
> >
> > suite.addTest(org.apache.cactus.sample.unit.TestJspTestCase.suite());
> >
> >
> >
> >   1.12      +17 -15
> > jakarta-cactus/src/sample/share/org/apache/cactus/sample/TestSampl
> > eServlet.java
> >
> >   Index: TestSampleServlet.java
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/src/sample/share/org/apache/cactus/sample
> > /TestSampleServlet.java,v
> >   retrieving revision 1.11
> >   retrieving revision 1.12
> >   diff -u -r1.11 -r1.12
> >   --- TestSampleServlet.java 2001/09/22 14:19:17 1.11
> >   +++ TestSampleServlet.java 2001/10/19 23:06:35 1.12
> >   @@ -68,7 +68,7 @@
> >     *
> >     * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
> >     *
> >   - * @version $Id: TestSampleServlet.java,v 1.11 2001/09/22
> > 14:19:17 vmassol Exp $
> >   + * @version $Id: TestSampleServlet.java,v 1.12 2001/10/19
> > 23:06:35 vmassol Exp $
> >     */
> >    public class TestSampleServlet extends ServletTestCase
> >    {
> >   @@ -131,30 +131,32 @@
> >
> >        /**
> >         * Verify that we can simulate a POST request to a
> > servlet. Note that
> >   -     * the POST method is the default method so we don't need
> > to initialize
> >   -     * any parameter in <code>beginPostMethod()</code>.
> >   +     * we send a parameter to force a POST.
> >   +     *
> >   +     * @param theRequest the request object that serves to
> > initialize the
> >   +     *                   HTTP connection to the server redirector.
> >         */
> >   -    public void testPostMethod()
> >   +    public void beginPostMethod(WebRequest theRequest)
> >        {
> >   -        SampleServlet servlet = new SampleServlet();
> >   -        assertEquals("POST", servlet.checkMethod(request));
> >   +        theRequest.addParameter("param", "value",
> > WebRequest.POST_METHOD);
> >        }
> >
> >   -
> > //----------------------------------------------------------------
> > ---------
> >   -
> >        /**
> >   -     * Verify that we can simulate a GET request to a servlet.
> >   -     *
> >   -     * @param theRequest the request object that serves to
> > initialize the
> >   -     *                   HTTP connection to the server redirector.
> >   +     * Verify that we can simulate a POST request to a
> > servlet. Note that
> >   +     * we send a parameter to force a POST. Otherwise Cactus
> > will do a GET
> >   +     * by default.
> >         */
> >   -    public void beginGetMethod(WebRequest theRequest)
> >   +    public void testPostMethod()
> >        {
> >   -        theRequest.setMethod(WebRequest.GET_METHOD);
> >   +        SampleServlet servlet = new SampleServlet();
> >   +        assertEquals("POST", servlet.checkMethod(request));
> >        }
> >
> >   +
> > //----------------------------------------------------------------
> > ---------
> >   +
> >        /**
> >   -     * Verify that we can simulate a GET request to a servlet
> >   +     * Verify that we can simulate a GET request to a servlet.
> > Note: Cactus
> >   +     * does a GET by default.
> >         */
> >        public void testGetMethod()
> >        {
> >
> >
> >
> >   1.17      +6 -4
> > jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/Test
> > ServletTestCase2.java
> >
> >   Index: TestServletTestCase2.java
> >   ===================================================================
> >   RCS file:
> > /home/cvs/jakarta-cactus/src/sample/share/org/apache/cactus/sample
> > /unit/TestServletTestCase2.java,v
> >   retrieving revision 1.16
> >   retrieving revision 1.17
> >   diff -u -r1.16 -r1.17
> >   --- TestServletTestCase2.java 2001/09/16 14:46:23 1.16
> >   +++ TestServletTestCase2.java 2001/10/19 23:06:35 1.17
> >   @@ -77,7 +77,7 @@
> >     *
> >     * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
> >     *
> >   - * @version $Id: TestServletTestCase2.java,v 1.16 2001/09/16
> > 14:46:23 vmassol Exp $
> >   + * @version $Id: TestServletTestCase2.java,v 1.17 2001/10/19
> > 23:06:35 vmassol Exp $
> >     */
> >    public class TestServletTestCase2 extends ServletTestCase
> >    {
> >   @@ -506,7 +506,8 @@
> >         */
> >        public void testStatusCode()
> >        {
> >   -        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
> >   +// FIXME: use HttpClient for http connection
> >   +//        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
> >        }
> >
> >        /**
> >   @@ -524,8 +525,9 @@
> >        public void endStatusCode(WebResponse theResponse)
> >            throws IOException
> >        {
> >   -        assertEquals(HttpServletResponse.SC_UNAUTHORIZED,
> >   -            theResponse.getConnection().getResponseCode());
> >   +// FIXME: use HttpClient for http connection
> >   +//        assertEquals(HttpServletResponse.SC_UNAUTHORIZED,
> >   +//            theResponse.getConnection().getResponseCode());
> >        }
> >
> >
> > //----------------------------------------------------------------
> > ---------
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>

Reply via email to