[
https://issues.apache.org/jira/browse/HTTPCLIENT-2177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17416605#comment-17416605
]
Oleg Kalnichevski commented on HTTPCLIENT-2177:
-----------------------------------------------
[~avasilev] when using a sane proxy such as Squid things work as expected.
{noformat}
Executing request GET https://nghttp2.org/
2021-09-17 12:06:29,503 DEBUG ex-0000000001 preparing request execution
2021-09-17 12:06:29,512 DEBUG ex-0000000001 Cookie spec selected: strict
2021-09-17 12:06:29,517 DEBUG ex-0000000001 Auth cache not set in the context
2021-09-17 12:06:29,517 DEBUG ex-0000000001 target auth state: UNCHALLENGED
2021-09-17 12:06:29,520 DEBUG ex-0000000001 acquiring connection with route
{tls}->http://localhost:8889->https://nghttp2.org:443
2021-09-17 12:06:29,521 DEBUG ex-0000000001 acquiring endpoint (3 MINUTES)
2021-09-17 12:06:29,523 DEBUG ex-0000000001 endpoint lease request (3 MINUTES)
[route: {tls}->http://localhost:8889->https://nghttp2.org:443][total available:
0; route allocated: 0 of 5; total allocated: 0 of 25]
2021-09-17 12:06:29,527 DEBUG ex-0000000001 endpoint leased [route:
{tls}->http://localhost:8889->https://nghttp2.org:443][total available: 0;
route allocated: 1 of 5; total allocated: 1 of 25]
2021-09-17 12:06:29,528 DEBUG ex-0000000001 acquired ep-0000000000
2021-09-17 12:06:29,528 DEBUG ex-0000000001 acquired endpoint ep-0000000000
2021-09-17 12:06:29,529 DEBUG ep-0000000000 connecting endpoint (3 MINUTES)
2021-09-17 12:06:29,530 DEBUG ep-0000000000 connecting endpoint to
http://localhost:8889 (3 MINUTES)
2021-09-17 12:06:29,531 DEBUG http://localhost:8889 resolving remote address
2021-09-17 12:06:29,532 DEBUG http://localhost:8889 resolved to
[localhost/127.0.0.1]
2021-09-17 12:06:29,533 DEBUG http://localhost:8889 connecting null to
localhost/127.0.0.1:8889 (3 MINUTES)
2021-09-17 12:06:29,547 DEBUG c-0000000000[ACTIVE][rc:c] protocol upgrade class
org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiator
2021-09-17 12:06:29,548 DEBUG http://localhost:8889 connected c-0000000000
/127.0.0.1:50008->localhost/127.0.0.1:8889
2021-09-17 12:06:29,549 DEBUG ep-0000000000 connected c-0000000000
2021-09-17 12:06:29,549 DEBUG ep-0000000000 endpoint connected
2021-09-17 12:06:29,549 DEBUG ex-0000000001 connected to proxy
2021-09-17 12:06:29,551 DEBUG ex-0000000001 executing CONNECT nghttp2.org:443
HTTP/1.1
2021-09-17 12:06:29,553 DEBUG ep-0000000000 start execution ex-0000000001
2021-09-17 12:06:29,553 DEBUG ep-0000000000 executing exchange ex-0000000001
over c-0000000000
2021-09-17 12:06:29,554 DEBUG c-0000000000 RequestExecutionCommand with NORMAL
priority
2021-09-17 12:06:29,554 DEBUG c-0000000000[ACTIVE][rwc:c] Enqueued
RequestExecutionCommand with priority IMMEDIATE
2021-09-17 12:06:29,555 DEBUG c-0000000000[ACTIVE][rw:c] Event cleared [c]
2021-09-17 12:06:29,565 DEBUG c-0000000000[ACTIVE][rw:c] protocol upgrade class
org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler
2021-09-17 12:06:29,567 DEBUG ex-0000000001 send request CONNECT
nghttp2.org:443 HTTP/1.1, null entity
2021-09-17 12:06:29,567 DEBUG c-0000000000 >> CONNECT nghttp2.org:443 HTTP/1.1
2021-09-17 12:06:29,567 DEBUG c-0000000000 >> Host: nghttp2.org:443
2021-09-17 12:06:29,567 DEBUG c-0000000000 >> User-Agent:
Apache-HttpAsyncClient/5.1.1-SNAPSHOT (Java/1.8.0_282)
2021-09-17 12:06:29,568 DEBUG c-0000000000[ACTIVE][rw:c] 127 bytes written
2021-09-17 12:06:29,568 DEBUG c-0000000000[ACTIVE][rw:c] Event set [w]
2021-09-17 12:06:29,568 DEBUG c-0000000000[ACTIVE][r:c] Event cleared [w]
2021-09-17 12:06:29,568 DEBUG c-0000000000[ACTIVE][r:r] 3607 bytes read
2021-09-17 12:06:29,572 DEBUG c-0000000000 << HTTP/1.1 407 Proxy Authentication
Required
2021-09-17 12:06:29,572 DEBUG c-0000000000 << Server: squid/3.3.8
2021-09-17 12:06:29,572 DEBUG c-0000000000 << Mime-Version: 1.0
2021-09-17 12:06:29,572 DEBUG c-0000000000 << Date: Fri, 17 Sep 2021 10:06:29
GMT
2021-09-17 12:06:29,572 DEBUG c-0000000000 << Content-Type: text/html
2021-09-17 12:06:29,572 DEBUG c-0000000000 << Content-Length: 3165
2021-09-17 12:06:29,572 DEBUG c-0000000000 << X-Squid-Error:
ERR_CACHE_ACCESS_DENIED 0
2021-09-17 12:06:29,572 DEBUG c-0000000000 << Vary: Accept-Language
2021-09-17 12:06:29,572 DEBUG c-0000000000 << Content-Language: en
2021-09-17 12:06:29,572 DEBUG c-0000000000 << Proxy-Authenticate: Basic
realm="test-proxy"
2021-09-17 12:06:29,572 DEBUG c-0000000000 << X-Cache: MISS from 6a774a46c2a3
2021-09-17 12:06:29,572 DEBUG c-0000000000 << X-Cache-Lookup: NONE from
6a774a46c2a3:8888
2021-09-17 12:06:29,573 DEBUG c-0000000000 << Via: 1.1 6a774a46c2a3
(squid/3.3.8)
2021-09-17 12:06:29,573 DEBUG c-0000000000 << Connection: keep-alive
2021-09-17 12:06:29,574 DEBUG ex-0000000001 consume response HTTP/1.1 407 Proxy
Authentication Required, entity len 3165
2021-09-17 12:06:29,574 DEBUG ex-0000000001 Authentication required
2021-09-17 12:06:29,574 DEBUG ex-0000000001 localhost:8889 requested
authentication
2021-09-17 12:06:29,576 DEBUG ex-0000000001 Authentication schemes in the order
of preference: [Negotiate, Kerberos, NTLM, Digest, Basic]
2021-09-17 12:06:29,576 DEBUG ex-0000000001, Challenge for Negotiate
authentication scheme not available
2021-09-17 12:06:29,577 DEBUG ex-0000000001, Challenge for Kerberos
authentication scheme not available
2021-09-17 12:06:29,580 DEBUG ex-0000000001, Challenge for NTLM authentication
scheme not available
2021-09-17 12:06:29,581 DEBUG ex-0000000001, Challenge for Digest
authentication scheme not available
2021-09-17 12:06:29,582 DEBUG ex-0000000001 Selecting authentication options
2021-09-17 12:06:29,582 DEBUG ex-0000000001 Selected authentication options:
[Basic{realm=test-proxy}]
2021-09-17 12:06:29,585 DEBUG ex-0000000001 consume response data, len 3165
bytes
2021-09-17 12:06:29,585 DEBUG ex-0000000001 end of response data
2021-09-17 12:06:29,586 DEBUG ex-0000000001 Generating response to an
authentication challenge using Basic scheme
2021-09-17 12:06:29,592 DEBUG ex-0000000001 executing CONNECT nghttp2.org:443
HTTP/1.1
2021-09-17 12:06:29,593 DEBUG ep-0000000000 start execution ex-0000000001
2021-09-17 12:06:29,593 DEBUG ep-0000000000 executing exchange ex-0000000001
over c-0000000000
2021-09-17 12:06:29,593 DEBUG c-0000000000 RequestExecutionCommand with NORMAL
priority
2021-09-17 12:06:29,593 DEBUG c-0000000000[ACTIVE][rw:r] Enqueued
RequestExecutionCommand with priority IMMEDIATE
2021-09-17 12:06:29,593 DEBUG c-0000000000[ACTIVE][rw:r] Event set [r]
2021-09-17 12:06:29,593 DEBUG c-0000000000 Connection is kept alive
2021-09-17 12:06:29,594 DEBUG c-0000000000[ACTIVE][r:r] Event cleared [w]
2021-09-17 12:06:29,594 DEBUG ex-0000000001 send request CONNECT
nghttp2.org:443 HTTP/1.1, null entity
2021-09-17 12:06:29,594 DEBUG c-0000000000 >> CONNECT nghttp2.org:443 HTTP/1.1
2021-09-17 12:06:29,594 DEBUG c-0000000000 >> Host: nghttp2.org:443
2021-09-17 12:06:29,594 DEBUG c-0000000000 >> User-Agent:
Apache-HttpAsyncClient/5.1.1-SNAPSHOT (Java/1.8.0_282)
2021-09-17 12:06:29,594 DEBUG c-0000000000 >> Proxy-Authorization: Basic
c3F1aWQ6bm9wYXNzd29yZA==
2021-09-17 12:06:29,595 DEBUG c-0000000000[ACTIVE][r:r] 180 bytes written
2021-09-17 12:06:29,595 DEBUG c-0000000000[ACTIVE][rw:r] Event set [w]
2021-09-17 12:06:29,595 DEBUG c-0000000000[ACTIVE][r:w] Event cleared [w]
2021-09-17 12:06:30,066 DEBUG c-0000000000[ACTIVE][r:r] 39 bytes read
2021-09-17 12:06:30,066 DEBUG c-0000000000 << HTTP/1.1 200 Connection
established
2021-09-17 12:06:30,067 DEBUG ex-0000000001 consume response HTTP/1.1 200
Connection established, null entity
2021-09-17 12:06:30,067 DEBUG ex-0000000001 Authentication succeeded
2021-09-17 12:06:30,069 DEBUG ex-0000000001 Caching 'Basic' auth scheme for
http://localhost:8889
2021-09-17 12:06:30,078 DEBUG ex-0000000001 tunnel to target created
2021-09-17 12:06:30,078 DEBUG ep-0000000000 upgrading endpoint
2021-09-17 12:06:30,079 DEBUG c-0000000000 start TLS
2021-09-17 12:06:30,098 DEBUG ep-0000000000 upgraded c-0000000000
2021-09-17 12:06:30,098 DEBUG ex-0000000001 upgraded to TLS
2021-09-17 12:06:30,098 DEBUG ex-0000000001 route fully established
2021-09-17 12:06:30,098 DEBUG ex-0000000001 executing GET / HTTP/1.1
2021-09-17 12:06:30,098 DEBUG ep-0000000000 start execution ex-0000000001
2021-09-17 12:06:30,098 DEBUG ep-0000000000 executing exchange ex-0000000001
over c-0000000000
2021-09-17 12:06:30,098 DEBUG c-0000000000 RequestExecutionCommand with NORMAL
priority
2021-09-17 12:06:30,099 DEBUG
c-0000000000[ACTIVE][rw:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][0] Enqueued
RequestExecutionCommand with priority IMMEDIATE
2021-09-17 12:06:30,099 DEBUG c-0000000000 Connection is kept alive
2021-09-17 12:06:30,099 DEBUG
c-0000000000[ACTIVE][rw:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][0] Event set [r]
2021-09-17 12:06:30,101 DEBUG Enabled protocols: [TLSv1.2, TLSv1.1, TLSv1]
2021-09-17 12:06:30,101 DEBUG Enabled cipher
suites:[TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,
TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, 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_AES_256_CBC_SHA384,
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256,
TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384,
TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256,
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
TLS_DHE_DSS_WITH_AES_256_CBC_SHA, 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_EMPTY_RENEGOTIATION_INFO_SCSV]
2021-09-17 12:06:31,097 DEBUG Secure session established
2021-09-17 12:06:31,098 DEBUG negotiated protocol: TLSv1.2
2021-09-17 12:06:31,098 DEBUG negotiated cipher suite:
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
2021-09-17 12:06:31,099 DEBUG peer principal: CN=nghttp2.org
2021-09-17 12:06:31,100 DEBUG peer alternative names: [nghttp2.org,
www.nghttp2.org]
2021-09-17 12:06:31,100 DEBUG issuer principal: CN=R3, O=Let's Encrypt, C=US
2021-09-17 12:06:31,105 DEBUG
c-0000000000[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0] Event cleared [w]
2021-09-17 12:06:31,105 DEBUG ex-0000000001 send request GET / HTTP/1.1, null
entity
2021-09-17 12:06:31,106 DEBUG c-0000000000 >> GET / HTTP/1.1
2021-09-17 12:06:31,106 DEBUG c-0000000000 >> User-Agent:
Apache-HttpAsyncClient/5.1.1-SNAPSHOT (Java/1.8.0_282)
2021-09-17 12:06:31,106 DEBUG c-0000000000 >> Host: nghttp2.org
2021-09-17 12:06:31,107 DEBUG c-0000000000 >> Connection: keep-alive
2021-09-17 12:06:31,108 DEBUG
c-0000000000[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][158] 129 bytes
written
2021-09-17 12:06:31,109 DEBUG
c-0000000000[ACTIVE][rw:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][158] Event set [w]
2021-09-17 12:06:31,109 DEBUG
c-0000000000[ACTIVE][r:w][ACTIVE][r][NOT_HANDSHAKING][0][0][0] Event cleared [w]
2021-09-17 12:06:31,514 DEBUG
c-0000000000[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][1329][1300][0] 0 bytes
read
2021-09-17 12:06:31,515 DEBUG c-0000000000 << HTTP/1.1 200 OK
2021-09-17 12:06:31,516 DEBUG c-0000000000 << Date: Fri, 17 Sep 2021 10:06:32
GMT
2021-09-17 12:06:31,516 DEBUG c-0000000000 << Content-Type: text/html
2021-09-17 12:06:31,516 DEBUG c-0000000000 << Last-Modified: Sun, 18 Jul 2021
04:17:59 GMT
2021-09-17 12:06:31,516 DEBUG c-0000000000 << Etag: "60f3ab77-19d8"
2021-09-17 12:06:31,517 DEBUG c-0000000000 << Accept-Ranges: bytes
2021-09-17 12:06:31,517 DEBUG c-0000000000 << Content-Length: 6616
2021-09-17 12:06:31,517 DEBUG c-0000000000 << X-Backend-Header-Rtt: 0.001851
2021-09-17 12:06:31,518 DEBUG c-0000000000 << Strict-Transport-Security:
max-age=31536000
2021-09-17 12:06:31,518 DEBUG c-0000000000 << Alt-Svc: h3=":443"; ma=3600
2021-09-17 12:06:31,518 DEBUG c-0000000000 << Server: nghttpx
2021-09-17 12:06:31,518 DEBUG c-0000000000 << Via: 2 nghttpx
2021-09-17 12:06:31,518 DEBUG c-0000000000 << x-frame-options: SAMEORIGIN
2021-09-17 12:06:31,519 DEBUG c-0000000000 << x-xss-protection: 1; mode=block
2021-09-17 12:06:31,519 DEBUG c-0000000000 << x-content-type-options: nosniff
2021-09-17 12:06:31,520 DEBUG ex-0000000001 consume response HTTP/1.1 200 OK,
entity len 6616
2021-09-17 12:06:31,527 DEBUG ex-0000000001 consume response data, len 872 bytes
2021-09-17 12:06:31,532 DEBUG ex-0000000001 consume response data, len 1300
bytes
2021-09-17 12:06:31,533 DEBUG ex-0000000001 consume response data, len 1300
bytes
2021-09-17 12:06:31,534 DEBUG ex-0000000001 consume response data, len 1300
bytes
2021-09-17 12:06:31,535 DEBUG
c-0000000000[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][5316][0][0] 0 bytes read
2021-09-17 12:06:31,536 DEBUG ex-0000000001 consume response data, len 1300
bytes
2021-09-17 12:06:31,537 DEBUG ex-0000000001 consume response data, len 544 bytes
2021-09-17 12:06:31,537 DEBUG ex-0000000001 end of response data
Shutting down
GET https://nghttp2.org/->HTTP/1.1 200 OK
SimpleBody{content length=6616, content type=text/html}
2021-09-17 12:06:31,541 DEBUG ex-0000000001 message exchange successfully
completed
2021-09-17 12:06:31,541 DEBUG Shutdown GRACEFUL
2021-09-17 12:06:31,541 DEBUG ep-0000000000 releasing valid endpoint
2021-09-17 12:06:31,541 DEBUG ep-0000000000 releasing endpoint
2021-09-17 12:06:31,542 DEBUG ep-0000000000 connection c-0000000000 can be kept
alive for 3 MINUTES
2021-09-17 12:06:31,544 DEBUG ep-0000000000 connection released [route:
{tls}->http://localhost:8889->https://nghttp2.org:443][total available: 1;
route allocated: 1 of 5; total allocated: 1 of 25]
2021-09-17 12:06:31,544 DEBUG
c-0000000000[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][1902][544][0] Event set
[r]
2021-09-17 12:06:31,544 DEBUG c-0000000000 Connection is kept alive
2021-09-17 12:06:31,545 DEBUG
c-0000000000[ACTIVE][rw:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][0] Enqueued
ShutdownCommand with priority IMMEDIATE
2021-09-17 12:06:31,546 DEBUG
c-0000000000[ACTIVE][r:w][ACTIVE][r][NOT_HANDSHAKING][0][0][0] Event cleared [w]
2021-09-17 12:06:31,546 DEBUG
c-0000000000[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][0] Event set [w]
2021-09-17 12:06:31,547 DEBUG
c-0000000000[ACTIVE][r:w][ACTIVE][r][NOT_HANDSHAKING][0][0][0] Event cleared [w]
2021-09-17 12:06:31,547 DEBUG
c-0000000000[ACTIVE][r:w][ACTIVE][r][NOT_HANDSHAKING][0][0][0] Close GRACEFUL
2021-09-17 12:06:32,016 DEBUG Shutdown connection pool GRACEFUL
2021-09-17 12:06:32,017 DEBUG c-0000000000 Shutdown connection GRACEFUL
2021-09-17 12:06:32,017 DEBUG Connection pool shut down
{noformat}
> Unable to use HTTP Proxy with CloseableHttpAsyncClient
> ------------------------------------------------------
>
> Key: HTTPCLIENT-2177
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2177
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient (async)
> Affects Versions: 5.0, 5.1
> Environment: Windows 10.0.19041 Build 19041
> Java 11.0.11
> Gradle 6.8
> Reporter: Andrei Vasilev
> Priority: Minor
> Fix For: 5.1.1, 5.2-alpha1
>
> Attachments: auth-proxy-context-wire-HTTPCLIENT-2177.log,
> context-wire.log, unauth-proxy-context-wire-HTTPCLIENT-2177.log
>
>
> When executing a standard GET request with a configured proxy (authenticated
> or not) using an instance of CloseableHttpAsyncClient, the request fails with
> "IllegalStateException: No tunnel unless connected."
> Is making requests via proxies using an AsyncClient not supported? It is not
> entirely clear from the current release notes/examples.
> Minimal example to reproduce issue, although you will of course need to
> configure the proxy accordingly given your environment.
>
> {code:java}
> import java.util.concurrent.Future;
> import javax.net.ssl.SSLEngine;
> import javax.net.ssl.SSLSession;
> import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
> import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
> import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
> import org.apache.hc.client5.http.async.methods.SimpleRequestProducer;
> import org.apache.hc.client5.http.async.methods.SimpleResponseConsumer;
> import org.apache.hc.client5.http.config.RequestConfig;
> import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
> import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
> import
> org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
> import
> org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
> import org.apache.hc.client5.http.protocol.HttpClientContext;
> import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder;
> import org.apache.hc.core5.concurrent.FutureCallback;
> import org.apache.hc.core5.function.Factory;
> import org.apache.hc.core5.http.HttpHost;
> import org.apache.hc.core5.http.message.StatusLine;
> import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
> import org.apache.hc.core5.http2.HttpVersionPolicy;
> import org.apache.hc.core5.io.CloseMode;
> import org.apache.hc.core5.reactor.ssl.TlsDetails;
> public class AsyncMain {
> public static void main(final String[] args) throws Exception {
> final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create()
> .useSystemProperties()
> .setTlsDetailsFactory(new Factory<SSLEngine, TlsDetails>() {
> @Override
> public TlsDetails create(final SSLEngine sslEngine) {
> return new TlsDetails(sslEngine.getSession(),
> sslEngine.getApplicationProtocol());
> }
> }).build();
> final PoolingAsyncClientConnectionManager cm =
> PoolingAsyncClientConnectionManagerBuilder.create()
> .setTlsStrategy(tlsStrategy)
> .build();
> try (final CloseableHttpAsyncClient client = HttpAsyncClients.custom()
> .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
> .setConnectionManager(cm)
> .build()) {
> client.start();
> final HttpClientContext clientContext = HttpClientContext.create();
> final HttpHost target = new HttpHost("https", "nghttp2.org");
> final HttpHost proxy = new HttpHost("127.0.0.1", 8888);
> final RequestConfig config =
> RequestConfig.custom().setProxy(proxy).build();
> final SimpleHttpRequest request = SimpleRequestBuilder.get()
> .setHttpHost(target)
> .setRequestConfig(config)
> .setPath("/httpbin/")
> .build();
> System.out.println("Executing request " + request);
> final Future<SimpleHttpResponse> future = client.execute(
> SimpleRequestProducer.create(request),
> SimpleResponseConsumer.create(),
> clientContext,
> new FutureCallback<SimpleHttpResponse>() {
> @Override
> public void completed(final SimpleHttpResponse response) {
> System.out.println(request + "->" + new StatusLine(response));
> final SSLSession sslSession = clientContext.getSSLSession();
> if (sslSession != null) {
> System.out.println("SSL protocol " +
> sslSession.getProtocol());
> System.out.println("SSL cipher suite " +
> sslSession.getCipherSuite());
> }
> System.out.println(response.getBody());
> }
> @Override
> public void failed(final Exception ex) {
> System.out.println(request + "->" + ex);
> }
> @Override
> public void cancelled() {
> System.out.println(request + " cancelled");
> }
> });
> future.get();
> System.out.println("Shutting down");
> client.close(CloseMode.GRACEFUL);
> }
> }
> }
> {code}
>
> The resulting stack trace :
> {code:java}
> Exception in thread "main" java.util.concurrent.ExecutionException:
> java.lang.IllegalStateException: No tunnel unless connected at
> org.apache.hc.core5.concurrent.BasicFuture.getResult(BasicFuture.java:72) at
> org.apache.hc.core5.concurrent.BasicFuture.get(BasicFuture.java:85) at
> AsyncMain.main(AsyncMain.java:86)Caused by: java.lang.IllegalStateException:
> No tunnel unless connected at
> org.apache.hc.core5.util.Asserts.check(Asserts.java:38) at
> org.apache.hc.client5.http.RouteTracker.tunnelTarget(RouteTracker.java:143)
> at
> org.apache.hc.client5.http.impl.async.AsyncConnectExec$4.completed(AsyncConnectExec.java:270)
> at
> org.apache.hc.client5.http.impl.async.AsyncConnectExec$5.completed(AsyncConnectExec.java:388)
> at
> org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.consumeResponse(HttpAsyncMainClientExec.java:206)
> at
> org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.consumeHeader(ClientHttp1StreamHandler.java:253)
> at
> org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.consumeHeader(ClientHttp1StreamDuplexer.java:348)
> at
> org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.consumeHeader(ClientHttp1StreamDuplexer.java:80)Caused
> by: java.lang.IllegalStateException: No tunnel unless connected
> at
> org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onInput(AbstractHttp1StreamDuplexer.java:288)
> at
> org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.inputReady(AbstractHttp1IOEventHandler.java:64)
> at
> org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.inputReady(ClientHttp1IOEventHandler.java:39)
> at
> org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:131)
> at
> org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
> at
> org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)
> at
> org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)
> at
> org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:85)
> at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
> at java.base/java.lang.Thread.run(Thread.java:829)
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]