hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Doyle (JIRA)" <j...@apache.org>
Subject [jira] [Issue Comment Deleted] (HTTPCLIENT-1550) "deflate" encoding issue : java.util.zip.ZipException: invalid stored block lengths
Date Tue, 18 Jul 2017 02:10:00 GMT

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1550?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Patrick Doyle updated HTTPCLIENT-1550:
--------------------------------------
    Comment: was deleted

(was: This is still happening for me.  I'm using httpclient 4.5.3.

*[EDIT]  Whoops, sorry, my mistake.  I thought the backtrace was more similar than it is.*

Backtrace:

{code}
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
	at java.util.zip.InflaterInputStream.fill(Unknown Source) ~[na:1.8.0_131]
	at java.util.zip.InflaterInputStream.read(Unknown Source) ~[na:1.8.0_131]
	at java.util.zip.GZIPInputStream.read(Unknown Source) ~[na:1.8.0_131]
	at org.apache.http.client.entity.LazyDecompressingInputStream.read(LazyDecompressingInputStream.java:70)
~[httpclient-4.5.3.jar:4.5.3]
	at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) ~[na:1.8.0_131]
	at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[na:1.8.0_131]
	at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[na:1.8.0_131]
	at java.io.InputStreamReader.read(Unknown Source) ~[na:1.8.0_131]
	at java.io.Reader.read(Unknown Source) ~[na:1.8.0_131]
	at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2001) ~[commons-io-2.4.jar:2.4]
	at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1980) ~[commons-io-2.4.jar:2.4]
	at org.apache.commons.io.IOUtils.copy(IOUtils.java:1957) ~[commons-io-2.4.jar:2.4]
	at org.apache.commons.io.IOUtils.copy(IOUtils.java:1907) ~[commons-io-2.4.jar:2.4]
	at org.apache.commons.io.IOUtils.toString(IOUtils.java:778) ~[commons-io-2.4.jar:2.4]
	at org.apache.commons.io.IOUtils.toString(IOUtils.java:803) ~[commons-io-2.4.jar:2.4]
	at org.vena.icecube.server.Main.lambda$33(Main.java:445) ~[classes/:na]
{code}

It's dying on the last line here:

{code}
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
	if (response.getStatusLine().getStatusCode() == 200) {
		try {
			String body = IOUtils.toString(response.getEntity().getContent(), "utf8");
{code}

The httpClient object was created like this:

{code}
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
{code})

> "deflate" encoding issue : java.util.zip.ZipException: invalid stored block lengths
> -----------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1550
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1550
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>    Affects Versions: 4.3.5
>         Environment: Windows
>            Reporter: Guillaume Serre
>            Priority: Minor
>             Fix For: 4.5.2
>
>
> When trying to GET any nzb files from http://nzbindex.nl with a httpclient request, a
ZipException is raised.
> {code:title=JunitTestFailing.java}
> 	@Test
> 	public void testDeflateIssueFailing() throws ClientProtocolException, IOException {
> 		HttpGet httpget = new HttpGet("http://nzbindex.nl/download/72441827/BackTrack5R3.Gnome.iSO.32bit-LiNUX-0171-bt5r2gis32.par2.nzb");
> 		HttpClient client = HttpClientBuilder.create().build();
> 		HttpResponse response = client.execute(httpget);
> 		HttpEntity entity = response.getEntity();
> 		byte[] data = EntityUtils.toByteArray( entity );
> 		Assert.assertEquals( data.length, 423548 );
> 	}
> {code}
> The complete stack trace I get is this:
> {code}
> java.util.zip.ZipException: invalid stored block lengths
> 	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
> 	at java.io.FilterInputStream.read(FilterInputStream.java:107)
> 	at org.apache.http.client.entity.DeflateInputStream.read(DeflateInputStream.java:144)
> 	at org.apache.http.client.entity.LazyDecompressingInputStream.read(LazyDecompressingInputStream.java:68)
> 	at org.apache.http.util.EntityUtils.toByteArray(EntityUtils.java:136)
> 	at hclient.HTTPClientTest.testDeflateIssueFailing(HTTPClientTest.java:39)
> {code}
> A workaround I found is to set the Accept-Encoding header to only accept gzip, as follows:
> {code:title=JunitTestWorking.java}
> 	
> 	@Test
> 	public void testDeflateIssueWorking() throws ClientProtocolException, IOException {
> 		HttpGet httpget = new HttpGet("http://nzbindex.nl/download/72441827/BackTrack5R3.Gnome.iSO.32bit-LiNUX-0171-bt5r2gis32.par2.nzb");
> 		httpget.setHeader("Accept-Encoding", "gzip");
> 		HttpClient client = HttpClientBuilder.create().build();
> 		HttpResponse response = client.execute(httpget);
> 		HttpEntity entity = response.getEntity();
> 		byte[] data = EntityUtils.toByteArray( entity );
> 		Assert.assertEquals( data.length, 423548 );
> 	}
> {code}
> Thanks



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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


Mime
View raw message