Skip to content

RestTemplate cannot handle GZIP response since 4.1.3 [SPR-12712] #17309

Closed
@spring-projects-issues

Description

@spring-projects-issues

Moosh Ben opened SPR-12712 and commented

We are using RestTemplate in our project with HttpClient.
Calling an API that returns a Gzipped response stopped working after upgrading to 4.1.3 (also not working in 4.1.4) .

RestTemplate creation:

RestTemplate rt = new RestTemplate();
		
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();

Jaxb2RootElementHttpMessageConverter xmlConverter = new Jaxb2RootElementHttpMessageConverter();
List<MediaType> mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(MediaType.APPLICATION_XML);
mediaTypes.add(MediaType.TEXT_XML);
xmlConverter.setSupportedMediaTypes(mediaTypes);
messageConverters.add(xmlConverter);

MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(MediaType.APPLICATION_JSON);

// Only valid for qualys
mediaTypes.add(MediaType.TEXT_HTML);
jsonConverter.setSupportedMediaTypes(mediaTypes);
messageConverters.add(jsonConverter);

messageConverters.add(new StringHttpMessageConverter(Charset.forName( "UTF-8")));
messageConverters.add(new FormHttpMessageConverter());

MultiPartMessageConverter multipartConverter = new MultiPartMessageConverter();
mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(new MediaType("multipart", "mixed"));

multipartConverter.setSupportedMediaTypes(mediaTypes);
messageConverters.add(multipartConverter);

rt.setMessageConverters(messageConverters);
rt.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClientFactory.getHttpClient()));

return rt;

Trace log of request and response (check the last line that prints the response of the exchange call):

