Hi,

  Here are a set of patches for review.  They should NOT be committed
to the repository yet (so there is no [PATCH] in the subject).

Goal: update Cactus to send Cactus specific information to the servlet 
redirector using the query string for both GET and POST requests.

Tested with JDK 1.3.0 on SunOS 5.8 with servlets 2.2 and Tomcat 3.2.3

Consequences:

1)
  The POST method seems to require data actually  being sent through
the output stream otherwise the server interprets the request as a GET 
request.

  Originally for a POST request the Cactus parameters were sent
through the output stream so this was always interepreted as a POST
request.

  Now, test cases must explicitly send parameters for the default POST 
request to actually be recieved by the server as a POST request.

  See test case 'testPostMethod' in TestSampleServer.java.




2)
  The 'testStatusCode' in TestServletTestCase2.java fails with:


     [java]     [junit] Testcase: testStatusCode took 0.105 sec
     [java]     [junit]         Caused an ERROR
     [java]     [junit] 
http://localhost:8080/test/ServletRedirector/?ServletTestRedirector_TestClass=org.apache.cactus.sample.unit.TestServletTestCase2&ServletTestRedirector_Service=CALL_TEST&ServletTestRedirector_AutomaticSession=true&ServletTestRedirector_TestMethod=testStatusCode
     [java]     [junit] java.io.FileNotFoundException: 
http://localhost:8080/test/ServletRedirector/?ServletTestRedirector_TestClass=org.apache.cactus.sample.unit.TestServletTestCase2&ServletTestRedirector_Service=CALL_TEST&ServletTestRedirector_AutomaticSession=true&ServletTestRedirector_TestMethod=testStatusCode
     [java]     [junit]         at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:545)
     [java]     [junit]         at 
org.apache.cactus.client.AutoReadHttpURLConnection.getInputStream(AutoReadHttpURLConnection.java:127)
     [java]     [junit]         at 
org.apache.cactus.client.AbstractHttpClient.doTest(AbstractHttpClient.java:136)
     [java]     [junit]         at 
org.apache.cactus.AbstractTestCase.runGenericTest(AbstractTestCase.java:422)
     [java]     [junit]         at 
org.apache.cactus.ServletTestCase.runTest(ServletTestCase.java:130)
     [java]     [junit]         at 
org.apache.cactus.AbstractTestCase.runBare(AbstractTestCase.java:371)
     [java]     [junit]         at 
junit.framework.TestResult$1.protect(TestResult.java:106)
     [java]     [junit]         at 
junit.framework.TestResult.runProtected(TestResult.java:124)
     [java]     [junit]         at junit.framework.TestResult.run(TestResult.java:109)
     [java]     [junit]         at junit.framework.TestCase.run(TestCase.java:131)
     [java]     [junit]         at 
junit.framework.TestSuite.runTest(TestSuite.java:173)
     [java]     [junit]         at junit.framework.TestSuite.run(TestSuite.java:168)
     [java]     [junit]         at 
junit.framework.TestSuite.runTest(TestSuite.java:173)
     [java]     [junit]         at junit.framework.TestSuite.run(TestSuite.java:168)
     [java]     [junit]         at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:231)
     [java]     [junit]         at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:409)
     [java]     [junit] 


  Any ideas why?

  Do the patches work with other jdk/servlet container/OS
combinations?

  Are there any other consequences or limitations caused by this
patch?

  What is the preferred way of sending multi-file patch messages?

  Should [PATCH] appear in the subject it the patch is not complete?


  Thanks for the help.


Alvin.

