You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Adam Hahn (JIRA)" <ji...@apache.org> on 2011/03/30 03:55:05 UTC

[jira] [Created] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
--------------------------------------------------------------------------------------------------------------------

                 Key: HTTPCLIENT-1075
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient
    Affects Versions: 4.1.1
         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.

`java -version` output:
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
            Reporter: Adam Hahn
             Fix For: 4.1.2


The following snippet:

    String url = "http://yahoo.com";
    HttpClient httpClient = new ContentEncodingHttpClient();
    HttpGet get = new HttpGet(url);
    String content = httpClient.execute(get, new BasicResponseHandler());

throws:

java.io.IOException: Attempted read from closed stream.
	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)

whereas the following snippet runs fine:

    String url = "http://yahoo.com";
    HttpClient httpClient = new ContentEncodingHttpClient();
    HttpGet get = new HttpGet(url);
    HttpResponse response = httpClient.execute(get);
    HttpEntity entity = response.getEntity();
    String content = EntityUtils.toString(entity);

These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "James Abley (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13014266#comment-13014266 ] 

James Abley commented on HTTPCLIENT-1075:
-----------------------------------------

My bad from the original implementation.

The implementations of HttpEntity.getContent() on the decompressing implementations were returning a new InputStream each time. From my reading of the API docs, they should have returned the same instance, since the content wasn't repeatable. I've attached a patch containing both tests which demonstrate the problem and the proposed fix which makes the tests green.

> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "Mirko Friedenhagen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13017619#comment-13017619 ] 

Mirko Friedenhagen commented on HTTPCLIENT-1075:
------------------------------------------------

I retried my tests with the version from:

[mirko@borg 4.1.x]$ svn info
Path: .
URL: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.1.x
Repository Root: https://svn.apache.org/repos/asf
Repository UUID: 13f79535-47bb-0310-9956-ffa450edef68
Revision: 1090406
Node Kind: directory
Schedule: normal
Last Changed Author: olegk
Last Changed Rev: 1088006
Last Changed Date: 2011-04-02 13:47:25 +0200 (Sat, 02 Apr 2011)

Works flawlessly. Any hints, when 4.1.2 will be released?


> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "James Abley (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13017620#comment-13017620 ] 

James Abley commented on HTTPCLIENT-1075:
-----------------------------------------

MIrko,

Sorry, I should have made my comments clearer. I picked up that the problem was with the interaction between BasicResponseHandler and the ResponseContentEncoding class. Your test in the previous comment runs without problems against current trunk code and the branch 4.1.x.

Thanks for the clarification.

> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Updated] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading compressed response

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski updated HTTPCLIENT-1075:
------------------------------------------

    Summary: ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading compressed response  (was: ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response)

Done.

Oleg

> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading compressed response
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "James Abley (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13019367#comment-13019367 ] 

James Abley commented on HTTPCLIENT-1075:
-----------------------------------------

Oleg,

I suggest editing the name of this issue to be "ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading compressed response" to make it clearer what the underlying issue was? It affected both deflate and gzip responses, and the fix handles both cases. Chunking had no bearing on the bug as far as I can tell.

Thanks,

James

> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "Mirko Friedenhagen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13017607#comment-13017607 ] 

Mirko Friedenhagen commented on HTTPCLIENT-1075:
------------------------------------------------

Just as a comment: this is not only true for chunked responses:
{code}
import java.io.IOException;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.RequestAcceptEncoding;
import org.apache.http.client.protocol.ResponseContentEncoding;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;

public class BasicTest {

    @Test
    public void testIt() throws IOException {
        DefaultHttpClient c = new DefaultHttpClient();
        c.addRequestInterceptor(new RequestAcceptEncoding());
        c.addResponseInterceptor(new ResponseContentEncoding());
        HttpGet get = new HttpGet("http://www.web.de/");
        c.execute(get, new BasicResponseHandler() {
            public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
                final Header[] allHeaders = response.getAllHeaders();
                for (final Header header : allHeaders) {
                  System.out.println(header);
                }
                return super.handleResponse(response);
            }
        });
    }
}
{code}

responds with:

{code}
java.io.EOFException
	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:249)
	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:239)
	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:142)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:67)
	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
	at BasicTest.testIt(BasicTest.java:24)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
{code}


> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Resolved] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCLIENT-1075.
-------------------------------------------

    Resolution: Fixed

I improved slightly the way decompressing entities handle content streaming and committed the patch to both SVN trunk and 4.1.x branch.

Please review and re-test.

Oleg

> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "James Abley (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13014239#comment-13014239 ] 

James Abley commented on HTTPCLIENT-1075:
-----------------------------------------

I've taken a quick look at this and have a couple of questions.

The failing case is getting the exception due to the 'mop up' code in AbstractHttpClient, line 974.

{code}
// Handling the response was successful. Ensure that the content has
// been fully consumed.
HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
return result;
{code}

I'm not familiar enough with the code base to say why this code is there. When it gets to this point, the result variable has already been populated with the uncompressed content as an HTML string, and the InputStream has been closed, due to the handling in BasicResponseHandler.

Could someone confirm that the code is AbstractHttpClient at this point is necessary and correct?

Looking an EntityUtils.consume(HttpEntity):

{code}
if (entity == null) {
    return;
}
if (entity.isStreaming()) {
    InputStream instream = entity.getContent();
    if (instream != null) {
        instream.close();
    }
}
{code}

Should perhaps the InputStream returned by GzipDecompressingEntity be a decorated form that tracks when close() has been called on the InputStream. Subsequent calls to entity.getContent() could then return null, or an InputStream that can safely have close() called on it?

> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "Mirko Friedenhagen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13017621#comment-13017621 ] 

Mirko Friedenhagen commented on HTTPCLIENT-1075:
------------------------------------------------

So maybe the subject should just be updated "when reading gzip response" as well ;-)? Anyway, I am happy this is already resolved.

> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13018268#comment-13018268 ] 

Oleg Kalnichevski commented on HTTPCLIENT-1075:
-----------------------------------------------

> Any hints, when 4.1.2 will be released? 

@Mirko

There are no immediate plans to release 4.1.2. Provided there are no critical issues we try to have a release every 3 to 6 months.

Oleg

> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Updated] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "James Abley (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James Abley updated HTTPCLIENT-1075:
------------------------------------

    Attachment: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch

Patch which seems to address the issue.

> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Issue Comment Edited] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler) throws IOException when reading chunked gzip response

Posted by "Mirko Friedenhagen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13017607#comment-13017607 ] 

Mirko Friedenhagen edited comment on HTTPCLIENT-1075 at 4/8/11 7:18 PM:
------------------------------------------------------------------------

Just as a comment: this applies as well for non-chunked responses:
{code}
import java.io.IOException;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.RequestAcceptEncoding;
import org.apache.http.client.protocol.ResponseContentEncoding;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;

public class BasicTest {

    @Test
    public void testIt() throws IOException {
        DefaultHttpClient c = new DefaultHttpClient();
        c.addRequestInterceptor(new RequestAcceptEncoding());
        c.addResponseInterceptor(new ResponseContentEncoding());
        HttpGet get = new HttpGet("http://www.web.de/");
        c.execute(get, new BasicResponseHandler() {
            public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
                final Header[] allHeaders = response.getAllHeaders();
                for (final Header header : allHeaders) {
                  System.out.println(header);
                }
                return super.handleResponse(response);
            }
        });
    }
}
{code}

responds with:

{code}
java.io.EOFException
	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:249)
	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:239)
	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:142)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:67)
	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
	at BasicTest.testIt(BasicTest.java:24)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
{code}


      was (Author: mfriedenhagen):
    Just as a comment: this is not only true for chunked responses:
{code}
import java.io.IOException;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.RequestAcceptEncoding;
import org.apache.http.client.protocol.ResponseContentEncoding;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;

public class BasicTest {

    @Test
    public void testIt() throws IOException {
        DefaultHttpClient c = new DefaultHttpClient();
        c.addRequestInterceptor(new RequestAcceptEncoding());
        c.addResponseInterceptor(new ResponseContentEncoding());
        HttpGet get = new HttpGet("http://www.web.de/");
        c.execute(get, new BasicResponseHandler() {
            public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
                final Header[] allHeaders = response.getAllHeaders();
                for (final Header header : allHeaders) {
                  System.out.println(header);
                }
                return super.handleResponse(response);
            }
        });
    }
}
{code}

responds with:

{code}
java.io.EOFException
	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:249)
	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:239)
	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:142)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:67)
	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
	at BasicTest.testIt(BasicTest.java:24)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
{code}

  
> ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1075
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1075
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.1
>         Environment: I'm using HttpClient 4.1.1 on Mac OS X 10.6.7.
> `java -version` output:
> java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Adam Hahn
>             Fix For: 4.1.2
>
>         Attachments: 0001-HTTPCLIENT-1075-ContentEncodingHttpClient-fails-when.patch
>
>
> The following snippet:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     String content = httpClient.execute(get, new BasicResponseHandler());
> throws:
> java.io.IOException: Attempted read from closed stream.
> 	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:126)
> 	at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:42)
> 	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:205)
> 	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:136)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.http.client.entity.GzipDecompressingEntity.getContent(GzipDecompressingEntity.java:63)
> 	at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
> 	at org.apache.http.util.EntityUtils.consume(EntityUtils.java:65)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:919)
> 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:910)
> 	at tv.adap.service.HttpPoolTest.testChunkedGzip(HttpPoolTest.java:41)
> whereas the following snippet runs fine:
>     String url = "http://yahoo.com";
>     HttpClient httpClient = new ContentEncodingHttpClient();
>     HttpGet get = new HttpGet(url);
>     HttpResponse response = httpClient.execute(get);
>     HttpEntity entity = response.getEntity();
>     String content = EntityUtils.toString(entity);
> These two snippets should be functionally the same (putting the entity body into content). Creating a JIRA per the recommendation of Oleg from httpclient-users.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org