Disclaimer: I know that this question has duplicates (one, two, three), BUT:
I tried all the answers and it doesn't solve the problem (I searched not only in SO)
I provide the full internal log of http client, so experienced users can
analize and comment it.
Those questions are old (more than a year), many things has been changed.
I'm trying to get content from this URL:
https://api.vk.com/method/database.getCountries
Mac OS Chrome browser gets the content in around 70-100 ms (I look at dev-tools Network tab), but my code with apache http client 4.5.2 gets it in 180-200 ms.
Also I have a code with (kevinsawicki-http-request) library, witch gets this page in 70-100 ms (like in browser).
This difference is critical for me, and (I think) for many other devs, who asked similar questions.
My code:
RequestConfig requestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
.setSocketTimeout(60000)
.setConnectTimeout(5000)
.setConnectionRequestTimeout(5000)
.build();
SocketConfig socketConfig = SocketConfig.custom()
.setSoKeepAlive(false) //true - no differences in request time
.setTcpNoDelay(true)
.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
connManager.setMaxTotal(50);
connManager.setDefaultMaxPerRoute(2);
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultSocketConfig(socketConfig)
.setConnectionManager(connManager)
.setDefaultRequestConfig(requestConfig)
.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36")
.build();
//1
long t11 = System.currentTimeMillis();
try(CloseableHttpResponse response1 = httpClient.execute(new HttpGet("https://api.vk.com/method/database.getCountries"))) {
code1 = response1.getStatusLine().getStatusCode();
}
long t12 = System.currentTimeMillis();
long reqTime1 = t12 - t11;
//2
long t21 = System.currentTimeMillis();
try(CloseableHttpResponse response2 = httpClient.execute(new HttpGet("https://api.vk.com/method/database.getCountries"))) {
code2 = response2.getStatusLine().getStatusCode();
}
long t22 = System.currentTimeMillis();
long reqTime2 = t22 - t21;
//3
long t31 = System.currentTimeMillis();
try(CloseableHttpResponse response3 = httpClient.execute(new HttpGet("https://api.vk.com/method/database.getCountries"))) {
code3 = response3.getStatusLine().getStatusCode();
}
long t32 = System.currentTimeMillis();
long reqTime3 = t32 - t31;
log.trace("reqTime1: {}", reqTime1);
log.trace("reqTime2: {}", reqTime2);
log.trace("reqTime3: {}", reqTime3);
This prints:
reqTime1: 198
reqTime2: 168
reqTime3: 160
(all 3 requests return 200 http code)
I have JVM options:
-Djavax.net.ssl.keyStore=/path/to/my/keyStore.jks
-Djavax.net.ssl.keyStorePassword=my_password
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Dorg.apache.commons.logging.simplelog.showdatetime=true
-Dorg.apache.commons.logging.simplelog.log.org.apache.http=DEBUG
-Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=ERROR
(vk.com certificate is added in my keyStore.jks)
Here is the internal log of http-client
[err] 2016/11/11 14:54:35:411 MSK [DEBUG] RequestAddCookies - CookieSpec selected: ignoreCookies
[err] 2016/11/11 14:54:35:412 MSK [DEBUG] RequestAuthCache - Auth cache not set in the context
[err] 2016/11/11 14:54:35:413 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:413 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 6][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 50]
[err] 2016/11/11 14:54:35:413 MSK [DEBUG] MainClientExec - Opening connection {s}->https://api.vk.com:443
[err] 2016/11/11 14:54:35:414 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connecting to api.vk.com/87.240.165.75:443
[err] 2016/11/11 14:54:35:414 MSK [DEBUG] SSLConnectionSocketFactory - Connecting socket to api.vk.com/87.240.165.75:443 with timeout 5000
[err] 2016/11/11 14:54:35:494 MSK [DEBUG] SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
[err] 2016/11/11 14:54:35:495 MSK [DEBUG] SSLConnectionSocketFactory - 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_EMPTY_RENEGOTIATION_INFO_SCSV]
[err] 2016/11/11 14:54:35:495 MSK [DEBUG] SSLConnectionSocketFactory - Starting handshake
[err] 2016/11/11 14:54:35:641 MSK [DEBUG] SSLConnectionSocketFactory - Secure session established
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory - negotiated protocol: TLSv1.2
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory - negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory - peer principal: CN=*.vk.com, OU=Domain Control Validated
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory - peer alternative names: [*.vk.com, vk.com]
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory - issuer principal: CN=Go Daddy Secure Certificate Authority - G2, OU=http://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US
[err] 2016/11/11 14:54:35:643 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connection established 172.20.10.2:55317<->87.240.165.75:443
[err] 2016/11/11 14:54:35:643 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-6: set socket timeout to 60000
[err] 2016/11/11 14:54:35:643 MSK [DEBUG] MainClientExec - Executing request GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:35:643 MSK [DEBUG] MainClientExec - Target auth state: UNCHALLENGED
[err] 2016/11/11 14:54:35:644 MSK [DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
[err] 2016/11/11 14:54:35:644 MSK [DEBUG] headers - http-outgoing-6 >> GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:35:644 MSK [DEBUG] headers - http-outgoing-6 >> Host: api.vk.com
[err] 2016/11/11 14:54:35:644 MSK [DEBUG] headers - http-outgoing-6 >> Connection: Keep-Alive
[err] 2016/11/11 14:54:35:645 MSK [DEBUG] headers - http-outgoing-6 >> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
[err] 2016/11/11 14:54:35:645 MSK [DEBUG] headers - http-outgoing-6 >> Accept-Encoding: gzip,deflate
[err] 2016/11/11 14:54:35:725 MSK [DEBUG] headers - http-outgoing-6 << HTTP/1.1 200 OK
[err] 2016/11/11 14:54:35:725 MSK [DEBUG] headers - http-outgoing-6 << Server: Apache
[err] 2016/11/11 14:54:35:726 MSK [DEBUG] headers - http-outgoing-6 << Date: Fri, 11 Nov 2016 11:54:35 GMT
[err] 2016/11/11 14:54:35:726 MSK [DEBUG] headers - http-outgoing-6 << Content-Type: application/json; charset=utf-8
[err] 2016/11/11 14:54:35:726 MSK [DEBUG] headers - http-outgoing-6 << Content-Length: 286
[err] 2016/11/11 14:54:35:727 MSK [DEBUG] headers - http-outgoing-6 << Connection: keep-alive
[err] 2016/11/11 14:54:35:727 MSK [DEBUG] headers - http-outgoing-6 << X-Powered-By: PHP/3.7212
[err] 2016/11/11 14:54:35:727 MSK [DEBUG] headers - http-outgoing-6 << Set-Cookie: remixlang=0; expires=Sun, 05 Nov 2017 18:31:29 GMT; path=/; domain=.vk.com
[err] 2016/11/11 14:54:35:727 MSK [DEBUG] headers - http-outgoing-6 << Pragma: no-cache
[err] 2016/11/11 14:54:35:728 MSK [DEBUG] headers - http-outgoing-6 << Cache-control: no-store
[err] 2016/11/11 14:54:35:728 MSK [DEBUG] headers - http-outgoing-6 << Content-Encoding: gzip
[err] 2016/11/11 14:54:35:728 MSK [DEBUG] MainClientExec - Connection can be kept alive indefinitely
[err] 2016/11/11 14:54:35:729 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-6: Close connection
[err] 2016/11/11 14:54:35:730 MSK [DEBUG] MainClientExec - Connection discarded
[err] 2016/11/11 14:54:35:730 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 6][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:730 MSK [DEBUG] RequestAddCookies - CookieSpec selected: ignoreCookies
[err] 2016/11/11 14:54:35:731 MSK [DEBUG] RequestAuthCache - Auth cache not set in the context
[err] 2016/11/11 14:54:35:731 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:731 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 7][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 50]
[err] 2016/11/11 14:54:35:731 MSK [DEBUG] MainClientExec - Opening connection {s}->https://api.vk.com:443
[err] 2016/11/11 14:54:35:732 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connecting to api.vk.com/87.240.165.75:443
[err] 2016/11/11 14:54:35:732 MSK [DEBUG] SSLConnectionSocketFactory - Connecting socket to api.vk.com/87.240.165.75:443 with timeout 5000
[err] 2016/11/11 14:54:35:786 MSK [DEBUG] SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
[err] 2016/11/11 14:54:35:787 MSK [DEBUG] SSLConnectionSocketFactory - 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_EMPTY_RENEGOTIATION_INFO_SCSV]
[err] 2016/11/11 14:54:35:787 MSK [DEBUG] SSLConnectionSocketFactory - Starting handshake
[err] 2016/11/11 14:54:35:909 MSK [DEBUG] SSLConnectionSocketFactory - Secure session established
[err] 2016/11/11 14:54:35:910 MSK [DEBUG] SSLConnectionSocketFactory - negotiated protocol: TLSv1.2
[err] 2016/11/11 14:54:35:910 MSK [DEBUG] SSLConnectionSocketFactory - negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
[err] 2016/11/11 14:54:35:910 MSK [DEBUG] SSLConnectionSocketFactory - peer principal: CN=*.vk.com, OU=Domain Control Validated
[err] 2016/11/11 14:54:35:911 MSK [DEBUG] SSLConnectionSocketFactory - peer alternative names: [*.vk.com, vk.com]
[err] 2016/11/11 14:54:35:911 MSK [DEBUG] SSLConnectionSocketFactory - issuer principal: CN=Go Daddy Secure Certificate Authority - G2, OU=http://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US
[err] 2016/11/11 14:54:35:911 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connection established 172.20.10.2:55318<->87.240.165.75:443
[err] 2016/11/11 14:54:35:912 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-7: set socket timeout to 60000
[err] 2016/11/11 14:54:35:912 MSK [DEBUG] MainClientExec - Executing request GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:35:912 MSK [DEBUG] MainClientExec - Target auth state: UNCHALLENGED
[err] 2016/11/11 14:54:35:913 MSK [DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
[err] 2016/11/11 14:54:35:913 MSK [DEBUG] headers - http-outgoing-7 >> GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:35:913 MSK [DEBUG] headers - http-outgoing-7 >> Host: api.vk.com
[err] 2016/11/11 14:54:35:913 MSK [DEBUG] headers - http-outgoing-7 >> Connection: Keep-Alive
[err] 2016/11/11 14:54:35:914 MSK [DEBUG] headers - http-outgoing-7 >> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
[err] 2016/11/11 14:54:35:914 MSK [DEBUG] headers - http-outgoing-7 >> Accept-Encoding: gzip,deflate
[err] 2016/11/11 14:54:35:989 MSK [DEBUG] headers - http-outgoing-7 << HTTP/1.1 200 OK
[err] 2016/11/11 14:54:35:989 MSK [DEBUG] headers - http-outgoing-7 << Server: Apache
[err] 2016/11/11 14:54:35:990 MSK [DEBUG] headers - http-outgoing-7 << Date: Fri, 11 Nov 2016 11:54:35 GMT
[err] 2016/11/11 14:54:35:990 MSK [DEBUG] headers - http-outgoing-7 << Content-Type: application/json; charset=utf-8
[err] 2016/11/11 14:54:35:990 MSK [DEBUG] headers - http-outgoing-7 << Content-Length: 286
[err] 2016/11/11 14:54:35:990 MSK [DEBUG] headers - http-outgoing-7 << Connection: keep-alive
[err] 2016/11/11 14:54:35:991 MSK [DEBUG] headers - http-outgoing-7 << X-Powered-By: PHP/3.7212
[err] 2016/11/11 14:54:35:991 MSK [DEBUG] headers - http-outgoing-7 << Set-Cookie: remixlang=0; expires=Wed, 08 Nov 2017 21:16:16 GMT; path=/; domain=.vk.com
[err] 2016/11/11 14:54:35:991 MSK [DEBUG] headers - http-outgoing-7 << Pragma: no-cache
[err] 2016/11/11 14:54:35:991 MSK [DEBUG] headers - http-outgoing-7 << Cache-control: no-store
[err] 2016/11/11 14:54:35:992 MSK [DEBUG] headers - http-outgoing-7 << Content-Encoding: gzip
[err] 2016/11/11 14:54:35:992 MSK [DEBUG] MainClientExec - Connection can be kept alive indefinitely
[err] 2016/11/11 14:54:35:992 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-7: Close connection
[err] 2016/11/11 14:54:35:993 MSK [DEBUG] MainClientExec - Connection discarded
[err] 2016/11/11 14:54:35:993 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 7][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:994 MSK [DEBUG] RequestAddCookies - CookieSpec selected: ignoreCookies
[err] 2016/11/11 14:54:35:994 MSK [DEBUG] RequestAuthCache - Auth cache not set in the context
[err] 2016/11/11 14:54:35:994 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:995 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 8][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 50]
[err] 2016/11/11 14:54:35:995 MSK [DEBUG] MainClientExec - Opening connection {s}->https://api.vk.com:443
[err] 2016/11/11 14:54:35:996 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connecting to api.vk.com/87.240.165.75:443
[err] 2016/11/11 14:54:35:996 MSK [DEBUG] SSLConnectionSocketFactory - Connecting socket to api.vk.com/87.240.165.75:443 with timeout 5000
[err] 2016/11/11 14:54:36:050 MSK [DEBUG] SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
[err] 2016/11/11 14:54:36:050 MSK [DEBUG] SSLConnectionSocketFactory - 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_EMPTY_RENEGOTIATION_INFO_SCSV]
[err] 2016/11/11 14:54:36:050 MSK [DEBUG] SSLConnectionSocketFactory - Starting handshake
[err] 2016/11/11 14:54:36:117 MSK [DEBUG] SSLConnectionSocketFactory - Secure session established
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory - negotiated protocol: TLSv1.2
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory - negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory - peer principal: CN=*.vk.com, OU=Domain Control Validated
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory - peer alternative names: [*.vk.com, vk.com]
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory - issuer principal: CN=Go Daddy Secure Certificate Authority - G2, OU=http://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connection established 172.20.10.2:55331<->87.240.165.75:443
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-8: set socket timeout to 60000
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] MainClientExec - Executing request GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] MainClientExec - Target auth state: UNCHALLENGED
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> Host: api.vk.com
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> Connection: Keep-Alive
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> Accept-Encoding: gzip,deflate
[err] 2016/11/11 14:54:36:188 MSK [DEBUG] headers - http-outgoing-8 << HTTP/1.1 200 OK
[err] 2016/11/11 14:54:36:189 MSK [DEBUG] headers - http-outgoing-8 << Server: Apache
[err] 2016/11/11 14:54:36:189 MSK [DEBUG] headers - http-outgoing-8 << Date: Fri, 11 Nov 2016 11:54:36 GMT
[err] 2016/11/11 14:54:36:189 MSK [DEBUG] headers - http-outgoing-8 << Content-Type: application/json; charset=utf-8
[err] 2016/11/11 14:54:36:189 MSK [DEBUG] headers - http-outgoing-8 << Content-Length: 286
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Connection: keep-alive
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << X-Powered-By: PHP/3.7212
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Set-Cookie: remixlang=0; expires=Thu, 16 Nov 2017 00:20:15 GMT; path=/; domain=.vk.com
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Pragma: no-cache
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Cache-control: no-store
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Content-Encoding: gzip
[err] 2016/11/11 14:54:36:191 MSK [DEBUG] MainClientExec - Connection can be kept alive indefinitely
[err] 2016/11/11 14:54:36:191 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-8: Close connection
[err] 2016/11/11 14:54:36:192 MSK [DEBUG] MainClientExec - Connection discarded
[err] 2016/11/11 14:54:36:192 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 8][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[14:54:36.193] TRACE [proliker.utils.TestService.hc(TestService.java:300)]: reqTime1: 319
[14:54:36.193] TRACE [proliker.utils.TestService.hc(TestService.java:301)]: reqTime2: 264
[14:54:36.194] TRACE [proliker.utils.TestService.hc(TestService.java:302)]: reqTime3: 198
Of course, the above tests were performed with internal logging turned OFF because it adds additional ~50 ms to each request.
I have read ALL apache http-client site docs thrice, I have no idea where to look and where I have mistake. I hope so much, that some geek can help me increase request speed.
[err] 2016/11/11 14:54:36:191 MSK [DEBUG] MainClientExec - Connection can be kept alive indefinitely
[err] 2016/11/11 14:54:36:191 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-8: Close connection
[err] 2016/11/11 14:54:36:192 MSK [DEBUG] MainClientExec - Connection discarded
If this is not intentional then the simplest way to make HttpClient faster is by re-using connections (especially when using SSL/TLS transport security).
Always make sure that response content has been fully consumed (by reading from the content stream until end of the stream or by closing the stream).
try(CloseableHttpResponse response1 = httpClient.execute(new HttpGet("https://api.vk.com/method/database.getCountries"))) {
int code1 = response1.getStatusLine().getStatusCode();
EntityUtils.consume(response1.getEntity());
}
Related
I have a strange issue and I can't find the solution.
I have the following code for building my ClosableHttpClient :
private void createClient() {
int timeout = 5;
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout * 1000)
.setConnectionRequestTimeout(timeout * 1000)
.setSocketTimeout(timeout * 1000).build();
final SSLSocketFactory socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
final HostnameVerifier defaultHostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier();
final SSLConnectionSocketFactory systemSocketFactory = new SSLConnectionSocketFactory(socketFactory, defaultHostnameVerifier);
httpclient = HttpClients.custom()
.setSSLSocketFactory(systemSocketFactory)
.setDefaultRequestConfig(config)
.build();
}
and than I'm trying this:
private JSONObject sendPostRequest(String url, StringEntity postData) throws HttpException, IOException {
HttpPost request = new HttpPost(url);
for (String key : headers.keySet()) {
request.addHeader(key, headers.get(key));
}
request.setEntity(postData);
HttpResponse response = httpclient.execute(request);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
String content = EntityUtils.toString(response.getEntity());
return new JSONObject(content);
} else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
throw new HttpException("Autorisierung nicht möglich");
}
throw new HttpException(String.valueOf(statusCode));
}
the code stops at httpclient.execute(). And I mean it stops. There is nothing after, no log no stacktrace nothing. When I try my code on localhost ther is the following debug-log
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.client.protocol.RequestAddCookies:123 - CookieSpec selected: default
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.client.protocol.RequestAuthCache:77 - Auth cache not set in the context
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.PoolingHttpClientConnectionManager:267 - Connection request: [route: {s}->https://doesnt.matter:8443][total available: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.PoolingHttpClientConnectionManager:312 - Connection leased: [id: 0][route: {s}->https://doesnt.matter:8443][total available: 0; route allocated: 1 of 2; total allocated: 1 of 20]
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.impl.execchain.MainClientExec:234 - Opening connection {s}->https://doesnt.matter:8443
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.DefaultHttpClientConnectionOperator:139 - Connecting to doesnt.matter/1.2.1.8:8443
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:366 - Connecting socket to doesnt.matter/1.2.1.8:8443 with timeout 5000
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:430 - Enabled protocols: [TLSv1.2]
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:431 - Enabled cipher suites:[SSL_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, SSL_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, SSL_ECDHE_RSA_WITH_AES_256_GCM_SHA384, SSL_RSA_WITH_AES_256_GCM_SHA384, SSL_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, SSL_ECDH_RSA_WITH_AES_256_GCM_SHA384, SSL_DHE_RSA_WITH_AES_256_GCM_SHA384, SSL_DHE_DSS_WITH_AES_256_GCM_SHA384, SSL_ECDHE_RSA_WITH_AES_128_GCM_SHA256, SSL_RSA_WITH_AES_128_GCM_SHA256, SSL_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, SSL_ECDH_RSA_WITH_AES_128_GCM_SHA256, SSL_DHE_RSA_WITH_AES_128_GCM_SHA256, SSL_DHE_DSS_WITH_AES_128_GCM_SHA256, SSL_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, SSL_ECDHE_RSA_WITH_AES_256_CBC_SHA384, SSL_RSA_WITH_AES_256_CBC_SHA256, SSL_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, SSL_ECDH_RSA_WITH_AES_256_CBC_SHA384, SSL_DHE_RSA_WITH_AES_256_CBC_SHA256, SSL_DHE_DSS_WITH_AES_256_CBC_SHA256, SSL_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, SSL_ECDHE_RSA_WITH_AES_256_CBC_SHA, SSL_RSA_WITH_AES_256_CBC_SHA, SSL_ECDH_ECDSA_WITH_AES_256_CBC_SHA, SSL_ECDH_RSA_WITH_AES_256_CBC_SHA, SSL_DHE_RSA_WITH_AES_256_CBC_SHA, SSL_DHE_DSS_WITH_AES_256_CBC_SHA, SSL_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, SSL_ECDHE_RSA_WITH_AES_128_CBC_SHA256, SSL_RSA_WITH_AES_128_CBC_SHA256, SSL_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, SSL_ECDH_RSA_WITH_AES_128_CBC_SHA256, SSL_DHE_RSA_WITH_AES_128_CBC_SHA256, SSL_DHE_DSS_WITH_AES_128_CBC_SHA256, SSL_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, SSL_ECDHE_RSA_WITH_AES_128_CBC_SHA, SSL_RSA_WITH_AES_128_CBC_SHA, SSL_ECDH_ECDSA_WITH_AES_128_CBC_SHA, SSL_ECDH_RSA_WITH_AES_128_CBC_SHA, SSL_DHE_RSA_WITH_AES_128_CBC_SHA, SSL_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:435 - Starting handshake
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:465 - Secure session established
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:466 - negotiated protocol: TLSv1.2
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:467 - negotiated cipher suite: SSL_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:475 - peer principal: CN=doesnt.matter, OU=D100, OU=SSL Server, OU=SSL, O=Finanz Informatik, C=DE
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:484 - peer alternative names: [doesnt.matter]
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:488 - issuer principal: CN=Finanz Informatik Issuing CA 01, OU=PKI, O=Finanz Informatik, C=DE
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.DefaultHttpClientConnectionOperator:146 - Connection established 16.160.132.187:58678<->17.239.174.83:8443
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.DefaultManagedHttpClientConnection:88 - http-outgoing-0: set socket timeout to 5000
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.execchain.MainClientExec:255 - Executing request POST /rest-api/authenticate HTTP/1.1
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.execchain.MainClientExec:260 - Target auth state: UNCHALLENGED
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.execchain.MainClientExec:266 - Proxy auth state: UNCHALLENGED
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:133 - http-outgoing-0 >> POST /rest-api/authenticate HTTP/1.1
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:136 - http-outgoing-0 >> Content-Length: 88
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:136 - http-outgoing-0 >> Content-Type: application/json; charset=UTF-8
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:136 - http-outgoing-0 >> Host: doesnt.matter:8443
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:136 - http-outgoing-0 >> Connection: Keep-Alive
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:136 - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_291)
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:136 - http-outgoing-0 >> Accept-Encoding: gzip,deflate
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 >> "POST /rest-api/authenticate HTTP/1.1[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 >> "Content-Length: 88[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 >> "Content-Type: application/json; charset=UTF-8[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 >> "Host: doesnt.matter:8443[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_291)[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 >> "[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:87 - http-outgoing-0 >> "{"clientContext":1,"password":"*********","repository":"UCMDB","username":"******"}"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Date: Fri, 11 Feb 2022 08:29:10 GMT[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "X-FRAME-OPTIONS: [\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Content-Security-Policy: frame-ancestors 'self'[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "X-Xss-Protection: 1; mode=block[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Strict-Transport-Security: max-age=31536000;includeSubDomains[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Cache-Control: no-store[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "IE-Language: en[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Access-Control-Allow-Origin: *[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Access-Control-Allow-Credentials: true[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Access-Control-Allow-Methods: POST, PUT, GET, HEAD, OPTIONS, PATCH, DELETE[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers , Authorization, Cache-Control, Pragma, Expires[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Access-Control-Max-Age: 17200[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Set-Cookie: JSESSIONID=node01dumaqs3jy4ycc2vtykxc0btx188; HttpOnly; secure; path=/rest-api[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Expires: Thu, 01 Jan 1970 00:00:00 GMT[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Content-Type: application/json[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "Content-Length: 243[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << "{[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:73 - http-outgoing-0 << " "token" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmlxdWVfc2FsdCI6IlY5OTBTVFdNVlFPUkEwMSIsImV4cCI6MTY0NDU3MTc1MCwicmVwb3NpdG9yeSI6IlVDTURCIiwiY3VzdG9tZXIiOjEsInVzZXJuYW1lIjoic3lzYWRtaW4ifQ.-BzMAsqUT0FdEpMsf0M__FodAP3yv7JOelXMvzwQBK4"[\r][\n]"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.wire:87 - http-outgoing-0 << "}"
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:122 - http-outgoing-0 << HTTP/1.1 200 OK
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Date: Fri, 11 Feb 2022 08:29:10 GMT
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << X-FRAME-OPTIONS:
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Content-Security-Policy: frame-ancestors 'self'
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << X-Content-Type-Options: nosniff
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << X-Xss-Protection: 1; mode=block
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Strict-Transport-Security: max-age=31536000;includeSubDomains
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Cache-Control: no-store
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << IE-Language: en
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Access-Control-Allow-Origin: *
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Access-Control-Allow-Credentials: true
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Access-Control-Allow-Methods: POST, PUT, GET, HEAD, OPTIONS, PATCH, DELETE
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers , Authorization, Cache-Control, Pragma, Expires
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Access-Control-Max-Age: 17200
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Set-Cookie: JSESSIONID=node01dumaqs3jy4ycc2vtykxc0btx188; HttpOnly; secure; path=/rest-api
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Expires: Thu, 01 Jan 1970 00:00:00 GMT
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Content-Type: application/json
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] org.apache.http.headers:125 - http-outgoing-0 << Content-Length: 243
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.execchain.MainClientExec:285 - Connection can be kept alive indefinitely
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.client.protocol.ResponseProcessCookies:119 - Cookie accepted [JSESSIONID="node01dumaqs3jy4ycc2vtykxc0btx188", version:0, domain:doesnt.matter, path:/rest-api, expiry:null]
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.PoolingHttpClientConnectionManager:344 - Connection [id: 0][route: {s}->https://doesnt.matter:8443] can be kept alive indefinitely
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.DefaultManagedHttpClientConnection:88 - http-outgoing-0: set socket timeout to 0
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.PoolingHttpClientConnectionManager:351 - Connection released: [id: 0][route: {s}->https://doesnt.matter:8443][total available: 1; route allocated: 1 of 2; total allocated: 1 of 20]
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.PoolingHttpClientConnectionManager:411 - Connection manager is shutting down
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.DefaultManagedHttpClientConnection:79 - http-outgoing-0: Close connection
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.impl.conn.PoolingHttpClientConnectionManager:434 - Connection manager shut down
When I deploy it to the WLP Server I only get the following output
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.client.protocol.RequestAddCookies:123 - CookieSpec selected: default
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.client.protocol.RequestAuthCache:77 - Auth cache not set in the context
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.impl.conn.PoolingHttpClientConnectionManager:267 - Connection request: [route: {s}->https://doesnt.matter:8443][total available: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.impl.conn.PoolingHttpClientConnectionManager:312 - Connection leased: [id: 120][route: {s}->https://doesnt.matter:8443][total available: 0; route allocated: 1 of 2; total allocated: 1 of 20]
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.impl.execchain.MainClientExec:234 - Opening connection {s}->https://doesnt.matter:8443
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.impl.conn.DefaultHttpClientConnectionOperator:139 - Connecting to doesnt.matter/1.2.1.8:8443
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.conn.ssl.SSLConnectionSocketFactory:366 - Connecting socket to doesnt.matter/1.2.1.8:8443 with timeout 5000
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.conn.ssl.SSLConnectionSocketFactory:430 - Enabled protocols: [TLSv1.2]
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.conn.ssl.SSLConnectionSocketFactory:431 - Enabled cipher suites:[SSL_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, SSL_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, SSL_ECDHE_RSA_WITH_AES_256_GCM_SHA384, SSL_DHE_RSA_WITH_AES_256_GCM_SHA384, SSL_DHE_DSS_WITH_AES_256_GCM_SHA384, SSL_ECDHE_RSA_WITH_AES_128_GCM_SHA256, SSL_DHE_RSA_WITH_AES_128_GCM_SHA256, SSL_DHE_DSS_WITH_AES_128_GCM_SHA256]
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.conn.ssl.SSLConnectionSocketFactory:435 - Starting handshake
[2022-02-11T09:25:50] [DEBUG] [Finalizer thread] apache.http.impl.conn.PoolingHttpClientConnectionManager:411 - Connection manager is shutting down
[2022-02-11T09:25:50] [DEBUG] [Finalizer thread] apache.http.impl.conn.PoolingHttpClientConnectionManager:434 - Connection manager shut down
[2022-02-11T09:26:23] [DEBUG] [Default Executor-thread-576] apache.http.impl.conn.PoolingHttpClientConnectionManager:411 - Connection manager is shutting down
[2022-02-11T09:26:23] [DEBUG] [Default Executor-thread-576] apache.http.impl.conn.DefaultManagedHttpClientConnection:96 - http-outgoing-120: Shutdown connection
[2022-02-11T09:26:23] [DEBUG] [Default Executor-thread-576] apache.http.impl.conn.PoolingHttpClientConnectionManager:434 - Connection manager shut down
And as I said than there is nothing. My code stops proceeding. This test is made every 15 Minutes and it is in a for-next-loop with some other tests. If it wold send an exception the for-next could work on, but it only stops working. Can someone tell my why it only stops and doesn't send something back to the application and help me making it stop so the other tasks are run.
The only difference I see between your LocalHost vs your Client connection is the following:
[2022-02-11T09:29:10] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:435 - Starting handshake
[2022-02-11T09:29:11] [DEBUG] [Default Executor-thread-2] apache.http.conn.ssl.SSLConnectionSocketFactory:465 - Secure session established
While for your client:
[2022-02-11T09:25:50] [DEBUG] [Default Executor-thread-576] apache.http.conn.ssl.SSLConnectionSocketFactory:435 - Starting handshake
[2022-02-11T09:25:50] [DEBUG] [Finalizer thread] apache.http.impl.conn.PoolingHttpClientConnectionManager:411 - Connection manager is shutting down
You could be facing 2 issues:
You are on a server which has network firewall of some kind, which does not allow you to access the specific IP you are attempting to reach, therefore the connection is getting killed instantly.
Another issue might be that your SSL connection for that IP is invalid, however I think this is less likely, because if there is a problem in SSL, you could get some debug info regarding that.
I am trying to fetch the list of objects from a bucket of amazon s3. Below is the code that i am using.
AWSCredentials credentials = new BasicAWSCredentials(serverSettings.getAccessKey(), serverSettings.getSecretesKey());
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setSignerOverride("AWSS3V4SignerType");
AmazonS3 s3Client = AmazonS3ClientBuilder
.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(serverSettings.getStorageUri(), Regions.AP_SOUTH_1.name()))
.withPathStyleAccessEnabled(true)
.withClientConfiguration(clientConfiguration)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
return s3Client;
public List<String> getBucketFiles(String bucket) {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucket)
.withDelimiter("/");
ObjectListing listing = s3Client.listObjects(listObjectsRequest);
log.debug("Bucket : {} contain files : {}", bucket, filesInBucket);
return filesInBucket;
}
While fetching s3Client.listObjects(listObjectsRequest) i get the below error.
2020-02-25 15:45:03.955 DEBUG com.amazonaws.AmazonWebServiceClient - Internal logging successfully configured to commons logger: true
2020-02-25 15:45:03.955 DEBUG com.amazonaws.metrics.AwsSdkMetrics - Admin mbean registered under com.amazonaws.management:type=AwsSdkMetrics
2020-02-25 15:45:04.002 WARN com.amazonaws.http.AmazonHttpClient - SSL Certificate checking for endpoints has been explicitly disabled.
2020-02-25 15:45:04.086 DEBUG com.amazonaws.request - Sending Request: GET https://s3.console.aws.amazon.com/s3/home?region=ap-southeast-1# /r9a2/ Parameters: ({"delimiter":["/"],"encoding-type":["url"]}Headers: (User-Agent: aws-sdk-java/1.11.232 Windows_10/10.0 Java_HotSpot(TM)_64-Bit_Server_VM/25.241-b07 java/1.8.0_241, amz-sdk-invocation-id: 24587b25-9691-3123-343a-329a6e57d106, Content-Type: application/octet-stream, )
2020-02-25 15:45:04.171 DEBUG com.amazonaws.auth.AWS4Signer - AWS4 Canonical Request: '"GET
/s3/home/r9a2/
delimiter=%2F&encoding-type=url
amz-sdk-invocation-id:24587b25-9691-3123-343a-329a6e57d106
amz-sdk-retry:0/0/500
content-type:application/octet-stream
host:s3.console.aws.amazon.com
user-agent:aws-sdk-java/1.11.232 Windows_10/10.0 Java_HotSpot(TM)_64-Bit_Server_VM/25.241-b07 java/1.8.0_241
x-amz-content-sha256:UNSIGNED-PAYLOAD
x-amz-date:20200225T101504Z
amz-sdk-invocation-id;amz-sdk-retry;content-type;host;user-agent;x-amz-content-sha256;x-amz-date
UNSIGNED-PAYLOAD"
2020-02-25 15:45:04.171 DEBUG com.amazonaws.auth.AWS4Signer - AWS4 String to Sign: '"AWS4-HMAC-SHA256
20200225T101504Z
20200225/AP_SOUTH_1/s3/aws4_request
2104ae348572863769961aabcbe488d3aae778eb807905f0d8e67edf95b6f659"
2020-02-25 15:45:04.171 DEBUG com.amazonaws.auth.AWS4Signer - Generating a new signing key as the signing key not available in the cache for the date 1582588800000
2020-02-25 15:45:04.187 DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default
2020-02-25 15:45:04.187 DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
2020-02-25 15:45:04.187 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://s3.console.aws.amazon.com:443][total kept alive: 0; route allocated: 0 of 50; total allocated: 0 of 50]
2020-02-25 15:45:04.202 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://s3.console.aws.amazon.com:443][total kept alive: 0; route allocated: 1 of 50; total allocated: 1 of 50]
2020-02-25 15:45:04.202 DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {s}->https://s3.console.aws.amazon.com:443
2020-02-25 15:45:05.961 DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to s3.console.aws.amazon.com/54.240.226.19:443
2020-02-25 15:45:05.975 DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 172.27.147.254:63178<->54.240.226.19:443
2020-02-25 15:45:05.975 DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 50000
2020-02-25 15:45:05.975 DEBUG org.apache.http.impl.execchain.MainClientExec - Executing request GET /s3/home?region=ap-southeast-1 HTTP/1.1
2020-02-25 15:45:05.975 DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> GET /s3/home?region=ap-southeast-1 HTTP/1.1
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> Host: s3.console.aws.amazon.com
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> x-amz-content-sha256: UNSIGNED-PAYLOAD
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> Authorization: AWS4-HMAC-SHA256 Credential=AKIA3N5SPIMUI7VMSV6J/20200225/AP_SOUTH_1/s3/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-retry;content-type;host;user-agent;x-amz-content-sha256;x-amz-date, Signature=2f08656e1ec077e9b5c69ffd4d5ffff623a8576e66298fb77634ce04a0f7b27b
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> X-Amz-Date: 20200225T101504Z
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: aws-sdk-java/1.11.232 Windows_10/10.0 Java_HotSpot(TM)_64-Bit_Server_VM/25.241-b07 java/1.8.0_241
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> amz-sdk-invocation-id: 24587b25-9691-3123-343a-329a6e57d106
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> amz-sdk-retry: 0/0/500
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/octet-stream
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 0
2020-02-25 15:45:05.975 DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 200 OK
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Server: Server
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Date: Tue, 25 Feb 2020 10:15:06 GMT
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: text/html;charset=ISO-8859-1
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Content-Length: 989
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Strict-Transport-Security: max-age=47304000; includeSubDomains
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Cache-Control: proxy-revalidate
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Connection: Keep-Alive
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: awsc-authTimer=%7B%22start%22%3A%221582625706301%22%7D; Secure; HttpOnly
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: aws-creds=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/s3; Secure
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: aws-creds=""; Domain=s3.console.aws.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/s3; Secure
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: aws-creds=""; Domain=console.aws.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/s3; Secure
2020-02-25 15:45:06.346 DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: JSESSIONID=C16202E2D237233CBB71A1BC2EC29B0A; Path=/; HttpOnly
2020-02-25 15:45:06.346 DEBUG org.apache.http.impl.execchain.MainClientExec - Connection can be kept alive for 60000 MILLISECONDS
2020-02-25 15:45:06.346 DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted [awsc-authTimer="%7B%22start%22%3A%221582625706301%22%7D", version:0, domain:s3.console.aws.amazon.com, path:/s3, expiry:null]
2020-02-25 15:45:06.346 DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted [aws-creds="""", version:0, domain:s3.console.aws.amazon.com, path:/s3, expiry:Thu Jan 01 05:30:10 IST 1970]
2020-02-25 15:45:06.346 DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted [aws-creds="""", version:0, domain:s3.console.aws.amazon.com, path:/s3, expiry:Thu Jan 01 05:30:10 IST 1970]
2020-02-25 15:45:06.346 DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted [aws-creds="""", version:0, domain:console.aws.amazon.com, path:/s3, expiry:Thu Jan 01 05:30:10 IST 1970]
2020-02-25 15:45:06.346 DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted [JSESSIONID="C16202E2D237233CBB71A1BC2EC29B0A", version:0, domain:s3.console.aws.amazon.com, path:/, expiry:null]
2020-02-25 15:45:06.362 DEBUG com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser - Sanitizing XML document destined for handler class com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser$ListBucketHandler
2020-02-25 15:45:06.362 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection [id: 0][route: {s}->https://s3.console.aws.amazon.com:443] can be kept alive for 60.0 seconds
2020-02-25 15:45:06.362 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://s3.console.aws.amazon.com:443][total kept alive: 1; route allocated: 1 of 50; total allocated: 1 of 50]
2020-02-25 15:45:06.362 DEBUG com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser - Parsing XML response document with handler: class com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser$ListBucketHandler
com.amazonaws.SdkClientException: Failed to parse XML document with handler class com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser$ListBucketHandler
at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.parseXmlInputStream(XmlResponsesSaxParser.java:161) ~[aws-java-sdk-s3-1.11.232.jar:?]
at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.parseListBucketObjectsResponse(XmlResponsesSaxParser.java:317) ~[aws-java-sdk-s3-1.11.232.jar:?]
at com.amazonaws.services.s3.model.transform.Unmarshallers$ListObjectsUnmarshaller.unmarshall(Unmarshallers.java:70) ~[aws-java-sdk-s3-1.11.232.jar:?]
at com.amazonaws.services.s3.model.transform.Unmarshallers$ListObjectsUnmarshaller.unmarshall(Unmarshallers.java:59) ~[aws-java-sdk-s3-1.11.232.jar:?]
at com.amazonaws.services.s3.internal.S3XmlResponseHandler.handle(S3XmlResponseHandler.java:62) ~[aws-java-sdk-s3-1.11.232.jar:?]
at com.amazonaws.services.s3.internal.S3XmlResponseHandler.handle(S3XmlResponseHandler.java:31) ~[aws-java-sdk-s3-1.11.232.jar:?]
at com.amazonaws.http.response.AwsResponseHandlerAdapter.handle(AwsResponseHandlerAdapter.java:70) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleResponse(AmazonHttpClient.java:1554) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1272) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1056) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513) ~[aws-java-sdk-core-1.11.232.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4319) ~[aws-java-sdk-s3-1.11.232.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4266) ~[aws-java-sdk-s3-1.11.232.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4260) ~[aws-java-sdk-s3-1.11.232.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:831) ~[aws-java-sdk-s3-1.11.232.jar:?]
at org.apache.sshd.common.file.root.RootedFileSystemProvider$1.iterator(RootedFileSystemProvider.java:204) [sshd-core-2.1.0.jar:2.1.0]
at org.apache.sshd.server.subsystem.sftp.DirectoryHandle.<init>(DirectoryHandle.java:52) [sshd-sftp-2.1.0.jar:2.1.0]
at org.apache.sshd.server.subsystem.sftp.SftpSubsystem.doOpenDir(SftpSubsystem.java:746) [sshd-sftp-2.1.0.jar:2.1.0]
at org.apache.sshd.server.subsystem.sftp.AbstractSftpSubsystemHelper.doOpenDir(AbstractSftpSubsystemHelper.java:696) [sshd-sftp-2.1.0.jar:2.1.0]
at org.apache.sshd.server.subsystem.sftp.AbstractSftpSubsystemHelper.doProcess(AbstractSftpSubsystemHelper.java:369) [sshd-sftp-2.1.0.jar:2.1.0]
at org.apache.sshd.server.subsystem.sftp.SftpSubsystem.doProcess(SftpSubsystem.java:335) [sshd-sftp-2.1.0.jar:2.1.0]
at org.apache.sshd.server.subsystem.sftp.AbstractSftpSubsystemHelper.process(AbstractSftpSubsystemHelper.java:336) [sshd-sftp-2.1.0.jar:2.1.0]
at org.apache.sshd.server.subsystem.sftp.SftpSubsystem.run(SftpSubsystem.java:308) [sshd-sftp-2.1.0.jar:2.1.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_241]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_241]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_241]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_241]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
Caused by: org.xml.sax.SAXParseException: The reference to entity "state" must end with the ';' delimiter.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1850) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3061) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) ~[?:1.8.0_241]
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) ~[?:1.8.0_241]
at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.parseXmlInputStream(XmlResponsesSaxParser.java:147) ~[aws-java-sdk-s3-1.11.232.jar:?]
... 36 more
The things which i have tried to solve this are:
- Added encoding url as .withEncodingType("url"); but doesnt work.
- Updated the access of the bucket as public access.
Version of amazon sdk used is 1.11.232
Any idea how to resolve this issue?
What is the recommended way to use Conscrypt with Apache HttpClient 5?
I've tried adding the conscrypt-openjdk-uber-2.2.1.jar jar to my classpath and configuring my sslcontext as SSLContexts.custom().setProvider(Conscrypt.newProvider()), but when I test HttpClient with that sslcontext it throws:
[main] INFO org.apache.hc.client5.http.impl.classic.HttpRequestRetryExec -
Recoverable I/O exception (java.net.NoRouteToHostException) caught when processing request to
{s}->https://www.wikipedia.org:443
If I remove the custom setProvider line then it works perfectly (via regular JSSE).
I notice that Conscrypt is listed as a dependency here: https://hc.apache.org/httpcomponents-client-5.0.x/httpclient5/dependencies.html, so perhaps there is built-in support for Conscrypt that I need to enable somewhere?
You do not really need to do anything. HttpClient automatically detects and configures Conscrypt as a provider for its async TLS layer on Java 1.7 and 1.8.
For all newer JREs one can explicitly configure the connection manager to use Conscrypt based TLS strategy:
PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder.create()
.setTlsStrategy(ConscryptClientTlsStrategy.getSystemDefault())
.build();
CloseableHttpAsyncClient client = HttpAsyncClients.custom()
.setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
.setConnectionManager(cm)
.build();
UPDATED
The following code snippet works for me with HttpClient 5.0-beta7
final SSLContext sslcontext = SSLContexts.custom()
.setProvider(Conscrypt.newProvider())
.build();
final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create()
.setSslContext(sslcontext)
.build();
final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(sslSocketFactory)
.build();
try (CloseableHttpClient httpclient = HttpClients.custom()
.setConnectionManager(cm)
.build()) {
final HttpGet httpget = new HttpGet("https://www.wikipedia.org/");
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
final HttpClientContext clientContext = HttpClientContext.create();
try (CloseableHttpResponse response = httpclient.execute(httpget, clientContext)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
final SSLSession sslSession = clientContext.getSSLSession();
if (sslSession != null) {
System.out.println("SSL protocol " + sslSession.getProtocol());
System.out.println("SSL cipher suite " + sslSession.getCipherSuite());
}
}
}
Console output:
Executing request GET https://www.wikipedia.org/
2020-02-06 10:33:22,619 DEBUG ex-00000001: preparing request execution
2020-02-06 10:33:22,625 DEBUG Cookie spec selected: strict
2020-02-06 10:33:22,629 DEBUG Auth cache not set in the context
2020-02-06 10:33:22,629 DEBUG ex-00000001: target auth state: UNCHALLENGED
2020-02-06 10:33:22,630 DEBUG ex-00000001: proxy auth state: UNCHALLENGED
2020-02-06 10:33:22,630 DEBUG ex-00000001: acquiring connection with route {s}->https://www.wikipedia.org:443
2020-02-06 10:33:22,630 DEBUG ex-00000001: acquiring endpoint (3 MINUTES)
2020-02-06 10:33:22,632 DEBUG ex-00000001: endpoint lease request (3 MINUTES) [route: {s}->https://www.wikipedia.org:443][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25]
2020-02-06 10:33:22,636 DEBUG ex-00000001: endpoint leased [route: {s}->https://www.wikipedia.org:443][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25]
2020-02-06 10:33:22,649 DEBUG ex-00000001: acquired ep-00000000
2020-02-06 10:33:22,649 DEBUG ex-00000001: acquired endpoint ep-00000000
2020-02-06 10:33:22,649 DEBUG ex-00000001: opening connection {s}->https://www.wikipedia.org:443
2020-02-06 10:33:22,650 DEBUG ep-00000000: connecting endpoint (3 MINUTES)
2020-02-06 10:33:22,650 DEBUG ep-00000000: connecting endpoint to https://www.wikipedia.org:443 (3 MINUTES)
2020-02-06 10:33:22,654 DEBUG http-outgoing-0: connecting to www.wikipedia.org/91.198.174.192:443
2020-02-06 10:33:22,654 DEBUG Connecting socket to www.wikipedia.org/91.198.174.192:443 with timeout 3 MINUTES
2020-02-06 10:33:22,759 DEBUG Enabled protocols: [TLSv1.2, TLSv1.3]
2020-02-06 10:33:22,759 DEBUG Enabled cipher suites:[TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
2020-02-06 10:33:22,759 DEBUG Starting handshake
2020-02-06 10:33:23,192 DEBUG Secure session established
2020-02-06 10:33:23,192 DEBUG negotiated protocol: TLSv1.2
2020-02-06 10:33:23,192 DEBUG negotiated cipher suite: TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
2020-02-06 10:33:23,192 DEBUG peer principal: CN=*.wikipedia.org, O="Wikimedia Foundation, Inc.", L=San Francisco, ST=California, C=US
2020-02-06 10:33:23,193 DEBUG peer alternative names: [*.wikipedia.org, *.wikimedia.org, *.wmfusercontent.org, *.wikimediafoundation.org, *.wiktionary.org, *.wikivoyage.org, *.wikiversity.org, *.wikisource.org, *.wikiquote.org, *.wikinews.org, *.wikidata.org, *.wikibooks.org, wikimedia.org, *.mediawiki.org, wikipedia.org, wikiquote.org, mediawiki.org, wmfusercontent.org, w.wiki, wikimediafoundation.org, wikibooks.org, wiktionary.org, wikivoyage.org, wikidata.org, wikiversity.org, wikisource.org, wikinews.org, *.m.wikipedia.org, *.m.wiktionary.org, *.m.wikivoyage.org, *.m.wikiquote.org, *.m.wikiversity.org, *.m.wikisource.org, *.m.wikimedia.org, *.m.wikinews.org, *.m.wikidata.org, *.m.wikibooks.org, *.planet.wikimedia.org, *.m.mediawiki.org]
2020-02-06 10:33:23,193 DEBUG issuer principal: CN=DigiCert SHA2 High Assurance Server CA, OU=www.digicert.com, O=DigiCert Inc, C=US
2020-02-06 10:33:23,196 DEBUG http-outgoing-0: connection established 192.168.43.143:55022<->91.198.174.192:443
2020-02-06 10:33:23,196 DEBUG ep-00000000: connected http-outgoing-0
2020-02-06 10:33:23,196 DEBUG ep-00000000: endpoint connected
2020-02-06 10:33:23,197 DEBUG ex-00000001: executing GET / HTTP/1.1
2020-02-06 10:33:23,197 DEBUG ep-00000000: start execution ex-00000001
2020-02-06 10:33:23,197 DEBUG ep-00000000: executing exchange ex-00000001 over http-outgoing-0
2020-02-06 10:33:23,198 DEBUG http-outgoing-0 >> GET / HTTP/1.1
2020-02-06 10:33:23,198 DEBUG http-outgoing-0 >> Accept-Encoding: gzip, x-gzip, deflate
2020-02-06 10:33:23,198 DEBUG http-outgoing-0 >> Host: www.wikipedia.org
2020-02-06 10:33:23,198 DEBUG http-outgoing-0 >> Connection: keep-alive
2020-02-06 10:33:23,198 DEBUG http-outgoing-0 >> User-Agent: Apache-HttpClient/5.0-beta8-SNAPSHOT (Java/1.8.0_181)
2020-02-06 10:33:23,402 DEBUG http-outgoing-0 << HTTP/1.1 200 OK
2020-02-06 10:33:23,403 DEBUG http-outgoing-0 << Date: Wed, 05 Feb 2020 20:39:26 GMT
2020-02-06 10:33:23,403 DEBUG http-outgoing-0 << Cache-Control: s-maxage=86400, must-revalidate, max-age=3600
2020-02-06 10:33:23,403 DEBUG http-outgoing-0 << Server: ATS/8.0.5
2020-02-06 10:33:23,404 DEBUG http-outgoing-0 << X-ATS-Timestamp: 1580935166
2020-02-06 10:33:23,404 DEBUG http-outgoing-0 << ETag: W/"12be8-59c0633ed3519"
2020-02-06 10:33:23,404 DEBUG http-outgoing-0 << Content-Type: text/html
2020-02-06 10:33:23,404 DEBUG http-outgoing-0 << Last-Modified: Mon, 13 Jan 2020 14:22:18 GMT
2020-02-06 10:33:23,405 DEBUG http-outgoing-0 << Backend-Timing: D=320 t=1579084179579408
2020-02-06 10:33:23,405 DEBUG http-outgoing-0 << Content-Encoding: gzip
2020-02-06 10:33:23,405 DEBUG http-outgoing-0 << Vary: Accept-Encoding
2020-02-06 10:33:23,405 DEBUG http-outgoing-0 << X-Varnish: 118503554 495852195
2020-02-06 10:33:23,406 DEBUG http-outgoing-0 << Age: 46437
2020-02-06 10:33:23,406 DEBUG http-outgoing-0 << X-Cache: cp3062 miss, cp3052 hit/600912
2020-02-06 10:33:23,406 DEBUG http-outgoing-0 << X-Cache-Status: hit-front
2020-02-06 10:33:23,407 DEBUG http-outgoing-0 << Server-Timing: cache;desc="hit-front"
2020-02-06 10:33:23,407 DEBUG http-outgoing-0 << Strict-Transport-Security: max-age=106384710; includeSubDomains; preload
2020-02-06 10:33:23,407 DEBUG http-outgoing-0 << Set-Cookie: WMF-Last-Access=06-Feb-2020;Path=/;HttpOnly;secure;Expires=Mon, 09 Mar 2020 00:00:00 GMT
2020-02-06 10:33:23,407 DEBUG http-outgoing-0 << Set-Cookie: WMF-Last-Access-Global=06-Feb-2020;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Mon, 09 Mar 2020 00:00:00 GMT
2020-02-06 10:33:23,408 DEBUG http-outgoing-0 << X-Client-IP: 213.55.225.99
2020-02-06 10:33:23,418 DEBUG http-outgoing-0 << Set-Cookie: GeoIP=CH:ZH:Zurich:47.37:8.55:v4; Path=/; secure; Domain=.wikipedia.org
2020-02-06 10:33:23,418 DEBUG http-outgoing-0 << Accept-Ranges: bytes
2020-02-06 10:33:23,418 DEBUG http-outgoing-0 << Content-Length: 18800
2020-02-06 10:33:23,419 DEBUG http-outgoing-0 << Connection: keep-alive
2020-02-06 10:33:23,429 DEBUG ex-00000001: connection can be kept alive for -1 MILLISECONDS
2020-02-06 10:33:23,437 DEBUG Cookie accepted [WMF-Last-Access="06-Feb-2020", domain:www.wikipedia.org, path:/, expiry:Mon Mar 09 01:00:00 CET 2020]
2020-02-06 10:33:23,438 DEBUG Cookie accepted [WMF-Last-Access-Global="06-Feb-2020", domain:wikipedia.org, path:/, expiry:Mon Mar 09 01:00:00 CET 2020]
2020-02-06 10:33:23,438 DEBUG Cookie accepted [GeoIP="CH:ZH:Zurich:47.37:8.55:v4", domain:wikipedia.org, path:/, expiry:null]
----------------------------------------
200 OK
SSL protocol TLSv1.2
SSL cipher suite TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
2020-02-06 10:33:23,467 DEBUG http-outgoing-0: close connection GRACEFUL
2020-02-06 10:33:23,468 DEBUG ep-00000000: endpoint closed
2020-02-06 10:33:23,468 DEBUG ep-00000000: endpoint closed
2020-02-06 10:33:23,468 DEBUG ep-00000000: discarding endpoint
2020-02-06 10:33:23,468 DEBUG ep-00000000: releasing endpoint
2020-02-06 10:33:23,469 DEBUG ep-00000000: connection released [route: {s}->https://www.wikipedia.org:443][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25]
2020-02-06 10:33:23,469 DEBUG Shutdown connection pool GRACEFUL
2020-02-06 10:33:23,469 DEBUG Connection pool shut down
I'm trying to create auto test (java). Service should be able to handle request correctly: return json instead of java stack trace.
In this test i have cases like #host/some/path/?param=%
Ok, % is incorrect symbol and should be encoded. When you are developer and creating service that send requests. But this is a test.
So question is: how can i create get response with url «as is», without encoding? Currently i'm using apache httpclient (4.5.2)
Currently i have nothing really special:
public void fetchGet(String uri) {
HttpGet getRequest = new HttpGet(uri);
HttpClient client = HttpClientBuilder.create().build();
try {
response = client.execute(requestBase);
} catch (IOException e) {
e.printStackTrace();
} finally {
requestBase.abort();
}
}
Use BasicHttpRequest instead of HttpGet to compose a request message
CloseableHttpClient client = HttpClientBuilder.create().build();
BasicHttpRequest request = new BasicHttpRequest("GET", "all kind of c%.p");
try (CloseableHttpResponse response1 = client.execute(new HttpHost("www.google.com"), request)) {
System.out.println(response1.getStatusLine());
EntityUtils.consume(response1.getEntity());
}
This code produces the following message exchange
[DEBUG] ProtocolExec - Unable to parse 'all kind of c%.p' as a valid URI; request URI and Host header may be inconsistent <java.lang.IllegalArgumentException: Illegal character in path at index 3: all kind of c%.p>java.lang.IllegalArgumentException: Illegal character in path at index 3: all kind of c%.p
at java.net.URI.create(URI.java:852)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:120)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118)
at Testing.main(Testing.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.net.URISyntaxException: Illegal character in path at index 3: all kind of c%.p
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.parseHierarchical(URI.java:3105)
at java.net.URI$Parser.parse(URI.java:3063)
at java.net.URI.<init>(URI.java:588)
at java.net.URI.create(URI.java:850)
... 11 more
[DEBUG] RequestAddCookies - CookieSpec selected: default
[DEBUG] RequestAuthCache - Auth cache not set in the context
[DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {}->http://www.google.com:80][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://www.google.com:80][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
[DEBUG] MainClientExec - Opening connection {}->http://www.google.com:80
[DEBUG] DefaultHttpClientConnectionOperator - Connecting to www.google.com/216.58.213.100:80
[DEBUG] DefaultHttpClientConnectionOperator - Connection established xx.xx.xx.xx:36088<->216.58.213.100:80
[DEBUG] MainClientExec - Executing request GET all kind of c%.p HTTP/1.1
[DEBUG] MainClientExec - Target auth state: UNCHALLENGED
[DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
[DEBUG] headers - http-outgoing-0 >> GET all kind of c%.p HTTP/1.1
[DEBUG] headers - http-outgoing-0 >> Host: www.google.com
[DEBUG] headers - http-outgoing-0 >> Connection: Keep-Alive
[DEBUG] headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_112)
[DEBUG] headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
[DEBUG] headers - http-outgoing-0 << HTTP/1.1 400 Bad Request
[DEBUG] headers - http-outgoing-0 << Cache-Control: no-cache
[DEBUG] headers - http-outgoing-0 << Pragma: no-cache
[DEBUG] headers - http-outgoing-0 << Content-Type: text/html; charset=utf-8
[DEBUG] headers - http-outgoing-0 << Connection: close
[DEBUG] headers - http-outgoing-0 << Content-Length: 1904
HTTP/1.1 400 Bad Request
[DEBUG] DefaultManagedHttpClientConnection - http-outgoing-0: Close connection
[DEBUG] MainClientExec - Connection discarded
[DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://www.google.com:80][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
I'm trying to send requests with HTTP Client 4.4 through a proxy with Basic Auth.
If I enter the right credentials, then the connection is successful.
But if I enter the wrong credentials, all the following other connection attempts will fails even with the right credentials.
It seems like once we have supplied the (wrong) credentials for the first time, the new (correct or wrong) credentials are never sent.
You will see there are two calls:
1st call, wrong proxy credentials
2nd call, correct proxy credentials
The code:
package test;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
public class Main {
private HttpClient client;
private HttpClientContext context = HttpClientContext.create();
public static void main(String[] args) throws Exception {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "DEBUG");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "ERROR");
Main main = new Main();
main.createHttpClient();
main.send(true, "test", "wrong"); // 1st call, wrong credentials, if this call is removed, it works !
main.send(true, "test", "correct"); // 2nd call, correct credentials
}
public void send(String username, String password) throws Exception {
proxyAuthenticate(username, password);
HttpUriRequest request = new HttpGet("https://the-backend.xyz");
HttpResponse httpResponse = client.execute(request, context);
int statusCode = httpResponse.getStatusLine().getStatusCode();
System.out.println("######################### " + statusCode);
}
public void createHttpClient() throws Exception {
HttpClientBuilder httpClientBuilder = HttpClients.custom();
httpClientBuilder.setProxy(new HttpHost("proxy.the-proxy.xyz", 1234));
client = httpClientBuilder.build();
}
private void proxyAuthenticate(String username, String password) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
AuthScope scope = new AuthScope("proxy.the-proxy.xyz", 1234);
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(scope, credentials);
context.setCredentialsProvider(provider);
}
}
The logs for 1st attempt (connect with wrong proxy cred: two http requests one without the creds, one with the creds, both returns 407, looks logical):
2015/10/07 13:39:02:502 CEST [WARN] BasicAuthCache - Unexpected I/O
error while serializing auth scheme java.io.NotSerializableException: test.Main at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at
org.apache.http.impl.client.BasicAuthCache.put(BasicAuthCache.java:107)
at test.Main.proxyAuthenticate(Main.java:109) at
test.Main.send(Main.java:56) at test.Main2.main(Main2.java:30)
2015/10/07 13:39:02:502 CEST [DEBUG] RequestAddCookies - CookieSpec
selected: default 2015/10/07 13:39:02:502 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection request: [route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 0 of 3; total allocated: 0 of 3]
2015/10/07 13:39:02:502 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection leased: [id: 1][route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 1 of 3; total allocated: 1 of 3]
2015/10/07 13:39:02:502 CEST [DEBUG] MainClientExec - Opening
connection
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443
2015/10/07 13:39:02:502 CEST [DEBUG]
DefaultHttpClientConnectionOperator - Connecting to
proxy.the-proxy.xyz/123.45.67.890:1234 2015/10/07 13:39:07:530 CEST
[DEBUG] DefaultHttpClientConnectionOperator - Connection established
321.54.76.098:58216<->123.45.67.890:1234 2015/10/07 13:39:07:530 CEST [DEBUG] headers - http-outgoing-1 >> CONNECT
the-backend.xyz:443 HTTP/1.1 2015/10/07 13:39:07:530
CEST [DEBUG] headers - http-outgoing-1 >> Host:
the-backend.xyz 2015/10/07 13:39:07:530 CEST [DEBUG]
headers - http-outgoing-1 >> User-Agent: Apache-HttpClient/4.4.1
(Java/1.7.0_51) 2015/10/07 13:39:07:530 CEST [DEBUG] headers -
http-outgoing-1 << HTTP/1.1 407 Proxy Authentication Required
2015/10/07 13:39:07:530 CEST [DEBUG] headers - http-outgoing-1 <<
Proxy-Authenticate: BASIC realm="InternetAccess" 2015/10/07
13:39:07:530 CEST [DEBUG] headers - http-outgoing-1 << Cache-Control:
no-cache 2015/10/07 13:39:07:530 CEST [DEBUG] headers -
http-outgoing-1 << Pragma: no-cache 2015/10/07 13:39:07:530 CEST
[DEBUG] headers - http-outgoing-1 << Content-Type: text/html;
charset=utf-8 2015/10/07 13:39:07:530 CEST [DEBUG] headers -
http-outgoing-1 << Proxy-Connection: close 2015/10/07 13:39:07:530
CEST [DEBUG] headers - http-outgoing-1 << Connection: close 2015/10/07
13:39:07:530 CEST [DEBUG] headers - http-outgoing-1 << Content-Length:
2916 2015/10/07 13:39:07:530 CEST [DEBUG] HttpAuthenticator -
Authentication required 2015/10/07 13:39:07:530 CEST [DEBUG]
HttpAuthenticator - proxy.the-proxy.xyz:1234 requested authentication
2015/10/07 13:39:07:530 CEST [DEBUG] ProxyAuthenticationStrategy -
Authentication schemes in the order of preference: [Negotiate,
Kerberos, NTLM, Digest, Basic] 2015/10/07 13:39:07:530 CEST [DEBUG]
ProxyAuthenticationStrategy - Challenge for Negotiate authentication
scheme not available 2015/10/07 13:39:07:530 CEST [DEBUG]
ProxyAuthenticationStrategy - Challenge for Kerberos authentication
scheme not available 2015/10/07 13:39:07:530 CEST [DEBUG]
ProxyAuthenticationStrategy - Challenge for NTLM authentication scheme
not available 2015/10/07 13:39:07:530 CEST [DEBUG]
ProxyAuthenticationStrategy - Challenge for Digest authentication
scheme not available 2015/10/07 13:39:07:530 CEST [DEBUG]
HttpAuthenticator - Selected authentication options: [BASIC
[complete=true]] 2015/10/07 13:39:07:530 CEST [DEBUG]
DefaultManagedHttpClientConnection - http-outgoing-1: Close connection
2015/10/07 13:39:07:530 CEST [DEBUG]
DefaultHttpClientConnectionOperator - Connecting to
proxy.the-proxy.xyz/123.45.67.890:1234 2015/10/07 13:39:12:560 CEST
[DEBUG] DefaultHttpClientConnectionOperator - Connection established
321.54.76.098:58217<->123.45.67.890:1234 2015/10/07 13:39:12:560 CEST [DEBUG] HttpAuthenticator - Generating response to an authentication
challenge using basic scheme 2015/10/07 13:39:12:560 CEST [DEBUG]
headers - http-outgoing-1 >> CONNECT
the-backend.xyz:443 HTTP/1.1 2015/10/07 13:39:12:560
CEST [DEBUG] headers - http-outgoing-1 >> Host:
the-backend.xyz 2015/10/07 13:39:12:560 CEST [DEBUG]
headers - http-outgoing-1 >> User-Agent: Apache-HttpClient/4.4.1
(Java/1.7.0_51) 2015/10/07 13:39:12:560 CEST [DEBUG] headers -
http-outgoing-1 >> Proxy-Authorization: Basic xXXxxXxXXXXX 2015/10/07
13:39:12:561 CEST [DEBUG] headers - http-outgoing-1 << HTTP/1.1 407
Proxy Authentication Required 2015/10/07 13:39:12:561 CEST [DEBUG]
headers - http-outgoing-1 << Proxy-Authenticate: BASIC
realm="InternetAccess" 2015/10/07 13:39:12:561 CEST [DEBUG] headers -
http-outgoing-1 << Cache-Control: no-cache 2015/10/07 13:39:12:561
CEST [DEBUG] headers - http-outgoing-1 << Pragma: no-cache 2015/10/07
13:39:12:561 CEST [DEBUG] headers - http-outgoing-1 << Content-Type:
text/html; charset=utf-8 2015/10/07 13:39:12:561 CEST [DEBUG] headers
- http-outgoing-1 << Proxy-Connection: close 2015/10/07 13:39:12:561 CEST [DEBUG] headers - http-outgoing-1 << Connection: close 2015/10/07
13:39:12:561 CEST [DEBUG] headers - http-outgoing-1 << Content-Length:
2966 2015/10/07 13:39:12:561 CEST [DEBUG] HttpAuthenticator -
Authentication required 2015/10/07 13:39:12:561 CEST [DEBUG]
HttpAuthenticator - proxy.the-proxy.xyz:1234 requested authentication
2015/10/07 13:39:12:561 CEST [DEBUG] HttpAuthenticator - Authorization
challenge processed 2015/10/07 13:39:12:561 CEST [DEBUG]
HttpAuthenticator - Authentication failed 2015/10/07 13:39:12:561 CEST
[DEBUG] ProxyAuthenticationStrategy - Clearing cached auth scheme for
http://proxy.the-proxy.xyz:1234 2015/10/07 13:39:12:561 CEST [DEBUG]
DefaultManagedHttpClientConnection - http-outgoing-1: Close connection
2015/10/07 13:39:12:561 CEST [DEBUG] MainClientExec - CONNECT refused
by proxy: HTTP/1.1 407 Proxy Authentication Required 2015/10/07
13:39:12:561 CEST [DEBUG] DefaultManagedHttpClientConnection -
http-outgoing-1: Close connection 2015/10/07 13:39:12:561 CEST [DEBUG]
MainClientExec - Connection discarded 2015/10/07 13:39:12:561 CEST
[DEBUG] DefaultManagedHttpClientConnection - http-outgoing-1: Close
connection 2015/10/07 13:39:12:561 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection released: [id:
1][route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 0 of 3; total allocated: 0 of 3]
################### 407
The logs for 2nd attempt (connect with correct proxy cred: only one http request, why isn't there a second request with the correct creds ???):
2015/10/07 13:39:17:585 CEST [WARN] BasicAuthCache - Unexpected I/O
error while serializing auth scheme java.io.NotSerializableException: test.Main at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at
org.apache.http.impl.client.BasicAuthCache.put(BasicAuthCache.java:107)
at test.Main.proxyAuthenticate(Main.java:109) at
test.Main.send(Main.java:56) at test.Main2.main(Main2.java:32)
2015/10/07 13:39:17:585 CEST [DEBUG] RequestAddCookies - CookieSpec
selected: default 2015/10/07 13:39:17:585 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection request: [route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 0 of 3; total allocated: 0 of 3]
2015/10/07 13:39:17:585 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection leased: [id: 2][route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 1 of 3; total allocated: 1 of 3]
2015/10/07 13:39:17:585 CEST [DEBUG] MainClientExec - Opening
connection
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443
2015/10/07 13:39:17:585 CEST [DEBUG]
DefaultHttpClientConnectionOperator - Connecting to
proxy.the-proxy.xyz/123.45.67.890:1234
2015/10/07 13:39:17:585 CEST [DEBUG] DefaultHttpClientConnectionOperator - Connection established
321.54.76.098:58218<->123.45.67.890:1234 2015/10/07 13:39:17:586 CEST [DEBUG] headers - http-outgoing-2 >> CONNECT
the-backend.xyz:443 HTTP/1.1 2015/10/07 13:39:17:586
CEST [DEBUG] headers - http-outgoing-2 >> Host:
the-backend.xyz 2015/10/07 13:39:17:586 CEST [DEBUG]
headers - http-outgoing-2 >> User-Agent: Apache-HttpClient/4.4.1
(Java/1.7.0_51) 2015/10/07 13:39:17:586 CEST [DEBUG] headers -
http-outgoing-2 << HTTP/1.1 407 Proxy Authentication Required
2015/10/07 13:39:17:586 CEST [DEBUG] headers - http-outgoing-2 <<
Proxy-Authenticate: BASIC realm="InternetAccess" 2015/10/07
13:39:17:586 CEST [DEBUG] headers - http-outgoing-2 << Cache-Control:
no-cache 2015/10/07 13:39:17:586 CEST [DEBUG] headers -
http-outgoing-2 << Pragma: no-cache 2015/10/07 13:39:17:586 CEST
[DEBUG] headers - http-outgoing-2 << Content-Type: text/html;
charset=utf-8 2015/10/07 13:39:17:586 CEST [DEBUG] headers -
http-outgoing-2 << Proxy-Connection: close 2015/10/07 13:39:17:586
CEST [DEBUG] headers - http-outgoing-2 << Connection: close 2015/10/07
13:39:17:586 CEST [DEBUG] headers - http-outgoing-2 << Content-Length:
2916 2015/10/07 13:39:17:586 CEST [DEBUG] HttpAuthenticator -
Authentication required 2015/10/07 13:39:17:586 CEST [DEBUG]
HttpAuthenticator - proxy.the-proxy.xyz:1234 requested authentication
2015/10/07 13:39:17:586 CEST [DEBUG]
DefaultManagedHttpClientConnection - http-outgoing-2: Close connection
2015/10/07 13:39:17:586 CEST [DEBUG] MainClientExec - CONNECT refused
by proxy: HTTP/1.1 407 Proxy Authentication Required 2015/10/07
13:39:17:586 CEST [DEBUG] DefaultManagedHttpClientConnection -
http-outgoing-2: Close connection 2015/10/07 13:39:17:586 CEST [DEBUG]
MainClientExec - Connection discarded 2015/10/07 13:39:17:586 CEST
[DEBUG] DefaultManagedHttpClientConnection - http-outgoing-2: Close
connection 2015/10/07 13:39:17:586 CEST [DEBUG]
PoolingHttpClientConnectionManager - Connection released: [id:
2][route:
{tls}->http://proxy.the-proxy.xyz:1234->https://the-backend.xyz:443][total
kept alive: 0; route allocated: 0 of 3; total allocated: 0 of 3]
################### 407
Any idea why on the 2nd attempt, it tries without the auth (normal), the server replies that Basic auth is required, then instead of trying with the correct credentials, it closes the connection.
Thanks !
UPDATE:
If I change the HttpClient (from 4.4) to DefaultHttpClient (from 4.3) and adapt these two methods, it works.
Note that the getCredentialsProvider is called from the client in 4.3 and from context in 4.4 !!!
First time I receive a 407 status code but second time I receive 200 which is what I expect.
public void createHttpClient() throws Exception {
client = new DefaultHttpClient();
HttpHost proxy = new HttpHost("proxy.eurocontrol.be", 9513);
ConnRouteParams.setDefaultProxy(client.getParams(), proxy);
}
private void proxyAuthenticate(String username, String password) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
AuthScope scope = new AuthScope("proxy.eurocontrol.be", 9513);
client.getCredentialsProvider().setCredentials(scope, credentials);
// Called from client !!!!!!!!!!!!!!!!!
}
The first lines of the codes clearly tells that both the requests were made.
First at - 2015/10/07 13:39:02:502
Second at - 2015/10/07 13:39:17:585
What you are printing is the status code of the server response, see this and Http Status 407
Even your logs clearly say
Unexpected I/O error while serializing auth scheme java.io.NotSerializableException
There can be an exception due to serialization also.