You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Archie Cobbs (JIRA)" <ji...@apache.org> on 2016/04/20 23:40:25 UTC

[jira] [Commented] (HTTPCLIENT-1738) CLONE - "deflate" encoding issue : java.util.zip.ZipException: invalid block type

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1738?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15250766#comment-15250766 ] 

Archie Cobbs commented on HTTPCLIENT-1738:
------------------------------------------

Note: I couldn't reopen HTTPCLIENT-1550 so I had to clone it instead into this issue.

The bug still occurs, although in a slightly different form.

I have a test case, but unfortunately it requires creating an Athena developer account to get access to their API. However, I've captured the problem using trace-level debugging (note the quoted `Authorization` token is transient and no longer works).

Test program:
{noformat}

import org.apache.http.impl.client.*;
import org.apache.http.impl.*;
import org.apache.http.*;
import org.apache.http.client.methods.*;
import org.apache.http.util.*;

public class Test {
    public static void main(String[] args) throws Exception {

        String[] websites = new String[]{
            "https://api.athenahealth.com/preview1/195900/appointments/changed?departmentid=blah&ignorerestrictions=true&leaveunprocessed=true"
        };
        
        try (CloseableHttpClient client = HttpClients.createDefault()){
            for (String website : websites) {
                System.out.println("getting " + website + "...");
                HttpGet request = new HttpGet(website);
                if (website.startsWith("https"))
                    request.setHeader("Authorization", "Bearer sz2aunzxswk2bb525hddhyap");
                try(CloseableHttpResponse response = client.execute(request)){
                    System.out.println(EntityUtils.toString(response.getEntity()));
                }
            }
        }
    }
}
{noformat}

