You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by og...@apache.org on 2002/12/11 14:38:25 UTC

cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestWebappMethods.java

oglueck     2002/12/11 05:38:25

  Modified:    httpclient/src/java/org/apache/commons/httpclient/methods
                        PostMethod.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestWebappMethods.java
  Log:
  Correctly recycle POST methods.
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.29      +4 -3      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java
  
  Index: PostMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- PostMethod.java	9 Dec 2002 09:16:17 -0000	1.28
  +++ PostMethod.java	11 Dec 2002 13:38:24 -0000	1.29
  @@ -560,6 +560,7 @@
           requestBody = null;
           requestContentLength = CONTENT_LENGTH_AUTO;
           buffer = null;
  +        repeatCount = 0;
           parameters.clear();
       }
   
  
  
  
  1.8       +52 -17    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestWebappMethods.java	29 Oct 2002 09:44:22 -0000	1.7
  +++ TestWebappMethods.java	11 Dec 2002 13:38:25 -0000	1.8
  @@ -109,7 +109,7 @@
        */
       public void testGetMethod() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           GetMethod method = new GetMethod("/" + context + "/params");
           method.setUseDisk(false);
           try {
  @@ -139,7 +139,7 @@
        */
       public void testPostMethod() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           PostMethod method = new PostMethod("/" + context + "/params");
           method.setUseDisk(false);
           try {
  @@ -169,7 +169,7 @@
        */
       public void testHeadMethod() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           HeadMethod method = new HeadMethod("/" + context + "/params");
           try {
               client.executeMethod(method);
  @@ -196,7 +196,7 @@
        */
       public void testOptionsMethod() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           OptionsMethod method = new OptionsMethod("/" + context + "/params");
           try {
               client.executeMethod(method);
  @@ -225,7 +225,7 @@
        */
       public void testOptionsStar() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           OptionsMethod method = new OptionsMethod("*");
           try {
               client.executeMethod(method);
  @@ -242,7 +242,7 @@
        */
       public void testDeleteMethod() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           DeleteMethod method = new DeleteMethod("/" + context + "/params");
           try {
               client.executeMethod(method);
  @@ -269,7 +269,7 @@
        */
       public void testPutMethod() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           PutMethod method = new PutMethod("/" + context + "/params");
           try {
               client.executeMethod(method);
  @@ -295,7 +295,7 @@
   
       public void testPostBodyNVP() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           PostMethod method = new PostMethod("/" + context + "/body");
           method.setUseDisk(false);
           method.addParameter("quote","It was the best of times, it was the worst of times.");
  @@ -311,7 +311,7 @@
   
       public void testPostBody() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           PostMethod method = new PostMethod("/" + context + "/body");
           method.setUseDisk(false);
           method.setRequestBody("quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.");
  @@ -328,7 +328,7 @@
   
       public void testPostBodyCustomLength() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           PostMethod method = new PostMethod("/" + context + "/body");
           method.setUseDisk(false);
           String body = "quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
  @@ -347,7 +347,7 @@
   
       public void testPostBodyAutoLength() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           PostMethod method = new PostMethod("/" + context + "/body");
           method.setUseDisk(false);
           String body = "quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
  @@ -368,7 +368,7 @@
       //note: only few servers support this
       public void testPostBodyChunked() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           PostMethod method = new PostMethod("/" + context + "/body");
           method.setUseDisk(false);
           String body = "quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.";
  @@ -387,7 +387,7 @@
   
       public void testPutBody() throws Exception {
           HttpClient client = new HttpClient();
  -        client.startSession(host, port);
  +        client.getHostConfiguration().setHost(host, port, "http");
           PutMethod method = new PutMethod("/" + context + "/body");
           method.setRequestBody("This is data to be sent in the body of an HTTP PUT.");
           try {
  @@ -400,4 +400,39 @@
           assertEquals(200,method.getStatusCode());
       }
   
  +
  +    public void testPostMethodRecycle() {
  +        HttpClient client = new HttpClient();
  +        client.getHostConfiguration().setHost(host, port, "http");
  +        PostMethod method = new PostMethod("/" + context + "/body");
  +        method.setUseDisk(false);
  +        String bodyStr = "Like, hello, and stuff";
  +        byte [] body = bodyStr.getBytes();
  +        method.setRequestHeader("Content-Type", "text/plain");
  +        method.setRequestBody(new ByteArrayInputStream(body));
  +        method.setRequestContentLength(body.length);
  +        try {
  +            client.executeMethod(method);
  +        } catch (Throwable t) {
  +            t.printStackTrace();
  +            fail("Unable to execute method : " + t.toString());
  +        }
  +        assertEquals(200,method.getStatusLine().getStatusCode());
  +        String response = method.getResponseBodyAsString();
  +        
  +        method.recycle();
  +        
  +        method.setPath("/" + context + "/body");
  +        method.setRequestHeader("Content-Type", "text/plain");
  +        method.setRequestBody(new ByteArrayInputStream(body));
  +        method.setRequestContentLength(body.length);
  +        try {
  +            client.executeMethod(method);
  +        } catch (Throwable t) {
  +            t.printStackTrace();
  +            fail("Unable to execute method : " + t.toString());
  +        }
  +        assertEquals(200,method.getStatusLine().getStatusCode());
  +        response = method.getResponseBodyAsString();
  +    }
   }
  
  
  

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