You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Mirko Friedenhagen (JIRA)" <ji...@apache.org> on 2011/04/08 21:19:05 UTC

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

    [ 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