hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Abley (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1075) ContentEncodingHttpClient.execute(HttpGet, ResponseHandler<T>) throws IOException when reading chunked gzip response
Date Thu, 31 Mar 2011 22:15:06 GMT

    [ 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


Mime
View raw message