127c127
<         theRequest.addParameter(ServiceDefinition.SERVICE_NAME_PARAM,
---
>         theRequest.addCactusParameter(ServiceDefinition.SERVICE_NAME_PARAM,
143c143
<         resultsRequest.addParameter(ServiceDefinition.SERVICE_NAME_PARAM,
---
>         resultsRequest.addCactusParameter(ServiceDefinition.SERVICE_NAME_PARAM,
214,215c214,217
<         String className = this.webImplicitObjects.getHttpServletRequest().
<             getParameter(ServiceDefinition.CLASS_NAME_PARAM);
---
>         String query = this.webImplicitObjects.getHttpServletRequest().
>             getQueryString();
>         String className = ServletURL.
>             getQueryStringParameter(query, ServiceDefinition.CLASS_NAME_PARAM);
238,239c240,243
<         String methodName = this.webImplicitObjects.getHttpServletRequest().
<             getParameter(ServiceDefinition.METHOD_NAME_PARAM);
---
>         String query = this.webImplicitObjects.getHttpServletRequest().
>             getQueryString();
>         String methodName = ServletURL.
>             getQueryStringParameter(query, ServiceDefinition.METHOD_NAME_PARAM);
262,263c266,269
<         String autoSession = this.webImplicitObjects.getHttpServletRequest().
<             getParameter(ServiceDefinition.AUTOSESSION_NAME_PARAM);
---
>         String query = this.webImplicitObjects.getHttpServletRequest().
>             getQueryString();
>         String autoSession = ServletURL.
>             getQueryStringParameter(query, ServiceDefinition.AUTOSESSION_NAME_PARAM);
350c356
< }
\ No newline at end of file
---
> }
408c408
<         request.addParameter(ServiceDefinition.CLASS_NAME_PARAM,
---
>         request.addCactusParameter(ServiceDefinition.CLASS_NAME_PARAM,
410,411c410,411
<         request.addParameter(ServiceDefinition.METHOD_NAME_PARAM, name());
<         request.addParameter(ServiceDefinition.AUTOSESSION_NAME_PARAM,
---
>         request.addCactusParameter(ServiceDefinition.METHOD_NAME_PARAM, name());
>         request.addCactusParameter(ServiceDefinition.AUTOSESSION_NAME_PARAM,
169,170c169,171
<         String serviceName =
<             theRequest.getParameter(ServiceDefinition.SERVICE_NAME_PARAM);
---
>         String query = theRequest.getQueryString();
>         String serviceName = ServletURL.
>             getQueryStringParameter(query, ServiceDefinition.SERVICE_NAME_PARAM);
185c186
< }
\ No newline at end of file
---
> }
419a420,422
>         // Add Cactus parameters to query string
>         url = addCactusParameters(theRequest, url);
> 
455c458,511
< 
---
>     
>     /**
>      * Add the Cactus parameters to the request query string.
>      *
>      * @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 addCactusParameters(WebRequest theRequest, URL theURL)
>         throws Throwable
>     {
>         logger.entry("addCactusParameters(" + theRequest + "," + theURL + ")");
>         
>         // If no parameters, the exit
>         if (!theRequest.getCactusParameterNames().hasMoreElements()) {
>             logger.exit("addCactusParameters");
>             return theURL;
>         }
>         
>         StringBuffer queryString = new StringBuffer();
>         
>         Enumeration keys = theRequest.getCactusParameterNames();
>         
>         if (keys.hasMoreElements()) {
>             String key = (String)keys.nextElement();
>             String value = theRequest.getCactusParameter(key);
>             queryString.append(key);
>             queryString.append('=');
>             queryString.append(URLEncoder.encode(value));
>         }
>         
>         while (keys.hasMoreElements()) {
>             String key = (String)keys.nextElement();
>             String value = theRequest.getCactusParameter(key);
>             queryString.append('&');
>             queryString.append(key);
>             queryString.append('=');
>             queryString.append(URLEncoder.encode(value));
>         }
>         
>         String file;
>         if (theURL.toString().indexOf("?") > 0) {
>             file = theURL.getFile() + "&" + queryString.toString();
>         } else {
>             file = theURL.getFile() + "?" + queryString.toString();
>         }
>         
>         logger.exit("addCactusParameters");
>         return new URL(theURL.getProtocol(), theURL.getHost(),
>                        theURL.getPort(), file);
>         
>     }
>     
310c310
<             theRequest.addParameter(URL_SERVER_NAME_PARAM, getServerName());
---
>             theRequest.addCactusParameter(URL_SERVER_NAME_PARAM, getServerName());
313c313
<             theRequest.addParameter(URL_CONTEXT_PATH_PARAM, getContextPath());
---
>             theRequest.addCactusParameter(URL_CONTEXT_PATH_PARAM, getContextPath());
316c316
<             theRequest.addParameter(URL_SERVLET_PATH_PARAM, getServletPath());
---
>             theRequest.addCactusParameter(URL_SERVLET_PATH_PARAM, getServletPath());
319c319
<             theRequest.addParameter(URL_PATH_INFO_PARAM, getPathInfo());
---
>             theRequest.addCactusParameter(URL_PATH_INFO_PARAM, getPathInfo());
322c322
<             theRequest.addParameter(URL_QUERY_STRING_PARAM, getQueryString());
---
>             theRequest.addCactusParameter(URL_QUERY_STRING_PARAM, getQueryString());
323a324
> 
336,340c337,343
<         String serverName = theRequest.getParameter(URL_SERVER_NAME_PARAM);
<         String contextPath = theRequest.getParameter(URL_CONTEXT_PATH_PARAM);
<         String servletPath = theRequest.getParameter(URL_SERVLET_PATH_PARAM);
<         String pathInfo = theRequest.getParameter(URL_PATH_INFO_PARAM);
<         String queryString = theRequest.getParameter(URL_QUERY_STRING_PARAM);
---
>         String query = theRequest.getQueryString();
> 
>         String serverName = getQueryStringParameter(query, URL_SERVER_NAME_PARAM);
>         String contextPath = getQueryStringParameter(query, URL_CONTEXT_PATH_PARAM);
>         String servletPath = getQueryStringParameter(query, URL_SERVLET_PATH_PARAM);
>         String pathInfo = getQueryStringParameter(query, URL_PATH_INFO_PARAM);
>         String queryString = getQueryStringParameter(query, URL_QUERY_STRING_PARAM);
366a370,412
>     /** A substitute method for getParameter.  This method does not
>      * access the request input stream.  Used to retrieve Cactus
>      * parameters from the query string.
>      *
>      * @param theQueryString the query string to parse
>      *
>      * @param theParameter the name of the parameter to locate
>      *
>      * @return the value for theParameter in theQueryString, null if
>      * theParameter does not exist.
>      */
>     public static String getQueryStringParameter(String theQueryString, String 
>theParameter)
>     {
>         if (theQueryString == null) {
>             return null;
>         }
>         
>         String value = null;
>         
>         int startIndex = theQueryString.indexOf(theParameter + "=" );
>         
>         if (startIndex >= 0) {
>             // add 1 for '='
>             startIndex += theParameter.length() + 1;
>             
>             int endIndex = theQueryString.indexOf('&', startIndex);
>             
>             logger.error("query: '" + theQueryString + "'"
>                          + "  param: '" + theParameter + "'"
>                          + "  startIndex: " + startIndex
>                          + "  endIndex: " + endIndex );
>             
>             if (endIndex > startIndex) {
>                 value = theQueryString.substring(startIndex, endIndex);
>             } else {
>                 value = theQueryString.substring(startIndex);
>             }
>             
>             value = URLDecoder.decode(value);
>         }
>         
>         return value;
>     }
133,135c133,145
<      * 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>.
---
>      * Something must be sent on the output stream for a POST request.
>      * Creates a dummy parameter to send.
>      */
>     public void beginPostMethod(WebRequest theRequest)
>     {
>         theRequest.addParameter("param1", "value1");
>     }
>     
>     /**
>      * Verify that we can simulate a POST request to a servlet. Note
>      * that the POST method is the default method but we still need to
>      * initialize a parameter in <code>beginPostMethod()</code> so
>      * that something is sent on the output stream.
206c216
< 
---
>     
214c224
< 
---
>         
220c230
< 
---
>     
222c232,264
< 
---
>     
>     /**
>      * Verify that we can simulate HTTP parameters in the HTTP request
>      * using the GET method
>      *
>      * @param theRequest the request object that serves to initialize the
>      *                   HTTP connection to the server redirector.
>      */
>     public void beginGetSendParams(WebRequest theRequest)
>     {
>         theRequest.setMethod(WebRequest.GET_METHOD);
>         
>         theRequest.addParameter("param1", "value1");
>         theRequest.addParameter("param2", "value2");
>     }
>     
>     /**
>      * Verify that we can send several parameters in the HTTP request
>      * using the GET method.
>      */
>     public void testGetSendParams()
>     {
>         SampleServlet servlet = new SampleServlet();
>         Hashtable params = servlet.getRequestParameters(request);
>         
>         assert(params.get("param1") != null);
>         assert(params.get("param2") != null);
>         assertEquals("value1", params.get("param1"));
>         assertEquals("value2", params.get("param2"));
>     }
>     
>     //-------------------------------------------------------------------------
>     
410a453
> 
289c289,328
< }
\ No newline at end of file
---
>     //-------------------------------------------------------------------------
> 
>     /**
>      * Verify that we can simulate different parts of the URL. Also verify 
>      * that HTTP parameters put in the simulation URL will be
>      * available on the server side as real HTTP parameters.
>      *
>      * Uses GET method.
>      *
>      * @param theRequest the request object that serves to initialize the
>      *                   HTTP connection to the server redirector.
>      */
>     public void beginSimulatedURL6(WebRequest theRequest)
>     {
>         theRequest.setMethod(WebRequest.GET_METHOD);
>         theRequest.setURL("jakarta.apache.org", "/catalog", 
>             "/help/feedback.jsp", null, "PARAM1=param1&PARAM2=&PARAM3=param3");
>     }
> 
>     /**
>      * Verify that we can simulate different parts of the URL. Also verify 
>      * that HTTP parameters put in the simulation URL will be
>      * available on the server side as real HTTP parameters.
>      */
>     public void testSimulatedURL6()
>     {
>         assertEquals("jakarta.apache.org", request.getServerName());
>         assertEquals("/catalog/help/feedback.jsp", request.getRequestURI());
>         assertEquals(80, request.getServerPort());
>         assertEquals("/catalog", request.getContextPath());
>         assertEquals("/help/feedback.jsp", request.getServletPath());
>         assert(request.getPathInfo() == null);
>         assertEquals("PARAM1=param1&PARAM2=&PARAM3=param3",
>             request.getQueryString());
>         assertEquals(request.getParameter("PARAM1"), "param1");
>         assertEquals(request.getParameter("PARAM2"), "");
>         assertEquals(request.getParameter("PARAM3"), "param3");
>     }
> 
> }
86a87,91
>      * The Cactus parameters.
>      */
>     private Hashtable cactusParameters = new Hashtable();
> 
>     /**
526a532,563
>     /**
>      * Adds a Cactus parameter to the request.  Currently only 1 value
>      * is supported.
>      *
>      * @param theName  the parameter's name
>      * @param theValue the parameter's value
>      */
>     public void addCactusParameter(String theName, String theValue)
>     {
>         this.cactusParameters.put(theName, theValue);
>     }
>     
>     /**
>      * @return the Cactus parameter names
>      */
>     public Enumeration getCactusParameterNames()
>     {
>         return this.cactusParameters.keys();
>     }
>     
>     /**
>      * Returns the first value corresponding to this Cactus parameter's name.
>      *
>      * @param  theName the parameter's name
>      * @return the first value corresponding to this parameter's name or null
>      *         if not found
>      */
>     public String getCactusParameter(String theName)
>     {
>         return (String)this.cactusParameters.get(theName);
>     }
>     

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

Reply via email to