hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1412858 - in /httpcomponents/httpclient/trunk: ./ httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ httpclient-cache/src/test/java/org/apache/http/impl/client/cache/
Date Fri, 23 Nov 2012 12:45:03 GMT
Author: olegk
Date: Fri Nov 23 12:45:02 2012
New Revision: 1412858

URL: http://svn.apache.org/viewvc?rev=1412858&view=rev
Log:
HTTPCLIENT-1263: CachingHttpClient fails to release connections back to the connection manager
for some type of HTTP response messages when used together with DecompressingHttpClient
Contributed by Francois-Xavier Bonnet <francois-xavier.bonnet at centraliens.net>

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1412858&r1=1412857&r2=1412858&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Fri Nov 23 12:45:02 2012
@@ -5,6 +5,14 @@ Changes in trunk
   Javadoc incorrectly states StringBody(String)'s encoding uses the system default. 
   Contributed by Tim <tdhutt at gmail.com> and Gary Gregory <ggregory at apache.org>

 
+* [HTTPCLIENT-1263] CachingHttpClient fails to release connections back to the connection
+  manager for some type of HTTP response messages when used together with DecompressingHttpClient.
 
+  Contributed by Francois-Xavier Bonnet <francois-xavier.bonnet at centraliens.net>

+
+* [HTTPCLIENT-1258] Fixed NullPointerException in NTLMEngineImpl caused by null NT domain
+  attribute.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1254] Redirect with underscore in hostname causes ProtocolException.
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java?rev=1412858&r1=1412857&r2=1412858&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
Fri Nov 23 12:45:02 2012
@@ -48,6 +48,7 @@ import org.apache.http.client.cache.Reso
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
 
 class BasicHttpCache implements HttpCache {
 
@@ -238,25 +239,33 @@ class BasicHttpCache implements HttpCach
             throws IOException {
 
         SizeLimitedResponseReader responseReader = getResponseReader(request, originResponse);
-        responseReader.readResponse();
+        try {
+            responseReader.readResponse();
 
-        if (responseReader.isLimitReached()) {
-            return responseReader.getReconstructedResponse();
-        }
+            if (responseReader.isLimitReached()) {
+                return responseReader.getReconstructedResponse();
+            }
 
-        Resource resource = responseReader.getResource();
-        if (isIncompleteResponse(originResponse, resource)) {
-            return generateIncompleteResponseError(originResponse, resource);
-        }
+            Resource resource = responseReader.getResource();
+            if (isIncompleteResponse(originResponse, resource)) {
+                return generateIncompleteResponseError(originResponse, resource);
+            }
 
-        HttpCacheEntry entry = new HttpCacheEntry(
-                requestSent,
-                responseReceived,
-                originResponse.getStatusLine(),
-                originResponse.getAllHeaders(),
-                resource);
-        storeInCache(host, request, entry);
-        return responseGenerator.generateResponse(entry);
+            HttpCacheEntry entry = new HttpCacheEntry(
+                    requestSent,
+                    responseReceived,
+                    originResponse.getStatusLine(),
+                    originResponse.getAllHeaders(),
+                    resource);
+            storeInCache(host, request, entry);
+            return responseGenerator.generateResponse(entry);
+        } catch (IOException ex) {
+            EntityUtils.consume(originResponse.getEntity());
+            throw ex;
+        } catch (RuntimeException ex) {
+            EntityUtils.consumeQuietly(originResponse.getEntity());
+            throw ex;
+        }
     }
 
     SizeLimitedResponseReader getResponseReader(HttpRequest request, HttpResponse backEndResponse)
{

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java?rev=1412858&r1=1412857&r2=1412858&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java
Fri Nov 23 12:45:02 2012
@@ -100,7 +100,13 @@ class SizeLimitedResponseReader {
         }
         String uri = request.getRequestLine().getUri();
         instream = entity.getContent();
-        resource = resourceFactory.generate(uri, instream, limit);
+        try {
+            resource = resourceFactory.generate(uri, instream, limit);
+        } finally {
+            if (!limit.isReached()) {
+                instream.close();
+            }
+        }
     }
 
     boolean isLimitReached() {

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java?rev=1412858&r1=1412857&r2=1412858&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
Fri Nov 23 12:45:02 2012
@@ -33,6 +33,7 @@ import static org.junit.Assert.assertNul
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.util.Date;
 import java.util.HashMap;
@@ -48,9 +49,11 @@ import org.apache.http.client.cache.Http
 import org.apache.http.client.cache.Resource;
 import org.apache.http.client.methods.HttpDelete;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -379,4 +382,28 @@ public class TestBasicHttpCache {
 
     }
 
+    @Test
+    public void testOriginalResponseWithNoContentSizeHeaderIsReleased() throws Exception
{
+        HttpHost host = new HttpHost("foo.example.com");
+        HttpRequest request = new HttpGet("http://foo.example.com/bar");
+
+        Date now = new Date();
+        Date requestSent = new Date(now.getTime() - 3 * 1000L);
+        Date responseGenerated = new Date(now.getTime() - 2 * 1000L);
+        Date responseReceived = new Date(now.getTime() - 1 * 1000L);
+
+        HttpResponse originResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
"OK");
+        BasicHttpEntity entity = new BasicHttpEntity();
+        ConsumableInputStream inputStream = new ConsumableInputStream(new ByteArrayInputStream(HttpTestUtils.getRandomBytes(CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES
- 1)));
+        entity.setContent(inputStream);
+        originResponse.setEntity(entity);
+        originResponse.setHeader("Cache-Control","public, max-age=3600");
+        originResponse.setHeader("Date", DateUtils.formatDate(responseGenerated));
+        originResponse.setHeader("ETag", "\"etag\"");
+
+        HttpResponse result = impl.cacheAndReturnResponse(host, request, originResponse,
requestSent, responseReceived);
+        EntityUtils.consume(result.getEntity());
+        assertTrue(inputStream.wasClosed());
+    }
+
 }



Mime
View raw message