2015-02-12 12:47:39,500 DEBUG RestTemplate             :78   - Created POST request for "https://1.1.1.1/test"
2015-02-12 12:47:39,500 DEBUG RestTemplate             :696  - Setting request Accept header to [application/json, text/html, text/plain, */*]
2015-02-12 12:47:39,547 DEBUG RestTemplate             :769  - Writing [{name=[value]}] as "application/x-www-form-urlencoded" using [org.springframework.http.converter.FormHttpMessageConverter@4f836d9]
2015-02-12 12:47:39,579 DEBUG RequestAddCookies        :122  - CookieSpec selected: default
2015-02-12 12:47:39,579 DEBUG RequestAddCookies        :151  - Unsupported cookie policy: default
2015-02-12 12:47:39,579 DEBUG RequestAuthCache         :76   - Auth cache not set in the context
2015-02-12 12:47:39,579 DEBUG tpClientConnectionManager:249  - Connection request: [route: {s}->https://1.1.1.1][total kept alive: 0; route allocated: 0 of 20; total allocated: 0 of 200]
2015-02-12 12:47:39,625 DEBUG tpClientConnectionManager:282  - Connection leased: [id: 0][route: {s}->https://1.1.1.1][total kept alive: 0; route allocated: 1 of 20; total allocated: 1 of 200]
2015-02-12 12:47:39,625 DEBUG MainClientExec           :234  - Opening connection {s}->https://1.1.1.1
2015-02-12 12:47:39,641 DEBUG pClientConnectionOperator:131  - Connecting to /1.1.1.1
2015-02-12 12:47:39,641 DEBUG SLConnectionSocketFactory:336  - Connecting socket to /1.1.1.1 with timeout 0
2015-02-12 12:47:40,109 DEBUG SLConnectionSocketFactory:389  - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
2015-02-12 12:47:40,109 DEBUG SLConnectionSocketFactory:390  - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, 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_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, 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, 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, SSL_RSA_WITH_RC4_128_MD5, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
2015-02-12 12:47:40,109 DEBUG SLConnectionSocketFactory:394  - Starting handshake
2015-02-12 12:47:40,312 DEBUG SLConnectionSocketFactory:424  - Secure session established
2015-02-12 12:47:40,312 DEBUG SLConnectionSocketFactory:425  -  negotiated protocol: TLSv1
2015-02-12 12:47:40,312 DEBUG SLConnectionSocketFactory:426  -  negotiated cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA
2015-02-12 12:47:40,312 DEBUG SLConnectionSocketFactory:434  -  peer principal: CN=Test, ST=NY, C=US, L=New York, OU=My Server, O=My Users United
2015-02-12 12:47:40,312 DEBUG SLConnectionSocketFactory:447  -  issuer principal: CN=My Certification Authority (5c858e74), ST=NY, C=US, L=New York, OU=My Certification Authority (5c858e74), O=My Users United
2015-02-12 12:47:40,312 DEBUG pClientConnectionOperator:138  - Connection established 192.168.3.182:51715<->1.1.1.1
2015-02-12 12:47:40,312 DEBUG MainClientExec           :255  - Executing request POST /test HTTP/1.1
2015-02-12 12:47:40,312 DEBUG MainClientExec           :260  - Target auth state: UNCHALLENGED
2015-02-12 12:47:40,312 DEBUG MainClientExec           :266  - Proxy auth state: UNCHALLENGED
2015-02-12 12:47:40,327 DEBUG headers                  :124  - http-outgoing-0 >> POST /test HTTP/1.1
2015-02-12 12:47:40,327 DEBUG headers                  :127  - http-outgoing-0 >> Accept: application/json, text/html, text/plain, */*
2015-02-12 12:47:40,327 DEBUG headers                  :127  - http-outgoing-0 >> Content-Type: application/x-www-form-urlencoded
2015-02-12 12:47:40,327 DEBUG headers                  :127  - http-outgoing-0 >> Cookie: token=00e645824aa40ffb1c0819017d0a3dffdc64c3d5ae86d0f5
2015-02-12 12:47:40,327 DEBUG headers                  :127  - http-outgoing-0 >> Content-Length: 88
2015-02-12 12:47:40,327 DEBUG headers                  :127  - http-outgoing-0 >> Host: 1.1.1.1
2015-02-12 12:47:40,327 DEBUG headers                  :127  - http-outgoing-0 >> Connection: Keep-Alive
2015-02-12 12:47:40,327 DEBUG headers                  :127  - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.4 (Java 1.5 minimum; Java/1.8.0_31)
2015-02-12 12:47:40,327 DEBUG headers                  :127  - http-outgoing-0 >> Accept-Encoding: gzip,deflate
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "POST /test HTTP/1.1[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "Accept: application/json, text/html, text/plain, */*[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "Content-Type: application/x-www-form-urlencoded[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "Cookie: token=00e645824aa40ffb1c0819017d0a3dffdc64c3d5ae86d0f5[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "Content-Length: 88[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "Host: 1.1.1.1[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.4 (Java 1.5 minimum; Java/1.8.0_31)[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 >> "[\r][\n]"
2015-02-12 12:47:40,327 DEBUG wire                     :86   - http-outgoing-0 >> "name=value"
2015-02-12 12:47:40,327 DEBUG wire                     :72   - http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Date: Thu, 12 Feb 2015 10:47:40 GMT[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Server: MyWWW[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Connection: close[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Expires: Thu, 12 Feb 2015 10:47:40 GMT[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Content-Length: 122[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Content-Type: text/xml[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Content-Encoding: gzip[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "X-Frame-Options: DENY[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Cache-Control: [\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Expires: 0[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "Pragma: [\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "[\r][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x3][0xb3][0xb1][0xaf][0xc8][0xcd]Q(K-*[0xce][0xcc][0xcf][0xb3]U2[0xd4]3PRH[0xcd]K[0xce]O[0xc9][0xcc]K[0xb7]U[\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :72   - http-outgoing-0 << "[\r]q[0xd3][0xb5]P[0xb2][0xb7][0xe3][0xb2])J-[0xc8][0xa9][0x4][0xd2][0xc5][0xa9][0x85]v6[0xfa] [0x12][0xc8].I,)-[0xb6][0xf3][0xf7][0x6][\n]"
2015-02-12 12:47:40,343 DEBUG wire                     :86   - http-outgoing-0 << "@[0x98]\6[0xc9][0xf9]y%[0xa9]y%[0xc5]v6[0x5]9[0xa5][0xe9][0x99]y>[0x99][0xc5]%@[\r]H[0x1c].[0x1b]}[0xb8]" [0x1b]b0[0x0][0x9e]'[0xc0][0xa8][0x87][0x0][0x0][0x0]"
2015-02-12 12:47:40,343 DEBUG headers                  :113  - http-outgoing-0 << HTTP/1.1 200 OK
2015-02-12 12:47:40,343 DEBUG headers                  :116  - http-outgoing-0 << Date: Thu, 12 Feb 2015 10:47:40 GMT
2015-02-12 12:47:40,343 DEBUG headers                  :116  - http-outgoing-0 << Server: MyWWW
2015-02-12 12:47:40,343 DEBUG headers                  :116  - http-outgoing-0 << Connection: close
2015-02-12 12:47:40,343 DEBUG headers                  :116  - http-outgoing-0 << Expires: Thu, 12 Feb 2015 10:47:40 GMT
2015-02-12 12:47:40,343 DEBUG headers                  :116  - http-outgoing-0 << Content-Length: 122
2015-02-12 12:47:40,343 DEBUG headers                  :116  - http-outgoing-0 << Content-Type: text/xml
2015-02-12 12:47:40,343 DEBUG headers                  :116  - http-outgoing-0 << Content-Encoding: gzip
2015-02-12 12:47:40,343 DEBUG headers                  :116  - http-outgoing-0 << X-Frame-Options: DENY
2015-02-12 12:47:40,359 DEBUG headers                  :116  - http-outgoing-0 << Cache-Control: 
2015-02-12 12:47:40,359 DEBUG headers                  :116  - http-outgoing-0 << Expires: 0
2015-02-12 12:47:40,359 DEBUG headers                  :116  - http-outgoing-0 << Pragma: 
2015-02-12 12:47:40,359 DEBUG ResponseProcessCookies   :76   - Cookie spec not specified in HTTP context
2015-02-12 12:47:40,374 DEBUG RestTemplate             :596  - POST request for "https://1.1.1.1/test" resulted in 200 (OK)
2015-02-12 12:47:40,390 DEBUG nagedHttpClientConnection:87   - http-outgoing-0: Shutdown connection
2015-02-12 12:47:40,390 DEBUG MainClientExec           :128  - Connection discarded
2015-02-12 12:47:40,390 DEBUG nagedHttpClientConnection:79   - http-outgoing-0: Close connection
2015-02-12 12:47:40,390 DEBUG tpClientConnectionManager:320  - Connection released: [id: 0][route: {s}->https://1.1.1.1][total kept alive: 0; route allocated: 0 of 20; total allocated: 0 of 200]
2015-02-12 12:48:12,022 INFO  TestTask                 :67   - Response: null

Affects: 4.1.3, 4.1.4

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions