hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r990924 - in /httpcomponents/httpclient/trunk: ./ httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ httpclient/src/main/java/org/apache/http/conn/ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/test/jav...
Date Mon, 30 Aug 2010 20:01:47 GMT
Author: olegk
Date: Mon Aug 30 20:01:46 2010
New Revision: 990924

URL: http://svn.apache.org/viewvc?rev=990924&view=rev
Log:
Upgraded HttpCore to version 4.1-beta2; updated HttpClient tutorial

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRedirects.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestUriEscapes.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionAutoRelease.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNegotiateScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestWrapper.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestStatefulConnManagement.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java
    httpcomponents/httpclient/trunk/pom.xml
    httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java
Mon Aug 30 20:01:46 2010
@@ -32,6 +32,8 @@ import org.apache.http.message.BasicStat
 
 public class OKStatus extends BasicStatusLine {
 
+    private static final long serialVersionUID = -1639872615816850272L;
+
     public OKStatus() {
         super(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java
Mon Aug 30 20:01:46 2010
@@ -35,6 +35,7 @@ import org.apache.http.annotation.NotThr
 
 import org.apache.http.HttpEntity;
 import org.apache.http.entity.HttpEntityWrapper;
+import org.apache.http.util.EntityUtils;
 
 /**
  * An entity that releases a {@link ManagedClientConnection connection}.
@@ -87,15 +88,14 @@ public class BasicManagedEntity extends 
         return new EofSensorInputStream(wrappedEntity.getContent(), this);
     }
 
-    @Override
-    public void consumeContent() throws IOException {
+    private void ensureConsumed() throws IOException {
         if (managedConn == null)
             return;
 
         try {
             if (attemptReuse) {
                 // this will not trigger a callback from EofSensorInputStream
-                wrappedEntity.consumeContent();
+                EntityUtils.consume(wrappedEntity);
                 managedConn.markReusable();
             }
         } finally {
@@ -103,14 +103,20 @@ public class BasicManagedEntity extends 
         }
     }
 
+    @Deprecated
+    @Override
+    public void consumeContent() throws IOException {
+        ensureConsumed();
+    }
+
     @Override
     public void writeTo(final OutputStream outstream) throws IOException {
         super.writeTo(outstream);
-        consumeContent();
+        ensureConsumed();
     }
 
     public void releaseConnection() throws IOException {
-        this.consumeContent();
+        ensureConsumed();
     }
 
     public void abortConnection() throws IOException {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Mon Aug 30 20:01:46 2010
@@ -89,6 +89,7 @@ import org.apache.http.protocol.Executio
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestExecutor;
+import org.apache.http.util.EntityUtils;
 
 /**
  * Default implementation of {@link RequestDirector}.
@@ -485,9 +486,7 @@ public class DefaultRequestDirector impl
                     if (reuse) {
                         // Make sure the response body is fully consumed, if present
                         HttpEntity entity = response.getEntity();
-                        if (entity != null) {
-                            entity.consumeContent();
-                        }
+                        EntityUtils.consume(entity);
                         // entity consumed above is not an auto-release entity,
                         // need to mark the connection re-usable explicitly
                         managedConn.markReusable();
@@ -875,9 +874,7 @@ public class DefaultRequestDirector impl
                             this.log.debug("Connection kept alive");
                             // Consume response content
                             HttpEntity entity = response.getEntity();
-                            if (entity != null) {
-                                entity.consumeContent();
-                            }
+                            EntityUtils.consume(entity);
                         } else {
                             this.managedConn.close();
                         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
Mon Aug 30 20:01:46 2010
@@ -57,7 +57,7 @@ public class EntityEnclosingRequestWrapp
 
     private HttpEntity entity;
     private boolean consumed;
-    
+
     public EntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request)
         throws ProtocolException {
         super(request);
@@ -84,11 +84,12 @@ public class EntityEnclosingRequestWrapp
     }
 
     class EntityWrapper extends HttpEntityWrapper {
-        
+
         EntityWrapper(final HttpEntity entity) {
             super(entity);
         }
 
+        @Deprecated
         @Override
         public void consumeContent() throws IOException {
             consumed = true;
@@ -106,7 +107,7 @@ public class EntityEnclosingRequestWrapp
             consumed = true;
             super.writeTo(outstream);
         }
-        
+
     }
-    
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java
Mon Aug 30 20:01:46 2010
@@ -52,6 +52,7 @@ import org.apache.http.protocol.BasicHtt
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -98,9 +99,7 @@ public class TestCookie2Support extends 
 
         HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e1 = response1.getEntity();
-        if (e1 != null) {
-            e1.consumeContent();
-        }
+        EntityUtils.consume(e1);
 
         List<Cookie> cookies = cookieStore.getCookies();
         Assert.assertNotNull(cookies);
@@ -108,9 +107,7 @@ public class TestCookie2Support extends 
 
         HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e2 = response2.getEntity();
-        if (e2 != null) {
-            e2.consumeContent();
-        }
+        EntityUtils.consume(e2);
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
 
@@ -150,9 +147,7 @@ public class TestCookie2Support extends 
 
         HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e1 = response1.getEntity();
-        if (e1 != null) {
-            e1.consumeContent();
-        }
+        EntityUtils.consume(e1);
 
         List<Cookie> cookies = cookieStore.getCookies();
         Assert.assertNotNull(cookies);
@@ -160,9 +155,7 @@ public class TestCookie2Support extends 
 
         HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e2 = response2.getEntity();
-        if (e2 != null) {
-            e2.consumeContent();
-        }
+        EntityUtils.consume(e2);
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
 
@@ -201,9 +194,7 @@ public class TestCookie2Support extends 
 
         HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e1 = response1.getEntity();
-        if (e1 != null) {
-            e1.consumeContent();
-        }
+        EntityUtils.consume(e1);
 
         List<Cookie> cookies = cookieStore.getCookies();
         Assert.assertNotNull(cookies);
@@ -211,9 +202,7 @@ public class TestCookie2Support extends 
 
         HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e2 = response2.getEntity();
-        if (e2 != null) {
-            e2.consumeContent();
-        }
+        EntityUtils.consume(e2);
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
 
@@ -253,9 +242,7 @@ public class TestCookie2Support extends 
 
         HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e1 = response1.getEntity();
-        if (e1 != null) {
-            e1.consumeContent();
-        }
+        EntityUtils.consume(e1);
 
         List<Cookie> cookies = cookieStore.getCookies();
         Assert.assertNotNull(cookies);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRedirects.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRedirects.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRedirects.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRedirects.java
Mon Aug 30 20:01:46 2010
@@ -32,7 +32,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.http.Header;
-import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
@@ -60,6 +59,7 @@ import org.apache.http.protocol.Executio
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -231,10 +231,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -257,10 +254,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -287,10 +281,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -325,10 +316,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -355,10 +343,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -385,10 +370,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -411,10 +393,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -437,10 +416,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -501,10 +477,7 @@ public class TestRedirects extends Basic
         httppost.setEntity(new StringEntity("stuff"));
 
         HttpResponse response = client.execute(getServerHttp(), httppost, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -529,10 +502,7 @@ public class TestRedirects extends Basic
         httppost.setEntity(new StringEntity("stuff"));
 
         HttpResponse response = client.execute(getServerHttp(), httppost, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -557,10 +527,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -588,10 +555,7 @@ public class TestRedirects extends Basic
         HttpGet httpget = new HttpGet("/test/oldlocation");
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -678,10 +642,7 @@ public class TestRedirects extends Basic
 
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -714,10 +675,7 @@ public class TestRedirects extends Basic
 
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestUriEscapes.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestUriEscapes.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestUriEscapes.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestUriEscapes.java
Mon Aug 30 20:01:46 2010
@@ -42,6 +42,7 @@ import org.apache.http.localserver.Basic
 import org.apache.http.localserver.LocalTestServer;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -89,12 +90,12 @@ public class TestUriEscapes extends Basi
             String request = "http://" + host + ":" + port + uri;
             HttpGet httpget = new HttpGet(request);
             response = client.execute(httpget);
-            response.getEntity().consumeContent();
+            EntityUtils.consume(response.getEntity());
         } else {
             HttpHost target = new HttpHost(host, port);
             HttpGet httpget = new HttpGet(uri);
             response = client.execute(target, httpget);
-            response.getEntity().consumeContent();
+            EntityUtils.consume(response.getEntity());
         }
 
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionAutoRelease.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionAutoRelease.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionAutoRelease.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionAutoRelease.java
Mon Aug 30 20:01:46 2010
@@ -87,7 +87,7 @@ public class TestConnectionAutoRelease e
 
         HttpEntity e = response.getEntity();
         Assert.assertNotNull(e);
-        e.consumeContent();
+        EntityUtils.consume(e);
 
         // Expect one connection in the pool
         Assert.assertEquals(1, mgr.getConnectionsInPool());

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
Mon Aug 30 20:01:46 2010
@@ -32,7 +32,6 @@ import java.net.InetSocketAddress;
 import java.net.URI;
 
 import org.apache.http.Header;
-import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
@@ -59,6 +58,7 @@ import org.apache.http.protocol.Response
 import org.apache.http.protocol.ResponseContent;
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
+import org.apache.http.util.EntityUtils;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
@@ -301,15 +301,13 @@ public class TestConnectionReuse {
         HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
 
         HttpResponse response = client.execute(target, new HttpGet("/random/2000"));
-        if(response.getEntity() != null)
-            response.getEntity().consumeContent();
+        EntityUtils.consume(response.getEntity());
 
         Assert.assertEquals(1, mgr.getConnectionsInPool());
         Assert.assertEquals(1, localServer.getAcceptedConnectionCount());
 
         response = client.execute(target, new HttpGet("/random/2000"));
-        if(response.getEntity() != null)
-            response.getEntity().consumeContent();
+        EntityUtils.consume(response.getEntity());
 
         Assert.assertEquals(1, mgr.getConnectionsInPool());
         Assert.assertEquals(1, localServer.getAcceptedConnectionCount());
@@ -317,8 +315,7 @@ public class TestConnectionReuse {
         // Now sleep for 1.1 seconds and let the timeout do its work
         Thread.sleep(1100);
         response = client.execute(target, new HttpGet("/random/2000"));
-        if(response.getEntity() != null)
-            response.getEntity().consumeContent();
+        EntityUtils.consume(response.getEntity());
 
         Assert.assertEquals(1, mgr.getConnectionsInPool());
         Assert.assertEquals(2, localServer.getAcceptedConnectionCount());
@@ -327,8 +324,7 @@ public class TestConnectionReuse {
         // sure we reuse that connection.
         Thread.sleep(500);
         response = client.execute(target, new HttpGet("/random/2000"));
-        if(response.getEntity() != null)
-            response.getEntity().consumeContent();
+        EntityUtils.consume(response.getEntity());
 
         Assert.assertEquals(1, mgr.getConnectionsInPool());
         Assert.assertEquals(2, localServer.getAcceptedConnectionCount());
@@ -372,10 +368,7 @@ public class TestConnectionReuse {
                     if (this.forceClose) {
                         httpget.abort();
                     } else {
-                        HttpEntity entity = response.getEntity();
-                        if (entity != null) {
-                            entity.consumeContent();
-                        }
+                        EntityUtils.consume(response.getEntity());
                     }
                 }
             } catch (Exception ex) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNegotiateScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNegotiateScheme.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNegotiateScheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNegotiateScheme.java
Mon Aug 30 20:01:46 2010
@@ -29,9 +29,6 @@ package org.apache.http.impl.auth;
 import java.io.IOException;
 import java.security.Principal;
 
-import junit.framework.Assert;
-
-import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
@@ -51,12 +48,14 @@ import org.apache.http.message.BasicHead
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.util.EntityUtils;
 
 import org.ietf.jgss.GSSContext;
 import org.ietf.jgss.GSSCredential;
 import org.ietf.jgss.GSSManager;
 import org.ietf.jgss.GSSName;
 import org.ietf.jgss.Oid;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -188,10 +187,7 @@ public class TestNegotiateScheme extends
         String s = "/path";
         HttpGet httpget = new HttpGet(s);
         HttpResponse response = client.execute(httpget);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         ((NegotiateSchemeFactoryWithMockGssManager)nsf).scheme.verify();
 
@@ -222,10 +218,7 @@ public class TestNegotiateScheme extends
         String s = "/path";
         HttpGet httpget = new HttpGet(s);
         HttpResponse response = client.execute(httpget);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         nsf.scheme.verify();
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
Mon Aug 30 20:01:46 2010
@@ -60,6 +60,7 @@ import org.apache.http.protocol.Response
 import org.apache.http.protocol.ResponseContent;
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
+import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -103,12 +104,12 @@ public class TestClientAuthentication ex
     static class AuthExpectationVerifier implements HttpExpectationVerifier {
 
         private final BasicAuthTokenExtractor authTokenExtractor;
-        
+
         public AuthExpectationVerifier() {
             super();
             this.authTokenExtractor = new BasicAuthTokenExtractor();
         }
-        
+
         public void verify(
                 final HttpRequest request,
                 final HttpResponse response,
@@ -166,7 +167,7 @@ public class TestClientAuthentication ex
         HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
-        entity.consumeContent();
+        EntityUtils.consume(entity);
         AuthScope authscope = credsProvider.getAuthScope();
         Assert.assertNotNull(authscope);
         Assert.assertEquals("test realm", authscope.getRealm());
@@ -189,7 +190,7 @@ public class TestClientAuthentication ex
         HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
-        entity.consumeContent();
+        EntityUtils.consume(entity);
         AuthScope authscope = credsProvider.getAuthScope();
         Assert.assertNotNull(authscope);
         Assert.assertEquals("test realm", authscope.getRealm());
@@ -212,7 +213,7 @@ public class TestClientAuthentication ex
         HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
-        entity.consumeContent();
+        EntityUtils.consume(entity);
         AuthScope authscope = credsProvider.getAuthScope();
         Assert.assertNotNull(authscope);
         Assert.assertEquals("test realm", authscope.getRealm());
@@ -298,7 +299,7 @@ public class TestClientAuthentication ex
         HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
-        entity.consumeContent();
+        EntityUtils.consume(entity);
         AuthScope authscope = credsProvider.getAuthScope();
         Assert.assertNotNull(authscope);
         Assert.assertEquals("test realm", authscope.getRealm());
@@ -384,13 +385,13 @@ public class TestClientAuthentication ex
         HttpEntity entity1 = response1.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response1.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity1);
-        entity1.consumeContent();
+        EntityUtils.consume(entity1);
 
         HttpResponse response2 = httpclient.execute(getServerHttp(), httpget, context);
         HttpEntity entity2 = response1.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response2.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity2);
-        entity1.consumeContent();
+        EntityUtils.consume(entity2);
 
         Assert.assertEquals(1, authHandler.getCount());
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
Mon Aug 30 20:01:46 2010
@@ -34,7 +34,6 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.http.Header;
 import org.apache.http.HttpClientConnection;
-import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
@@ -74,6 +73,7 @@ import org.apache.http.protocol.Executio
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestExecutor;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -607,10 +607,7 @@ public class TestDefaultClientRequestDir
         HttpGet httpget = new HttpGet(s);
 
         HttpResponse response = client.execute(httpget);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
     }
 
@@ -630,10 +627,7 @@ public class TestDefaultClientRequestDir
         httpget.getParams().setParameter(ClientPNames.DEFAULT_HOST, target2);
 
         HttpResponse response = client.execute(httpget);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
     }
 
@@ -717,10 +711,7 @@ public class TestDefaultClientRequestDir
         HttpGet httpget = new HttpGet(s);
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestWrapper.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestWrapper.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestWrapper.java
Mon Aug 30 20:01:46 2010
@@ -28,7 +28,6 @@ package org.apache.http.impl.client;
 
 import java.io.IOException;
 
-import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
@@ -41,6 +40,7 @@ import org.apache.http.protocol.BasicHtt
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -85,10 +85,7 @@ public class TestRequestWrapper extends 
         HttpGet httpget = new HttpGet(s);
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
@@ -111,10 +108,7 @@ public class TestRequestWrapper extends 
         HttpGet httpget = new HttpGet(s);
 
         HttpResponse response = client.execute(getServerHttp(), httpget, context);
-        HttpEntity e = response.getEntity();
-        if (e != null) {
-            e.consumeContent();
-        }
+        EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestStatefulConnManagement.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestStatefulConnManagement.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestStatefulConnManagement.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestStatefulConnManagement.java
Mon Aug 30 20:01:46 2010
@@ -27,7 +27,6 @@ package org.apache.http.impl.client;
 
 import java.io.IOException;
 
-import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
@@ -47,6 +46,7 @@ import org.apache.http.protocol.BasicHtt
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -185,10 +185,7 @@ public class TestStatefulConnManagement 
 
                     this.context.setAttribute("r" + r, conn.getState());
 
-                    HttpEntity entity = response.getEntity();
-                    if (entity != null) {
-                        entity.consumeContent();
-                    }
+                    EntityUtils.consume(response.getEntity());
                 }
 
             } catch (Exception ex) {
@@ -229,10 +226,7 @@ public class TestStatefulConnManagement 
         context1.setAttribute("user", "stuff");
         HttpResponse response1 = client.execute(
                 new HttpHost("localhost", port), new HttpGet("/"), context1);
-        HttpEntity entity1 = response1.getEntity();
-        if (entity1 != null) {
-            entity1.consumeContent();
-        }
+        EntityUtils.consume(response1.getEntity());
 
         // The ConnPoolByRoute now has 1 free connection, out of 2 max
         // The ConnPoolByRoute has one RouteSpcfcPool, that has one free connection
@@ -245,10 +239,7 @@ public class TestStatefulConnManagement 
         HttpContext context2 = new BasicHttpContext();
         HttpResponse response2 = client.execute(
                 new HttpHost("127.0.0.1", port), new HttpGet("/"), context2);
-        HttpEntity entity2 = response2.getEntity();
-        if (entity2 != null) {
-            entity2.consumeContent();
-        }
+        EntityUtils.consume(response2.getEntity());
         // ConnPoolByRoute now has 2 free connexions, out of its 2 max.
         // The [localhost][stuff] RouteSpcfcPool is the same as earlier
         // And there is a [127.0.0.1][null] pool with 1 free connection
@@ -267,10 +258,7 @@ public class TestStatefulConnManagement 
         // If the ConnPoolByRoute did not behave coherently with the RouteSpecificPool
         // this may fail. Ex : if the ConnPool discared the route pool because it was empty,
         // but still used it to build the request3 connection.
-        HttpEntity entity3 = response3.getEntity();
-        if (entity3 != null) {
-            entity3.consumeContent();
-        }
+        EntityUtils.consume(response3.getEntity());
 
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java
Mon Aug 30 20:01:46 2010
@@ -30,7 +30,6 @@ package org.apache.http.impl.conn;
 import java.net.InetSocketAddress;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.ClientProtocolException;
@@ -48,6 +47,7 @@ import org.apache.http.localserver.Serve
 import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
+import org.apache.http.util.EntityUtils;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -128,10 +128,7 @@ public class TestIdleConnectionEviction 
                         this.request.abort();
                         throw new ClientProtocolException("Unexpected status code: " + status);
                     }
-                    HttpEntity entity = response.getEntity();
-                    if (entity != null) {
-                        entity.consumeContent();
-                    }
+                    EntityUtils.consume(response.getEntity());
                     Thread.sleep(10);
                 }
             } catch (Exception ex) {

Modified: httpcomponents/httpclient/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/pom.xml?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/pom.xml (original)
+++ httpcomponents/httpclient/trunk/pom.xml Mon Aug 30 20:01:46 2010
@@ -68,7 +68,7 @@
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
-    <httpcore.version>4.1-beta1</httpcore.version>
+    <httpcore.version>4.1-beta2</httpcore.version>
     <commons-logging.version>1.1.1</commons-logging.version>
     <commons-codec.version>1.4</commons-codec.version>
     <ehcache.version>2.2.0</ehcache.version>

Modified: httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml?rev=990924&r1=990923&r2=990924&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml (original)
+++ httpcomponents/httpclient/trunk/src/docbkx/fundamentals.xml Mon Aug 30 20:01:46 2010
@@ -296,16 +296,30 @@ important message
         </section>
         <section>
             <title>Ensuring release of low level resources</title>
-            <para>When finished with a response entity, it's important to ensure that
all entity
-                content has been fully consumed, so that the connection could be safely returned
to
-                the connection pool and re-used by the connection manager for subsequent
requests.
-                The easiest way to do so is to call the
-                    <methodname>HttpEntity#consumeContent(</methodname>) method
to consume any
-                available content on the stream. HttpClient will automatically release the
-                underlying connection back to the connection manager as soon as it detects
that the
-                end of the content stream has been reached. The
-                    <methodname>HttpEntity#consumeContent()</methodname> method
is safe to call more
-                than once.</para>
+            <para> In order to ensure proper release of system resources one must close
the content
+                stream associated with the entity.</para>
+            <programlisting><![CDATA[
+HttpResponse response;
+HttpEntity entity = response.getEntity();
+if (entity != null) {
+    InputStream instream = entity.getContent();
+    try {
+        // do something useful
+    } finally {
+        instream.close();
+    }
+}
+]]></programlisting>
+            <para>Please note that <methodname>HttpEntity#writeTo(OutputStream)</methodname>

+                method is also required to ensure proper release of system resources once
the 
+                entity has been fully written out. If this method obtains an instance of

+                <classname>java.io.InputStream</classname> by calling 
+                <methodname>HttpEntity#getContent()</methodname>, it is also
expected to close
+                the stream in a finally clause.</para>
+            <para>When working with streaming entities, one can use the
+                <methodname>EntityUtils#consume(HttpEntity)</methodname> method
to ensure that
+                the entity content has been fully consumed and the underlying stream has
been
+                closed.</para>
             <para>There can be situations, however, when only a small portion of the
entire response
                 content needs to be retrieved and the performance penalty for consuming the
                 remaining content and making the connection reusable is too high, one can
simply



Mime
View raw message