Trace of problem:
{noformat}
[archie@retina] 581 ./run.sh 
getting https://api.athenahealth.com/preview1/195900/appointments/changed?departmentid=blah&ignorerestrictions=true&leaveunprocessed=true...
DEBUG: CookieSpec selected: default
DEBUG: Auth cache not set in the context
DEBUG: Connection request: [route: {s}->https://api.athenahealth.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
DEBUG: Connection leased: [id: 0][route: {s}->https://api.athenahealth.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
DEBUG: Opening connection {s}->https://api.athenahealth.com:443
DEBUG: Connecting to api.athenahealth.com/107.20.227.47:443
DEBUG: Connecting socket to api.athenahealth.com/107.20.227.47:443 with timeout 0
DEBUG: Enabled protocols: [TLSv1]
DEBUG: Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA, SSL_RSA_WITH_RC4_128_SHA, TLS_ECDH_ECDSA_WITH_RC4_128_SHA, TLS_ECDH_RSA_WITH_RC4_128_SHA, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_RC4_128_MD5, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
DEBUG: Starting handshake
DEBUG: Secure session established
DEBUG:  negotiated protocol: TLSv1
DEBUG:  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
DEBUG:  peer principal: CN=api.athenahealth.com, O="Athenahealth, Inc.", L=Watertown, ST=Massachusetts, C=US
DEBUG:  peer alternative names: [api.athenahealth.com]
DEBUG:  issuer principal: CN=DigiCert SHA2 High Assurance Server CA, OU=www.digicert.com, O=DigiCert Inc, C=US
DEBUG: Connection established 10.10.199.93:64053<->107.20.227.47:443
DEBUG: Executing request GET /preview1/195900/appointments/changed?departmentid=blah&ignorerestrictions=true&leaveunprocessed=true HTTP/1.1
DEBUG: Proxy auth state: UNCHALLENGED
DEBUG: http-outgoing-0 >> GET /preview1/195900/appointments/changed?departmentid=blah&ignorerestrictions=true&leaveunprocessed=true HTTP/1.1
DEBUG: http-outgoing-0 >> Authorization: Bearer sz2aunzxswk2bb525hddhyap
DEBUG: http-outgoing-0 >> Host: api.athenahealth.com
DEBUG: http-outgoing-0 >> Connection: Keep-Alive
DEBUG: http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.2 (Java/1.7.0_45)
DEBUG: http-outgoing-0 >> Accept-Encoding: gzip,deflate
DEBUG: http-outgoing-0 >> "GET /preview1/195900/appointments/changed?departmentid=blah&ignorerestrictions=true&leaveunprocessed=true HTTP/1.1[\r][\n]"
DEBUG: http-outgoing-0 >> "Authorization: Bearer sz2aunwxswk2ef525hddhyap[\r][\n]"
DEBUG: http-outgoing-0 >> "Host: api.athenahealth.com[\r][\n]"
DEBUG: http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
DEBUG: http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.2 (Java/1.7.0_45)[\r][\n]"
DEBUG: http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
DEBUG: http-outgoing-0 >> "[\r][\n]"
DEBUG: http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]"
DEBUG: http-outgoing-0 << "Content-Encoding: gzip[\r][\n]"
DEBUG: http-outgoing-0 << "Content-Type: application/json[\r][\n]"
DEBUG: http-outgoing-0 << "Date: Wed, 20 Apr 2016 21:34:46 GMT[\r][\n]"
DEBUG: http-outgoing-0 << "nnCoection: close[\r][\n]"
DEBUG: http-outgoing-0 << "Pragma: No-cache[\r][\n]"
DEBUG: http-outgoing-0 << "Server: Apache[\r][\n]"
DEBUG: http-outgoing-0 << "Vary: Accept-Encoding[\r][\n]"
DEBUG: http-outgoing-0 << "X-Mashery-Message-ID: 9bb66bde-ce50-41c7-97a2-2c65a7241142[\r][\n]"
DEBUG: http-outgoing-0 << "X-Mashery-Responder: prod-j-worker-us-east-1d-125.mashery.com[\r][\n]"
DEBUG: http-outgoing-0 << "Content-Length: 129[\r][\n]"
DEBUG: http-outgoing-0 << "Connection: keep-alive[\r][\n]"
DEBUG: http-outgoing-0 << "[\r][\n]"
DEBUG: http-outgoing-0 << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x3][0x2][0x0][0x0][0x0][0xff][0xff][0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x3][0x15][0xcb][0xc1][\r][0x83]0[0xc]F[0xe1];SX>#[0x6][0xe8][0xbd][0x1b]t[0x1][0x83][0x5]K!D[0x8e]AT[0x88][0xdd][0x9b]^[0x9f][0xbe]7[0xc]7+B,C7[0xb4]&[0x9][0xfc][0xe2][0xf7]U[0xb1][0x84][0x95]D[0xf1][0xad] +[0x81][0x4][0x1f]i>[0x82]N[0xc9]GO[0x8d][0xe6],+[0x8f][0xc][0xf7][0xdd][0xfb][0xf3]YA*!T}?M[0xa1]c[0xa5]s[0xd3][0x89][0x9f][0x1f]7"[0x97][0xd5]i[0x0][0x0][0x0]"
DEBUG: http-outgoing-0 << HTTP/1.1 400 Bad Request
DEBUG: http-outgoing-0 << Content-Encoding: gzip
DEBUG: http-outgoing-0 << Content-Type: application/json
DEBUG: http-outgoing-0 << Date: Wed, 20 Apr 2016 21:34:46 GMT
DEBUG: http-outgoing-0 << nnCoection: close
DEBUG: http-outgoing-0 << Pragma: No-cache
DEBUG: http-outgoing-0 << Server: Apache
DEBUG: http-outgoing-0 << Vary: Accept-Encoding
DEBUG: http-outgoing-0 << X-Mashery-Message-ID: 9bb66bde-ce50-41c7-97a2-2c65a7241142
DEBUG: http-outgoing-0 << X-Mashery-Responder: prod-j-worker-us-east-1d-125.mashery.com
DEBUG: http-outgoing-0 << Content-Length: 129
DEBUG: http-outgoing-0 << Connection: keep-alive
DEBUG: Connection can be kept alive indefinitely
DEBUG: Connection [id: 0][route: {s}->https://api.athenahealth.com:443] can be kept alive indefinitely
DEBUG: Connection released: [id: 0][route: {s}->https://api.athenahealth.com:443][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
DEBUG: Connection manager is shutting down
DEBUG: http-outgoing-0: Close connection
DEBUG: Connection manager shut down
Exception in thread "main" java.util.zip.ZipException: invalid block type
	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
	at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:116)
	at org.apache.http.client.entity.LazyDecompressingInputStream.read(LazyDecompressingInputStream.java:73)
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
	at java.io.InputStreamReader.read(InputStreamReader.java:184)
	at java.io.Reader.read(Reader.java:140)
	at org.apache.http.util.EntityUtils.toString(EntityUtils.java:247)
	at org.apache.http.util.EntityUtils.toString(EntityUtils.java:291)
	at Test.main(Test.java:22)
{noformat}

> CLONE - "deflate" encoding issue : java.util.zip.ZipException: invalid block type
> ---------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1738
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1738
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>         Environment: Windows
>            Reporter: Archie Cobbs
>            Priority: Minor
>
> 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.3.4#6332)

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