--------------------------------------
/**
* Create the pooled asynchronous http client.
*
* @param config configuration for the http client
* @return asynchronous http client
* @since 3.0 (changed parameter to Configuration)
*/
public static CloseableHttpAsyncClient
createClient(Configuration
config) {
int connectionIdleSecs =
config.getTimeAsInt(Proxy2Config.HTTP_CONNECTION_IDLE_TIMEOUT,
TimeUnit.SECONDS);
final CloseableHttpAsyncClient client =
HttpAsyncClientBuilder.create()
.disableCookieManagement()
.setDefaultRequestConfig(createCustomRequestConfig(config))
.setConnectionManager(createPoolingConnManager(config))
.setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
.setIOReactorConfig(
IOReactorConfig.custom().setSoTimeout(Timeout.ofSeconds(connectionIdl
eSecs)).build())
.addRequestInterceptorFirst(new RequestDate())
.setKeepAliveStrategy(new
DefaultConnectionKeepAliveStrategy() {
@Override
public TimeValue
getKeepAliveDuration(HttpResponse
response, HttpContext context) {
TimeValue keepAlive =
super.getKeepAliveDuration(response, context);
if (keepAlive == null ||
keepAlive.getDuration() < 0) {
// Keep connections alive if a keep-
alive value
// has not be explicitly set by the
server
keepAlive = KEEP_ALIVE;
}
return keepAlive;
}
}).build();
client.start();
return client;
}
/**
* Create the http request-config.
*
* @param config configuration for the http client
* @return http request-config
* @since 3.0 (changed parameter to Configuration)
*/
private static RequestConfig
createCustomRequestConfig(Configuration config) {
long connecTimeoutMillis =
config.get(Proxy2Config.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS);
return
RequestConfig.custom().setConnectionRequestTimeout(Timeout.ofMillisec
onds(connecTimeoutMillis
* 4))
.setConnectTimeout(Timeout.ofMilliseconds(connecTimeoutMillis)).build
();
}
/**
* Create pooling connection Manager.
*
* @param config configuration for the http client
* @return pooling connection Manager
* @since 3.0 (changed parameter to Configuration)
*/
private static PoolingAsyncClientConnectionManager
createPoolingConnManager(Configuration config) {
long connectionIdleSecs =
config.get(Proxy2Config.HTTP_CONNECTION_IDLE_TIMEOUT,
TimeUnit.MILLISECONDS);
return PoolingAsyncClientConnectionManagerBuilder.create()
.setPoolConcurrencyPolicy(PoolConcurrencyPolicy.STRICT).setConnPoolPo
licy(PoolReusePolicy.LIFO)
.setConnectionTimeToLive(TimeValue.ofSeconds(connectionIdleSecs)).set
MaxConnTotal(250)
.setMaxConnPerRoute(50).build();
}
--------------------------------------
fails on https requests.
Using HttpVersionPolicy.FORCE_HTTP_1 it works. Using it with http it
works.
best regards
Achim
Logs:
11:31:53.827 DEBUG [ProxyHttpClientResource]: Outgoing http request:
GET
/impressum HTTP/1.1
11:31:53.827 DEBUG [InternalAbstractHttpAsyncClient]: ex-0000000002
preparing request execution
11:31:53.827 DEBUG [RequestAuthCache]: ex-0000000002 Auth cache not
set
in the context
11:31:53.828 DEBUG [AsyncProtocolExec]: ex-0000000002 target auth
state:
UNCHALLENGED
11:31:53.828 DEBUG [AsyncProtocolExec]: ex-0000000002 proxy auth
state:
UNCHALLENGED
11:31:53.828 DEBUG [AsyncConnectExec]: ex-0000000002 acquiring
connection with route {s}->https://cloudcoap.net:443
11:31:53.828 DEBUG [InternalHttpAsyncClient]: ex-0000000002 acquiring
endpoint (60000 MILLISECONDS)
11:31:53.828 DEBUG [PoolingAsyncClientConnectionManager]: ex-
0000000002
endpoint lease request (60000 MILLISECONDS) [route:
{s}->https://cloudcoap.net:443][total available: 0; route allocated:
0
of 50; total allocated: 0 of 250]
11:31:53.828 DEBUG [PoolingAsyncClientConnectionManager]: ex-
0000000002
endpoint leased [route: {s}-
https://cloudcoap.net:443][total available:
0; route allocated: 1 of 50; total allocated: 1 of 250]
11:31:53.829 DEBUG [PoolingAsyncClientConnectionManager]: ex-
0000000002
acquired ep-0000000001
11:31:53.829 DEBUG [InternalHttpAsyncClient]: ex-0000000002 acquired
endpoint ep-0000000001
11:31:53.829 DEBUG [InternalHttpAsyncClient]: ep-0000000001
connecting
endpoint (15000 MILLISECONDS)
11:31:53.829 DEBUG [PoolingAsyncClientConnectionManager]: ep-
0000000001
connecting endpoint to https://cloudcoap.net:443 (15000 MILLISECONDS)
11:31:53.829 DEBUG [MultihomeIOSessionRequester]:
https://cloudcoap.net:443 resolving remote address
11:31:53.830 DEBUG [MultihomeIOSessionRequester]:
https://cloudcoap.net:443 resolved to [cloudcoap.net/81.169.145.163,
cloudcoap.net/2a01:238:20a:202:1163:0:0:0]
11:31:53.830 DEBUG [MultihomeIOSessionRequester]:
https://cloudcoap.net:443 connecting null to
cloudcoap.net/81.169.145.163:443 (15000 MILLISECONDS)
11:31:53.848 DEBUG [IOSessionImpl]: c-0000000001[ACTIVE][rc:c]
protocol
upgrade class
org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiator
11:31:53.848 DEBUG [MultihomeIOSessionRequester]:
https://cloudcoap.net:443 connected c-0000000001
/192.168.178.10:33848->cloudcoap.net/81.169.145.163:443
11:31:53.848 DEBUG [DefaultManagedAsyncClientConnection]: c-
0000000001
start TLS
11:31:53.849 DEBUG [PoolingAsyncClientConnectionManager]: ep-
0000000001
connected c-0000000001
11:31:53.849 DEBUG [InternalHttpAsyncClient]: ep-0000000001 endpoint
connected
11:31:53.849 DEBUG [AsyncConnectExec]: ex-0000000002 connected to
target
11:31:53.849 DEBUG [AsyncConnectExec]: ex-0000000002 route fully
established
11:31:53.849 DEBUG [HttpAsyncMainClientExec]: ex-0000000002 executing
GET /impressum HTTP/1.1
11:31:53.849 DEBUG [InternalHttpAsyncClient]: ep-0000000001 start
execution ex-0000000002
11:31:53.849 DEBUG [PoolingAsyncClientConnectionManager]: ep-
0000000001
executing exchange ex-0000000002 over c-0000000001
11:31:53.849 DEBUG [DefaultManagedAsyncClientConnection]: c-
0000000001
RequestExecutionCommand with NORMAL priority
11:31:53.849 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][rwc:c][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
Enqueued RequestExecutionCommand with priority IMMEDIATE
11:31:53.849 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][rw:c][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
Event
cleared [c]
11:31:53.850 DEBUG [AbstractClientTlsStrategy]: Enabled protocols:
[TLSv1.3, TLSv1.2]
11:31:53.850 DEBUG [AbstractClientTlsStrategy]: Enabled cipher
suites:[TLS_AES_256_GCM_SHA384, TLS_AES_128_GCM_SHA256,
TLS_CHACHA20_POLY1305_SHA256,
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
TLS_DHE_DSS_WITH_AES_256_GCM_SHA384,
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_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,
TLS_DHE_DSS_WITH_AES_256_CBC_SHA256,
TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,
TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,
TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,
TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,
TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,
TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,
TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384,
TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384,
TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256,
TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256,
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
TLS_DHE_DSS_WITH_AES_128_CBC_SHA,
TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
TLS_ECDH_RSA_WITH_AES_256_CBC_SHA,
TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_GCM_SHA384,
TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
TLS_RSA_WITH_AES_128_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
11:31:53.894 DEBUG [AbstractClientTlsStrategy]: Secure session
established
11:31:53.894 DEBUG [AbstractClientTlsStrategy]: negotiated protocol:
TLSv1.3
11:31:53.894 DEBUG [AbstractClientTlsStrategy]: negotiated cipher
suite: TLS_AES_256_GCM_SHA384
11:31:53.894 DEBUG [AbstractClientTlsStrategy]: peer principal:
CN=cloudcoap.net
11:31:53.894 DEBUG [AbstractClientTlsStrategy]: peer alternative
names:
[cloudcoap.net, www.cloudcoap.net]
11:31:53.894 DEBUG [AbstractClientTlsStrategy]: issuer principal:
CN=Encryption Everywhere DV TLS CA - G1, OU=www.digicert.com,
O=DigiCert
Inc, C=US
11:31:53.895 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][r:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][90]
protocol upgrade class
org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler
11:31:53.895 DEBUG [HttpAsyncMainClientExec]: ex-0000000002 send
request
GET /impressum HTTP/1.1, null entity
11:31:53.895 DEBUG [headers]: c-0000000001 >> GET /impressum HTTP/1.1
11:31:53.895 DEBUG [headers]: c-0000000001 >> User-Agent:
Apache-HttpAsyncClient/5.1.3 (Java/17.0.4)
11:31:53.895 DEBUG [headers]: c-0000000001 >> Host: cloudcoap.net
11:31:53.895 DEBUG [headers]: c-0000000001 >> Connection: keep-alive
11:31:53.895 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][r:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][90] 0
bytes
written
11:31:53.895 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][rw:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][90]
Event
set [w]
11:31:53.895 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][rw:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][90] 0
bytes written
11:31:53.896 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][166]
128
bytes written
11:31:53.896 DEBUG [wire]:
c-0000000001[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][166] >>
GET /impressum H 47 45 54 20 2f 69 6d 70 72 65 73 73 75 6d 20 48
11:31:53.896 DEBUG [wire]:
c-0000000001[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][166] >>
TTP/1.1 User-Ag 54 54 50 2f 31 2e 31 0d 0a 55 73 65 72 2d 41 67
11:31:53.896 DEBUG [wire]:
c-0000000001[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][166] >>
ent: Apache-Http 65 6e 74 3a 20 41 70 61 63 68 65 2d 48 74 74 70
11:31:53.896 DEBUG [wire]:
c-0000000001[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][166] >>
AsyncClient/5.1. 41 73 79 6e 63 43 6c 69 65 6e 74 2f 35 2e 31 2e
11:31:53.896 DEBUG [wire]:
c-0000000001[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][166] >>
3
(Java/17.0.4) 33 20 28 4a 61 76 61 2f 31 37 2e 30 2e 34 29 0d
11:31:53.896 DEBUG [wire]:
c-0000000001[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][166]
Host: cloudcoap 0a 48 6f 73 74 3a 20 63 6c 6f 75 64 63 6f 61 70
11:31:53.896 DEBUG [wire]:
c-0000000001[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][166] >>
.net Connection 2e 6e 65 74 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e
11:31:53.896 DEBUG [wire]:
c-0000000001[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][166] >>
:
keep-alive 3a 20 6b 65 65 70 2d 61 6c 69 76 65 0d 0a 0d 0a
11:31:53.896 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][rw:w][ACTIVE][r][NOT_HANDSHAKING][0][0][166]
Event
cleared [w]
11:31:53.911 DEBUG [wire]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][656][0][0] <<
..............d. 00 00 06 04 00 00 00 00 00 00 03 00 00 00 64 00
11:31:53.912 DEBUG [wire]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][656][0][0] <<
........... 00 04 08 00 00 00 00 00 7f ff 00 00
11:31:53.912 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][656][28][0] 0
bytes read
11:31:53.915 DEBUG [wire]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][76][0][0] <<
..-............. 00 00 2d 07 00 00 00 00 00 00 00 00 00 ff ff fc
11:31:53.915 DEBUG [wire]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][76][0][0] <<
yReceived bad cl 79 52 65 63 65 69 76 65 64 20 62 61 64 20 63 6c
11:31:53.915 DEBUG [wire]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][76][0][0] <<
ient
magic byte 69 65 6e 74 20 6d 61 67 69 63 20 62 79 74 65 20
11:31:53.915 DEBUG [wire]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][76][0][0] <<
string 73 74 72 69 6e 67
11:31:53.915 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][76][54][0] 0
bytes
read
11:31:53.916 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][inbound
done][][EOF][][0][0][0] -1 bytes read
11:31:53.916 DEBUG [HttpAsyncMainClientExec]: ex-0000000002 execution
failed: Invalid protocol version; error at offset 0:
<[0x2e][0x2f][0x30][0x31][0x32][0x33][0x34][0x35][0x36][0x37][0x38][0
x39][0x3a][0x3b]d[0x3d][0x3e][0x3f][0x40][0x41][0x42][0x43][0x44][0x4
5]ÿ[0x48][0x49][0x4a][0x4b]-
[0x4d][0x4e][0x4f][0x50][0x51][0x52][0x53][0x54][0x55][0x56]ÿÿüyRecei
ved
bad client magic byte string>
11:31:53.916 DEBUG [InternalAbstractHttpAsyncClient]: ex-0000000002
request failed: Invalid protocol version; error at offset 0:
<[0x2e][0x2f][0x30][0x31][0x32][0x33][0x34][0x35][0x36][0x37][0x38][0
x39][0x3a][0x3b]d[0x3d][0x3e][0x3f][0x40][0x41][0x42][0x43][0x44][0x4
5]ÿ[0x48][0x49][0x4a][0x4b]-
[0x4d][0x4e][0x4f][0x50][0x51][0x52][0x53][0x54][0x55][0x56]ÿÿüyRecei
ved
bad client magic byte string>
11:31:53.916 DEBUG [PoolingAsyncClientConnectionManager]: ep-
0000000001
close IMMEDIATE
11:31:53.916 DEBUG [DefaultManagedAsyncClientConnection]: c-
0000000001
Shutdown connection IMMEDIATE
11:31:53.917 DEBUG [SSLIOSession]:
c-0000000001[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][inbound
done][][EOF][][0][0][0] Close IMMEDIATE
11:31:53.917 DEBUG [InternalHttpAsyncClient]: ep-0000000001 endpoint
closed
11:31:53.917 DEBUG [InternalHttpAsyncClient]: ep-0000000001
discarding
endpoint
11:31:53.917 DEBUG [PoolingAsyncClientConnectionManager]: ep-
0000000001
releasing endpoint
11:31:53.917 DEBUG [PoolingAsyncClientConnectionManager]: ep-
0000000001
connection released [route: {s}->https://cloudcoap.net:443][total
available: 0; route allocated: 0 of 50; total allocated: 0 of 250]
11:31:53.917 DEBUG [ProxyHttpClientResource]: Failed to get the http
response: Invalid protocol version; error at offset 0:
<[0x2e][0x2f][0x30][0x31][0x32][0x33][0x34][0x35][0x36][0x37][0x38][0
x39][0x3a][0x3b]d[0x3d][0x3e][0x3f][0x40][0x41][0x42][0x43][0x44][0x4
5]ÿ[0x48][0x49][0x4a][0x4b]-
[0x4d][0x4e][0x4f][0x50][0x51][0x52][0x53][0x54][0x55][0x56]ÿÿüyRecei
ved
bad client magic byte string>
org.apache.hc.core5.http.ParseException: Invalid protocol version;
error
at offset 0:
<[0x2e][0x2f][0x30][0x31][0x32][0x33][0x34][0x35][0x36][0x37][0x38][0
x39][0x3a][0x3b]d[0x3d][0x3e][0x3f][0x40][0x41][0x42][0x43][0x44][0x4
5]ÿ[0x48][0x49][0x4a][0x4b]-
[0x4d][0x4e][0x4f][0x50][0x51][0x52][0x53][0x54][0x55][0x56]ÿÿüyRecei
ved
bad client magic byte string>
at
org.apache.hc.core5.http.message.BasicLineParser.parseProtocolVersion
(BasicLineParser.java:110)
at
org.apache.hc.core5.http.message.BasicLineParser.parseStatusLine(Basi
cLineParser.java:181)
at
org.apache.hc.core5.http.impl.nio.DefaultHttpResponseParser.createMes
sage(DefaultHttpResponseParser.java:83)
at
org.apache.hc.core5.http.impl.nio.DefaultHttpResponseParser.createMes
sage(DefaultHttpResponseParser.java:44)
at
org.apache.hc.core5.http.impl.nio.AbstractMessageParser.parseHeadLine
(AbstractMessageParser.java:115)
at
org.apache.hc.core5.http.impl.nio.AbstractMessageParser.parse(Abstrac
tMessageParser.java:167)
at
org.apache.hc.core5.http.impl.nio.AbstractMessageParser.parse(Abstrac
tMessageParser.java:51)
at
org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.parseMe
ssageHead(AbstractHttp1StreamDuplexer.java:256)
at
org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onInput
(AbstractHttp1StreamDuplexer.java:285)
at
org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.inputRe
ady(AbstractHttp1IOEventHandler.java:64)
at
org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.inputRead
y(ClientHttp1IOEventHandler.java:39)
at
org.apache.hc.client5.http.impl.async.LoggingIOSession$1.inputReady(L
oggingIOSession.java:238)
at
org.apache.hc.core5.reactor.ssl.SSLIOSession.decryptData(SSLIOSession
.java:574)
at
org.apache.hc.core5.reactor.ssl.SSLIOSession.access$400(SSLIOSession.
java:72)
at
org.apache.hc.core5.reactor.ssl.SSLIOSession$1.inputReady(SSLIOSessio
n.java:172)
at
org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDat
aChannel.java:131)
at
org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalCha
nnel.java:51)
at
org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleC
oreIOReactor.java:178)
at
org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreI
OReactor.java:127)
at
org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(Abstr
actSingleCoreIOReactor.java:85)
at
org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:
44)
at java.base/java.lang.Thread.run(Thread.java:833)