hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1578440 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
Date Mon, 17 Mar 2014 15:34:42 GMT
Author: olegk
Date: Mon Mar 17 15:34:41 2014
New Revision: 1578440

URL: http://svn.apache.org/r1578440
Log:
HTTPCLIENT-1484: GzipCompressingEntity should not close the underlying output stream if the
entity has not been fully written out due to an exception

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1578440&r1=1578439&r2=1578440&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Mon Mar 17 15:34:41 2014
@@ -4,6 +4,10 @@ Changes for 4.4-alpha1
 Changelog:
 -------------------
 
+* [HTTPCLIENT-1484] GzipCompressingEntity should not close the underlying output stream
+  if the entity has not been fully written out due to an exception.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1474] Fixed broken entity enclosing requests in HC Fluent.
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java?rev=1578440&r1=1578439&r2=1578440&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
Mon Mar 17 15:34:41 2014
@@ -104,11 +104,10 @@ public class GzipCompressingEntity exten
     public void writeTo(final OutputStream outstream) throws IOException {
         Args.notNull(outstream, "Output stream");
         final GZIPOutputStream gzip = new GZIPOutputStream(outstream);
-        try {
-            wrappedEntity.writeTo(gzip);
-        } finally {
-            gzip.close();
-        }
+        wrappedEntity.writeTo(gzip);
+        // Only close output stream if the wrapped entity has been
+        // successfully written out
+        gzip.close();
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java?rev=1578440&r1=1578439&r2=1578440&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
Mon Mar 17 15:34:41 2014
@@ -30,6 +30,7 @@ package org.apache.http.client.entity;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.http.Consts;
@@ -41,6 +42,7 @@ import org.apache.http.entity.StringEnti
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
 import org.junit.Test;
+import org.mockito.Mockito;
 
 public class TestGZip {
 
@@ -93,4 +95,17 @@ public class TestGZip {
         }
     }
 
+    @Test
+    public void testCompressionIOExceptionLeavesOutputStreamOpen() throws Exception {
+        final HttpEntity in = Mockito.mock(HttpEntity.class);
+        Mockito.doThrow(new IOException("Ooopsie")).when(in).writeTo(Mockito.<OutputStream>any());
+        final GzipCompressingEntity gzipe = new GzipCompressingEntity(in);
+        final OutputStream out = Mockito.mock(OutputStream.class);
+        try {
+            gzipe.writeTo(out);
+        } catch (IOException ex) {
+            Mockito.verify(out, Mockito.never()).close();
+        }
+    }
+
 }



Mime
View raw message