hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1088006 - in /httpcomponents/httpclient/branches/4.1.x: ./ httpclient/ httpclient/src/main/java/org/apache/http/client/entity/ httpclient/src/test/java/org/apache/http/client/entity/ httpclient/src/test/java/org/apache/http/impl/client/
Date Sat, 02 Apr 2011 11:47:25 GMT
Author: olegk
Date: Sat Apr  2 11:47:25 2011
New Revision: 1088006

URL: http://svn.apache.org/viewvc?rev=1088006&view=rev
Log:
HTTPCLIENT-1075: Decompressing entities (DeflateDecompressingEntity, GzipDecompressingEntity)
do not correctly handle content streaming

Contributed by James Abley <james.abley at gmail.com> 

Added:
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/test/java/org/apache/http/client/entity/
      - copied from r1088000, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/test/java/org/apache/http/client/entity/TestDecompressingEntity.java
      - copied unchanged from r1088000, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestDecompressingEntity.java
Modified:
    httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.1.x/httpclient/   (props changed)
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java

Modified: httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt?rev=1088006&r1=1088005&r2=1088006&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt Sat Apr  2 11:47:25 2011
@@ -1,3 +1,10 @@
+Changes since 4.1.1
+
+* [HTTPCLIENT-1075] Decompressing entities (DeflateDecompressingEntity, GzipDecompressingEntity)

+  do not correctly handle content streaming.
+  Contributed by James Abley <james.abley at gmail.com> 
+
+
 Release 4.1.1
 -------------------
 

Propchange: httpcomponents/httpclient/branches/4.1.x/httpclient/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Sat Apr  2 11:47:25 2011
@@ -0,0 +1,4 @@
+/httpcomponents/httpclient/branches/4.0.x/httpclient:950681-950688
+/httpcomponents/httpclient/branches/branch_4_1/httpclient:755593-811107
+/httpcomponents/httpclient/branches/notice-plugin-test/httpclient:1024348-1031454
+/httpcomponents/httpclient/trunk/httpclient:1087358,1088000-1088004

Modified: httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java?rev=1088006&r1=1088005&r2=1088006&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
(original)
+++ httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
Sat Apr  2 11:47:25 2011
@@ -45,6 +45,12 @@ abstract class DecompressingEntity exten
     private static final int BUFFER_SIZE = 1024 * 2;
 
     /**
+     * DecompressingEntities are not repeatable, so they will return the same
+     * InputStream instance when {@link #getContent()} is called.
+     */
+    private InputStream content;
+
+    /**
      * Creates a new {@link DecompressingEntity}.
      *
      * @param wrapped
@@ -54,6 +60,23 @@ abstract class DecompressingEntity exten
         super(wrapped);
     }
 
+    abstract InputStream getDecompressingInputStream(final InputStream wrapped) throws IOException;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public InputStream getContent() throws IOException {
+        if (wrappedEntity.isStreaming()) {
+            if (content == null) {
+                content = getDecompressingInputStream(wrappedEntity.getContent());
+            }
+            return content;
+        } else {
+            return getDecompressingInputStream(wrappedEntity.getContent());
+        }
+    }
+
     /**
      * {@inheritDoc}
      */

Modified: httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java?rev=1088006&r1=1088005&r2=1088006&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
(original)
+++ httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
Sat Apr  2 11:47:25 2011
@@ -63,12 +63,14 @@ public class DeflateDecompressingEntity 
     }
 
     /**
-     * {@inheritDoc}
+     * Returns the non-null InputStream that should be returned to by all requests to
+     * {@link #getContent()}.
+     *
+     * @return a non-null InputStream
+     * @throws IOException if there was a problem
      */
     @Override
-    public InputStream getContent() throws IOException {
-        InputStream wrapped = this.wrappedEntity.getContent();
-
+    InputStream getDecompressingInputStream(final InputStream wrapped) throws IOException
{
         /*
          * A zlib stream will have a header.
          *

Modified: httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java?rev=1088006&r1=1088005&r2=1088006&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java
(original)
+++ httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java
Sat Apr  2 11:47:25 2011
@@ -51,16 +51,9 @@ public class GzipDecompressingEntity ext
         super(entity);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    public InputStream getContent() throws IOException, IllegalStateException {
-
-        // the wrapped entity's getContent() decides about repeatability
-        InputStream wrappedin = wrappedEntity.getContent();
-
-        return new GZIPInputStream(wrappedin);
+    InputStream getDecompressingInputStream(final InputStream wrapped) throws IOException
{
+        return new GZIPInputStream(wrapped);
     }
 
     /**

Modified: httpcomponents/httpclient/branches/4.1.x/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java?rev=1088006&r1=1088005&r2=1088006&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java
(original)
+++ httpcomponents/httpclient/branches/4.1.x/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java
Sat Apr  2 11:47:25 2011
@@ -313,6 +313,34 @@ public class TestContentCodings extends 
         client.getConnectionManager().shutdown();
     }
 
+    @Test
+    public void gzipResponsesWorkWithBasicResponseHandler() throws Exception {
+        final String entityText = "Hello, this is some plain text coming back.";
+
+        this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
+
+        DefaultHttpClient client = createHttpClient();
+        HttpGet request = new HttpGet("/some-resource");
+        String response = client.execute(getServerHttp(), request, new BasicResponseHandler());
+        Assert.assertEquals("The entity text is correctly transported", entityText, response);
+
+        client.getConnectionManager().shutdown();
+    }
+
+    @Test
+    public void deflateResponsesWorkWithBasicResponseHandler() throws Exception {
+        final String entityText = "Hello, this is some plain text coming back.";
+
+        this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, false));
+
+        DefaultHttpClient client = createHttpClient();
+        HttpGet request = new HttpGet("/some-resource");
+        String response = client.execute(getServerHttp(), request, new BasicResponseHandler());
+        Assert.assertEquals("The entity text is correctly transported", entityText, response);
+
+        client.getConnectionManager().shutdown();
+    }
+
     /**
      * Creates a new {@link HttpRequestHandler} that will attempt to provide a deflate stream
      * Content-Coding.



Mime
View raw message