olegk       2004/05/12 13:43:54

  Modified:    httpclient/src/examples ChunkEncodedPost.java PostXML.java
                        UnbufferedPost.java
               httpclient/src/java/org/apache/commons/httpclient
                        MultiThreadedHttpConnectionManager.java
               httpclient/src/java/org/apache/commons/httpclient/methods
                        EntityEnclosingMethod.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestMethodCharEncoding.java TestMethodsNoHost.java
                        TestWebappBasicAuth.java TestWebappMethods.java
                        TestWebappNoncompliant.java
                        TestWebappPostMethod.java TestWebappRedirect.java
               httpclient/src/test/org/apache/commons/httpclient/server
                        ProxyRequestHandler.java
  Log:
  Cleanup of deprecated methods in the test cases and sample applications
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.6       +18 -12    jakarta-commons/httpclient/src/examples/ChunkEncodedPost.java
  
  Index: ChunkEncodedPost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/ChunkEncodedPost.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ChunkEncodedPost.java     22 Feb 2004 18:08:45 -0000      1.5
  +++ ChunkEncodedPost.java     12 May 2004 20:43:53 -0000      1.6
  @@ -31,6 +31,7 @@
   import java.io.FileInputStream;
   import org.apache.commons.httpclient.HttpClient;
   import org.apache.commons.httpclient.HttpStatus;
  +import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
   import org.apache.commons.httpclient.methods.PostMethod;
   
   /**
  @@ -50,16 +51,21 @@
   
       PostMethod httppost = new 
PostMethod("http://localhost:8080/httpclienttest/body";);
   
  -    httppost.setRequestBody(new FileInputStream(new File(args[0])));
  -    httppost.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
  +    File file = new File(args[0]);
   
  -    client.executeMethod(httppost);
  +    httppost.setRequestEntity(new InputStreamRequestEntity(new 
FileInputStream(file)));
  +    httppost.setContentChunked(true);
   
  -    if (httppost.getStatusCode() == HttpStatus.SC_OK) {
  -        System.out.println(httppost.getResponseBodyAsString());
  -    } else {
  -      System.out.println("Unexpected failure: " + 
httppost.getStatusLine().toString());
  -    }
  -    httppost.releaseConnection();
  +    try {
  +        client.executeMethod(httppost);
  +
  +        if (httppost.getStatusCode() == HttpStatus.SC_OK) {
  +            System.out.println(httppost.getResponseBodyAsString());
  +        } else {
  +          System.out.println("Unexpected failure: " + 
httppost.getStatusLine().toString());
  +        }
  +    } finally {
  +        httppost.releaseConnection();
  +    }   
     }
   }
  
  
  
  1.13      +18 -20    jakarta-commons/httpclient/src/examples/PostXML.java
  
  Index: PostXML.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/PostXML.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PostXML.java      22 Feb 2004 18:08:45 -0000      1.12
  +++ PostXML.java      12 May 2004 20:43:53 -0000      1.13
  @@ -32,7 +32,7 @@
   import java.io.FileInputStream;
   
   import org.apache.commons.httpclient.HttpClient;
  -import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
  +import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
   import org.apache.commons.httpclient.methods.PostMethod;
   
   /**
  @@ -78,17 +78,12 @@
           PostMethod post = new PostMethod(strURL);
           // Request content will be retrieved directly 
           // from the input stream
  -        post.setRequestBody(new FileInputStream(input));
           // Per default, the request content needs to be buffered
           // in order to determine its length.
           // Request body buffering can be avoided when
  -        // = content length is explicitly specified
  -        // = chunk-encoding is used
  -        if (input.length() < Integer.MAX_VALUE) {
  -            post.setRequestContentLength(input.length());
  -        } else {
  -            
post.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
  -        }
  +        // content length is explicitly specified
  +        post.setRequestEntity(new InputStreamRequestEntity(
  +            new FileInputStream(input), input.length()));
           // Specify content type and encoding
           // If content encoding is not explicitly specified
           // ISO-8859-1 is assumed
  @@ -96,13 +91,16 @@
           // Get HTTP client
           HttpClient httpclient = new HttpClient();
           // Execute request
  -        int result = httpclient.executeMethod(post);
  -        // Display status code
  -        System.out.println("Response status code: " + result);
  -        // Display response
  -        System.out.println("Response body: ");
  -        System.out.println(post.getResponseBodyAsString());
  -        // Release current connection to the connection pool once you are done
  -        post.releaseConnection();
  +        try {
  +            int result = httpclient.executeMethod(post);
  +            // Display status code
  +            System.out.println("Response status code: " + result);
  +            // Display response
  +            System.out.println("Response body: ");
  +            System.out.println(post.getResponseBodyAsString());
  +        } finally {
  +            // Release current connection to the connection pool once you are done
  +            post.releaseConnection();
  +        }
       }
   }
  
  
  
  1.5       +15 -11    jakarta-commons/httpclient/src/examples/UnbufferedPost.java
  
  Index: UnbufferedPost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/UnbufferedPost.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- UnbufferedPost.java       22 Feb 2004 18:08:45 -0000      1.4
  +++ UnbufferedPost.java       12 May 2004 20:43:53 -0000      1.5
  @@ -31,6 +31,7 @@
   import java.io.FileInputStream;
   import org.apache.commons.httpclient.HttpClient;
   import org.apache.commons.httpclient.HttpStatus;
  +import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
   import org.apache.commons.httpclient.methods.PostMethod;
   
   /**
  @@ -51,16 +52,19 @@
       PostMethod httppost = new 
PostMethod("http://localhost:8080/httpclienttest/body";);
   
       File file = new File(args[0]);
  -    httppost.setRequestBody(new FileInputStream(file));
  -    httppost.setRequestContentLength(file.length());
  +    httppost.setRequestEntity(new InputStreamRequestEntity(
  +        new FileInputStream(file), file.length()));
   
  -    client.executeMethod(httppost);
  +    try {
  +        client.executeMethod(httppost);
   
  -    if (httppost.getStatusCode() == HttpStatus.SC_OK) {
  -        System.out.println(httppost.getResponseBodyAsString());
  -    } else {
  -      System.out.println("Unexpected failure: " + 
httppost.getStatusLine().toString());
  +        if (httppost.getStatusCode() == HttpStatus.SC_OK) {
  +            System.out.println(httppost.getResponseBodyAsString());
  +        } else {
  +          System.out.println("Unexpected failure: " + 
httppost.getStatusLine().toString());
  +        }
  +    } finally {
  +        httppost.releaseConnection();
       }
  -    httppost.releaseConnection();
     }
   }
  
  
  
  1.37      +6 -3      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java
  
  Index: MultiThreadedHttpConnectionManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- MultiThreadedHttpConnectionManager.java   25 Apr 2004 21:49:34 -0000      1.36
  +++ MultiThreadedHttpConnectionManager.java   12 May 2004 20:43:53 -0000      1.37
  @@ -1404,6 +1404,9 @@
               }
           }
   
  +        /**
  +         * @deprecated
  +         */
           public void shutdownOutput() {
               if (hasConnection()) {
                   wrappedConnection.shutdownOutput();
  
  
  
  1.35      +6 -5      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java
  
  Index: EntityEnclosingMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- EntityEnclosingMethod.java        12 May 2004 03:07:03 -0000      1.34
  +++ EntityEnclosingMethod.java        12 May 2004 20:43:53 -0000      1.35
  @@ -414,6 +414,8 @@
        * content encoding is used (ISO-8859-1).
        *
        * @param body Request body content as a string
  +     * 
  +     * @deprecated use [EMAIL PROTECTED] #setRequestEntity(RequestEntity)}
        */
       public void setRequestBody(String body) {
           LOG.trace("enter EntityEnclosingMethod.setRequestBody(String)");
  @@ -461,7 +463,6 @@
           }
   
           if ((this.repeatCount > 0) && !requestEntity.isRepeatable()) {
  -            // TODO: Is this the right exception to throw here?
               throw new ProtocolException(
                   "Unbuffered entity enclosing request can not be repeated.");
           }
  
  
  
  1.9       +13 -10    
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodCharEncoding.java
  
  Index: TestMethodCharEncoding.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodCharEncoding.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestMethodCharEncoding.java       28 Apr 2004 02:23:16 -0000      1.8
  +++ TestMethodCharEncoding.java       12 May 2004 20:43:54 -0000      1.9
  @@ -42,6 +42,7 @@
   import org.apache.commons.httpclient.methods.GetMethod;
   import org.apache.commons.httpclient.methods.PostMethod;
   import org.apache.commons.httpclient.methods.RequestEntity;
  +import org.apache.commons.httpclient.methods.StringRequestEntity;
   import org.apache.commons.httpclient.util.URIUtil;
   
   /**
  @@ -184,32 +185,34 @@
       }
       
       public void testLatinAccentInRequestBody() throws IOException {
  -
           PostMethod httppost = new PostMethod("/");
  -        httppost.setRequestBody(constructString(SWISS_GERMAN_STUFF_UNICODE));
  +        String s = constructString(SWISS_GERMAN_STUFF_UNICODE);
           // Test default encoding ISO-8859-1
  +        httppost.setRequestEntity(
  +            new StringRequestEntity(s, "text/plain", CHARSET_DEFAULT));
           verifyEncoding(httppost.getRequestEntity(), SWISS_GERMAN_STUFF_ISO8859_1);
           // Test UTF-8 encoding
  -        httppost.setRequestHeader("Content-Type", "text/plain; charset=" + 
CHARSET_UTF8);
  +        httppost.setRequestEntity(
  +            new StringRequestEntity(s, "text/plain", CHARSET_UTF8));
           verifyEncoding(httppost.getRequestEntity(), SWISS_GERMAN_STUFF_UTF8);
   
       }
       
       public void testRussianInRequestBody() throws IOException {
  -
           PostMethod httppost = new PostMethod("/");
  -        httppost.setRequestBody(constructString(RUSSIAN_STUFF_UNICODE));
  -
  +        String s = constructString(RUSSIAN_STUFF_UNICODE);
           // Test UTF-8 encoding
  -        httppost.setRequestHeader("Content-Type", "text/plain; charset=" + 
CHARSET_UTF8);
  +        httppost.setRequestEntity(
  +            new StringRequestEntity(s, "text/plain", CHARSET_UTF8));
           verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_UTF8);
           // Test KOI8-R
  -        httppost.setRequestHeader("Content-Type", "text/plain; charset=" + 
CHARSET_KOI8_R);
  +        httppost.setRequestEntity(
  +            new StringRequestEntity(s, "text/plain", CHARSET_KOI8_R));
           verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_KOI8R);
           // Test WIN1251
  -        httppost.setRequestHeader("Content-Type", "text/plain; charset=" + 
CHARSET_WIN1251);
  +        httppost.setRequestEntity(
  +            new StringRequestEntity(s, "text/plain", CHARSET_WIN1251));
           verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_WIN1251);
  -
       }
   
       public void testQueryParams() throws Exception {
  
  
  
  1.23      +6 -5      
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java
  
  Index: TestMethodsNoHost.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- TestMethodsNoHost.java    28 Apr 2004 02:23:16 -0000      1.22
  +++ TestMethodsNoHost.java    12 May 2004 20:43:54 -0000      1.23
  @@ -41,6 +41,7 @@
   import org.apache.commons.httpclient.methods.HeadMethod;
   import org.apache.commons.httpclient.methods.PostMethod;
   import org.apache.commons.httpclient.methods.RequestEntity;
  +import org.apache.commons.httpclient.methods.StringRequestEntity;
   
   /**
    * @author Rodney Waldhoff
  @@ -99,7 +100,7 @@
       public void testPostSetRequestBody() throws Exception {
           PostMethod post = new PostMethod("/foo");
           String body = "this+is+the+body";
  -        post.setRequestBody(body);
  +        post.setRequestEntity(new StringRequestEntity(body));
           assertEquals(body, getRequestAsString(post.getRequestEntity()));
       }
   
  
  
  
  1.16      +6 -5      
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappBasicAuth.java
  
  Index: TestWebappBasicAuth.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappBasicAuth.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TestWebappBasicAuth.java  22 Feb 2004 18:08:50 -0000      1.15
  +++ TestWebappBasicAuth.java  12 May 2004 20:43:54 -0000      1.16
  @@ -38,6 +38,7 @@
   import org.apache.commons.httpclient.methods.HeadMethod;
   import org.apache.commons.httpclient.methods.PostMethod;
   import org.apache.commons.httpclient.methods.PutMethod;
  +import org.apache.commons.httpclient.methods.StringRequestEntity;
   
   /**
    * This suite of tests depends upon the httpclienttest webapp,
  @@ -144,7 +145,7 @@
               new HttpAuthRealm(getHost(), getPort(), "BasicAuthServlet"),
               new UsernamePasswordCredentials("jakarta","commons"));
           PutMethod method = new PutMethod("/" + getWebappContext() + "/auth/basic");
  -        method.setRequestBody("testing one two three");
  +        method.setRequestEntity(new StringRequestEntity("testing one two three"));
           try {
               client.executeMethod(method);
           } catch (Throwable t) {
  
  
  
  1.22      +22 -92    
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java
  
  Index: TestWebappMethods.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- TestWebappMethods.java    22 Feb 2004 18:08:50 -0000      1.21
  +++ TestWebappMethods.java    12 May 2004 20:43:54 -0000      1.22
  @@ -30,9 +30,6 @@
   
   package org.apache.commons.httpclient;
   
  -import java.io.ByteArrayInputStream;
  -import java.io.InputStream;
  -
   import junit.framework.*;
   import org.apache.commons.httpclient.methods.*;
   import org.apache.commons.httpclient.util.EncodingUtil;
  @@ -277,7 +274,7 @@
           HttpClient client = createHttpClient();
           PostMethod method = new PostMethod("/" + getWebappContext() + "/body");
           
  -        
method.setRequestBody("quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.");
  +        method.setRequestEntity(new 
StringRequestEntity("quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times."));
           try {
               client.executeMethod(method);
           } catch (Throwable t) {
  @@ -296,14 +293,8 @@
           String bodyStr = 
"quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
                byte[] body = EncodingUtil.getBytes(bodyStr, "ISO-8859-1");
   
  -        method.setRequestBody(new ByteArrayInputStream(body));
  -        method.setRequestContentLength((long)body.length);
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        method.setRequestEntity(new ByteArrayRequestEntity(body));
  +        client.executeMethod(method);
           
assertTrue(method.getResponseBodyAsString().indexOf("<tt>quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.</tt>")
 >= 0);
           assertEquals(200,method.getStatusCode());
       }
  @@ -314,14 +305,8 @@
           PostMethod method = new PostMethod("/" + getWebappContext() + "/body");
           
           String body = 
"quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
  -        method.setRequestBody(body);
  -        method.setRequestContentLength(PostMethod.CONTENT_LENGTH_AUTO);
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        method.setRequestEntity(new StringRequestEntity(body));
  +        client.executeMethod(method);
           
assertTrue(method.getResponseBodyAsString().indexOf("<tt>quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.</tt>")
 >= 0);
           assertEquals(200,method.getStatusCode());
       }
  @@ -332,14 +317,9 @@
           PostMethod method = new PostMethod("/" + getWebappContext() + "/body");
           
           String body = 
"quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
  -        method.setRequestBody(body);
  -        method.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        method.setRequestEntity(new StringRequestEntity(body));
  +        method.setContentChunked(true);
  +        client.executeMethod(method);
           
assertTrue(method.getResponseBodyAsString().indexOf("<tt>quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.</tt>")
 >= 0);
           assertEquals(200,method.getStatusLine().getStatusCode());
       }
  @@ -348,13 +328,8 @@
       public void testPutBody() throws Exception {
           HttpClient client = createHttpClient();
           PutMethod method = new PutMethod("/" + getWebappContext() + "/body");
  -        method.setRequestBody("This is data to be sent in the body of an HTTP 
PUT.");
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        method.setRequestEntity(new StringRequestEntity("This is data to be sent in 
the body of an HTTP PUT."));
  +        client.executeMethod(method);
           
assertTrue(method.getResponseBodyAsString(),method.getResponseBodyAsString().indexOf("<tt>This
 is data to be sent in the body of an HTTP PUT.</tt>") >= 0);
           assertEquals(200,method.getStatusCode());
       }
  @@ -367,14 +342,8 @@
           String bodyStr = "Like, hello, and stuff";
           byte [] body = EncodingUtil.getBytes(bodyStr, "ISO-8859-1");
           method.setRequestHeader("Content-Type", "text/plain");
  -        method.setRequestBody(new ByteArrayInputStream(body));
  -        method.setRequestContentLength((long)body.length);
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        method.setRequestEntity(new ByteArrayRequestEntity(body));
  +        client.executeMethod(method);
           assertEquals(200,method.getStatusLine().getStatusCode());
           String response = method.getResponseBodyAsString();
   
  @@ -382,14 +351,8 @@
   
           method.setPath("/" + getWebappContext() + "/body");
           method.setRequestHeader("Content-Type", "text/plain");
  -        method.setRequestBody(new ByteArrayInputStream(body));
  -        method.setRequestContentLength((long)body.length);
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        method.setRequestEntity(new ByteArrayRequestEntity(body));
  +        client.executeMethod(method);
           assertEquals(200,method.getStatusLine().getStatusCode());
           response = method.getResponseBodyAsString();
       }
  @@ -408,37 +371,6 @@
   
           method.setPath("/" + getWebappContext() + "/body");
           method.setRequestHeader("Content-Type", "text/plain");
  -        method.setRequestBody((String)null);
  -        client.executeMethod(method);
  -        assertEquals(200,method.getStatusLine().getStatusCode());
  -        response = method.getResponseBodyAsString();
  -        assertTrue(response.indexOf("No body submitted") >= 0);
  -
  -        method.recycle();
  -
  -        method.setPath("/" + getWebappContext() + "/body");
  -        method.setRequestHeader("Content-Type", "text/plain");
  -        method.setRequestBody((InputStream)null);
  -        client.executeMethod(method);
  -        assertEquals(200,method.getStatusLine().getStatusCode());
  -        response = method.getResponseBodyAsString();
  -        assertTrue(response.indexOf("No body submitted") >= 0);
  -
  -        method.recycle();
  -
  -        method.setPath("/" + getWebappContext() + "/body");
  -        method.setRequestHeader("Content-Type", "text/plain");
  -        method.setRequestBody("");
  -        client.executeMethod(method);
  -        assertEquals(200,method.getStatusLine().getStatusCode());
  -        response = method.getResponseBodyAsString();
  -        assertTrue(response.indexOf("No body submitted") >= 0);
  -
  -        method.recycle();
  -
  -        method.setPath("/" + getWebappContext() + "/body");
  -        method.setRequestHeader("Content-Type", "text/plain");
  -        
method.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
           client.executeMethod(method);
           assertEquals(200,method.getStatusLine().getStatusCode());
           response = method.getResponseBodyAsString();
  @@ -448,8 +380,7 @@
   
           method.setPath("/" + getWebappContext() + "/body");
           method.setRequestHeader("Content-Type", "text/plain");
  -        
method.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
  -        method.setRequestBody((String)null);
  +        method.setRequestEntity(new StringRequestEntity(""));
           client.executeMethod(method);
           assertEquals(200,method.getStatusLine().getStatusCode());
           response = method.getResponseBodyAsString();
  @@ -459,8 +390,7 @@
   
           method.setPath("/" + getWebappContext() + "/body");
           method.setRequestHeader("Content-Type", "text/plain");
  -        
method.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
  -        method.setRequestBody((InputStream)null);
  +        method.setContentChunked(true);
           client.executeMethod(method);
           assertEquals(200,method.getStatusLine().getStatusCode());
           response = method.getResponseBodyAsString();
  @@ -470,8 +400,8 @@
   
           method.setPath("/" + getWebappContext() + "/body");
           method.setRequestHeader("Content-Type", "text/plain");
  -        
method.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
  -        method.setRequestBody("");
  +        method.setRequestEntity(new StringRequestEntity(""));
  +        method.setContentChunked(true);
           client.executeMethod(method);
           assertEquals(200,method.getStatusLine().getStatusCode());
           response = method.getResponseBodyAsString();
  
  
  
  1.8       +1 -1      
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappNoncompliant.java
  
  Index: TestWebappNoncompliant.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappNoncompliant.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestWebappNoncompliant.java       22 Feb 2004 18:08:50 -0000      1.7
  +++ TestWebappNoncompliant.java       12 May 2004 20:43:54 -0000      1.8
  @@ -67,7 +67,7 @@
           HttpClient client = createHttpClient();
           NoncompliantPostMethod method = new NoncompliantPostMethod("/" + 
getWebappContext() + "/body");
           
method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
  -        method.setRequestBody("This is data to be sent in the body of an HTTP 
POST.");
  +        method.setRequestEntity(new StringRequestEntity("This is data to be sent in 
the body of an HTTP POST."));
           try {
               client.executeMethod(method);
           } catch (Exception e) {
  
  
  
  1.7       +7 -34     
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappPostMethod.java
  
  Index: TestWebappPostMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappPostMethod.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestWebappPostMethod.java 28 Apr 2004 02:23:16 -0000      1.6
  +++ TestWebappPostMethod.java 12 May 2004 20:43:54 -0000      1.7
  @@ -119,8 +119,8 @@
           PostMethod method = new PostMethod(paramsPath);
           String stringBody = "pname1=pvalue1&pname2=pvalue2";
   
  -        method.setRequestBody(stringBody);
  -        method.setRequestHeader("Content-Type", 
PostMethod.FORM_URL_ENCODED_CONTENT_TYPE);
  +        method.setRequestEntity(
  +            new StringRequestEntity(stringBody, 
PostMethod.FORM_URL_ENCODED_CONTENT_TYPE, null));
           
           verifyParams(method);
       }
  @@ -132,34 +132,7 @@
           PostMethod method = new PostMethod(bodyPath);
           String stringBody = "pname1=pvalue1&pname2=pvalue2";
   
  -        method.setRequestBody(stringBody);
  -        
  -        verifyBody(method);
  -    }
  -
  -    /**
  -     * Test that the body can be set as a stream to the param servlet.
  -     */
  -    public void testStreamBodyToParamServlet() throws Exception {
  -        PostMethod method = new PostMethod(paramsPath);
  -        InputStream streamBody = 
  -            new ByteArrayInputStream("pname1=pvalue1&pname2=pvalue2".getBytes());
  -
  -        method.setRequestBody(streamBody);
  -        method.setRequestHeader("Content-Type", 
PostMethod.FORM_URL_ENCODED_CONTENT_TYPE);
  -        
  -        verifyParams(method);
  -    }
  -
  -    /**
  -     * Test that the body can be set as a stream to the body servlet.
  -     */
  -    public void testStreamBodyToBodyServlet() throws Exception {
  -        PostMethod method = new PostMethod(bodyPath);
  -        
  -        InputStream streamBody = 
  -            new ByteArrayInputStream("pname1=pvalue1&pname2=pvalue2".getBytes());
  -        method.setRequestBody(streamBody);
  +        method.setRequestEntity(new StringRequestEntity(stringBody));
           
           verifyBody(method);
       }
  
  
  
  1.23      +16 -39    
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java
  
  Index: TestWebappRedirect.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- TestWebappRedirect.java   12 Apr 2004 10:30:46 -0000      1.22
  +++ TestWebappRedirect.java   12 May 2004 20:43:54 -0000      1.23
  @@ -35,9 +35,13 @@
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  +
  +import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
   import org.apache.commons.httpclient.methods.GetMethod;
  +import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
   import org.apache.commons.httpclient.methods.PostMethod;
   import org.apache.commons.httpclient.methods.PutMethod;
  +import org.apache.commons.httpclient.methods.StringRequestEntity;
   import org.apache.commons.httpclient.util.EncodingUtil;
   import org.apache.commons.httpclient.util.URIUtil;
   import org.apache.commons.logging.Log;
  @@ -90,12 +94,7 @@
           HttpClient client = createHttpClient();
           GetMethod method = new GetMethod(redirectUrl);
           method.setQueryString("to=" + paramsUrl + "&code=" + code);
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        client.executeMethod(method);
           assertEquals(200,method.getStatusCode());
           assertTrue(method.getResponseBodyAsString().indexOf("<title>Param Servlet: 
GET</title>") >= 0);
       }
  @@ -123,12 +122,7 @@
           HttpClient client = createHttpClient();
           GetMethod method = new GetMethod(redirectUrl);
           method.setQueryString("to=params");
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        client.executeMethod(method);
           assertEquals(200,method.getStatusCode());
           assertTrue(method.getResponseBodyAsString().indexOf("<title>Param Servlet: 
GET</title>") >= 0);
       }
  @@ -141,12 +135,7 @@
               new NameValuePair("to", paramsUrl + "?foo=bar&bar=foo")
               }
           );
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        client.executeMethod(method);
           assertEquals(200,method.getStatusCode());
           assertTrue(method.getResponseBodyAsString().indexOf("<title>Param Servlet: 
GET</title>") >= 0);
           
assertTrue(method.getResponseBodyAsString().indexOf("<p>QueryString=\"foo=bar&bar=foo\"</p>")
 >= 0);
  @@ -161,12 +150,7 @@
               qs = redirectUrl + "?to=" + URIUtil.encodeWithinQuery(qs);
           }
           method.setQueryString("to=" + URIUtil.encodeWithinQuery(qs));
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        client.executeMethod(method);
           assertEquals(200,method.getStatusCode());
           assertTrue(method.getResponseBodyAsString().indexOf("<title>Param Servlet: 
GET</title>") >= 0);
           
assertTrue(method.getResponseBodyAsString().indexOf("<p>QueryString=\"foo=bar&bar=foo\"</p>")
 >= 0);
  @@ -197,8 +181,7 @@
                       client.getHostConfiguration().getHostURL() + "/" 
                       + getWebappContext() + "/params?foo=bar&bar=foo"));
           byte[] body = EncodingUtil.getBytes(bodyStr, "ISO-8859-1");
  -        method.setRequestBody(new ByteArrayInputStream(body));
  -        method.setRequestContentLength((long)body.length);  //unbuffered request
  +        method.setRequestEntity(new ByteArrayRequestEntity(body));
           
           try {
               client.executeMethod(method);
  @@ -211,8 +194,7 @@
   
           method = new PostMethod(redirectUrl);
           method.setQueryString("to=" + URIUtil.encodeWithinQuery(paramsUrl + 
"?foo=bar&bar=foo"));
  -        method.setRequestBody(new ByteArrayInputStream(body));
  -        method.setRequestContentLength(PostMethod.CONTENT_LENGTH_AUTO); //buffered 
request
  +        method.setRequestEntity(new InputStreamRequestEntity(new 
ByteArrayInputStream(body)));
           
           try {
               client.executeMethod(method);
  @@ -228,13 +210,8 @@
           HttpClient client = createHttpClient();
           PutMethod method = new PutMethod(redirectUrl);
           method.setQueryString("to=" + URIUtil.encodeWithinQuery(bodyUrl + 
"?foo=bar&bar=foo"));
  -        method.setRequestBody("This is data to be sent in the body of an HTTP 
PUT.");
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  +        method.setRequestEntity(new StringRequestEntity("This is data to be sent in 
the body of an HTTP PUT."));
  +        client.executeMethod(method);
           assertEquals(HttpStatus.SC_MOVED_TEMPORARILY,method.getStatusCode());
       }
   }
  
  
  
  1.5       +6 -4      
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/ProxyRequestHandler.java
  
  Index: ProxyRequestHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/ProxyRequestHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProxyRequestHandler.java  27 Feb 2004 19:01:34 -0000      1.4
  +++ ProxyRequestHandler.java  12 May 2004 20:43:54 -0000      1.5
  @@ -42,6 +42,7 @@
   import org.apache.commons.httpclient.URI;
   import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
   import org.apache.commons.httpclient.methods.GetMethod;
  +import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -91,7 +92,8 @@
                }
                if (method instanceof EntityEnclosingMethod) {
                        EntityEnclosingMethod emethod = (EntityEnclosingMethod) method;
  -                     emethod.setRequestBody(conn.getInputStream());
  +                     emethod.setRequestEntity(
  +                new InputStreamRequestEntity(conn.getInputStream()));
                }
                client.executeMethod(method);
   
  
  
  

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

Reply via email to