hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1422996 - in /httpcomponents/httpclient/branches/4.2.x: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
Date Mon, 17 Dec 2012 16:11:12 GMT
Author: olegk
Date: Mon Dec 17 16:11:11 2012
New Revision: 1422996

URL: http://svn.apache.org/viewvc?rev=1422996&view=rev
Log:
HTTPCLIENT-1281: GzipDecompressingEntity does not release InputStream when an IOException
occurs while reading the Gzip header
Contributed by Francois-Xavier Bonnet <francois-xavier.bonnet at centraliens.net>

Added:
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
  (with props)
Modified:
    httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java

Modified: httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt?rev=1422996&r1=1422995&r2=1422996&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt Mon Dec 17 16:11:11 2012
@@ -1,6 +1,10 @@
 Changes since 4.2.2
 -------------------
 
+* [HTTPCLIENT-1281] GzipDecompressingEntity does not release InputStream when an IOException

+  occurs while reading the Gzip header 
+  Contributed by Francois-Xavier Bonnet <francois-xavier.bonnet at centraliens.net>

+
 * [HTTPCLIENT-1277] Caching client sends a 304 to an unconditional request.
   Contributed by Francois-Xavier Bonnet <francois-xavier.bonnet at centraliens.net>
 

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java?rev=1422996&r1=1422995&r2=1422996&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java
Mon Dec 17 16:11:11 2012
@@ -31,6 +31,7 @@ import java.io.OutputStream;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.entity.HttpEntityWrapper;
+import org.apache.http.util.EntityUtils;
 
 /**
  * Common base class for decompressing {@link HttpEntity} implementations.
@@ -67,13 +68,18 @@ abstract class DecompressingEntity exten
      */
     @Override
     public InputStream getContent() throws IOException {
-        if (wrappedEntity.isStreaming()) {
-            if (content == null) {
-                content = getDecompressingInputStream(wrappedEntity.getContent());
+        try {
+            if (wrappedEntity.isStreaming()) {
+                if (content == null) {
+                    content = getDecompressingInputStream(wrappedEntity.getContent());
+                }
+                return content;
+            } else {
+                return getDecompressingInputStream(wrappedEntity.getContent());
             }
-            return content;
-        } else {
-            return getDecompressingInputStream(wrappedEntity.getContent());
+        } catch (IOException e) {
+            EntityUtils.consume(wrappedEntity);
+            throw e;
         }
     }
 

Added: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java?rev=1422996&view=auto
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
(added)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
Mon Dec 17 16:11:11 2012
@@ -0,0 +1,69 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.entity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import junit.framework.Assert;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.InputStreamEntity;
+import org.junit.Test;
+
+public class TestGZip {
+
+    @Test
+    public void testGzipDecompressingEntityDoesNotCrashInConstructorAndLeaveInputStreamOpen()
+            throws Exception {
+        final AtomicBoolean inputStreamIsClosed = new AtomicBoolean(false);
+        HttpEntity in = new InputStreamEntity(new InputStream() {
+            @Override
+            public int read() throws IOException {
+                throw new IOException("An exception occurred");
+            }
+
+            @Override
+            public void close() throws IOException {
+                inputStreamIsClosed.set(true);
+            }
+
+        }, 123);
+        GzipDecompressingEntity gunzipe = new GzipDecompressingEntity(in);
+        try {
+            gunzipe.getContent();
+        } catch (IOException e) {
+            // As I cannot get the content, GzipDecompressingEntity is supposed
+            // to have released everything
+            Assert.assertTrue(inputStreamIsClosed.get());
+        }
+    }
+
+}

Propchange: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message