diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-05 06:52:15 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-25 10:48:48 +0100 |
commit | f8338e1ea64c58a7986f929a4c3c229b92a8cfde (patch) | |
tree | 5d8fc4e174b281e32d06d16977fe70b039aff82e /vespa-feed-client/src/main | |
parent | dd05e4b94d67b481c241cfa20ccf0e481dcb0bd7 (diff) |
Avoid deprecated RequestConfig.setConnectTimeout
Diffstat (limited to 'vespa-feed-client/src/main')
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java index 3192bb4f225..a097c01b76b 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java @@ -5,6 +5,7 @@ import ai.vespa.feed.client.FeedClientBuilder.Compression; import ai.vespa.feed.client.HttpResponse; import org.apache.hc.client5.http.async.methods.SimpleHttpRequest; import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; +import org.apache.hc.client5.http.config.ConnectionConfig; 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; @@ -58,9 +59,10 @@ class ApacheCluster implements Cluster { private final ScheduledExecutorService timeoutExecutor = Executors.newSingleThreadScheduledExecutor(t -> new Thread(t, "request-timeout-thread")); ApacheCluster(FeedClientBuilderImpl builder) throws IOException { + ConnectionConfig connectionConfig = createConnectionConfig(); for (int i = 0; i < builder.connectionsPerEndpoint; i++) for (URI endpoint : builder.endpoints) - endpoints.add(new Endpoint(createHttpClient(builder), endpoint)); + endpoints.add(new Endpoint(createHttpClient(builder, connectionConfig), endpoint)); this.requestConfig = createRequestConfig(builder); this.compression = builder.compression; } @@ -160,7 +162,7 @@ class ApacheCluster implements Cluster { } @SuppressWarnings("deprecation") - private static CloseableHttpAsyncClient createHttpClient(FeedClientBuilderImpl builder) throws IOException { + private static CloseableHttpAsyncClient createHttpClient(FeedClientBuilderImpl builder, ConnectionConfig connectionConfig) throws IOException { SSLContext sslContext = builder.constructSslContext(); String[] allowedCiphers = excludeH2Blacklisted(excludeWeak(sslContext.getSupportedSSLParameters().getCipherSuites())); if (allowedCiphers.length == 0) @@ -173,7 +175,7 @@ class ApacheCluster implements Cluster { if (builder.hostnameVerifier != null) tlsStrategyBuilder.setHostnameVerifier(builder.hostnameVerifier); - return HttpAsyncClients.createHttp2Minimal(H2Config.custom() + var client = HttpAsyncClients.createHttp2Minimal(H2Config.custom() .setMaxConcurrentStreams(builder.maxStreamsPerConnection) .setCompressionEnabled(true) .setPushEnabled(false) @@ -185,6 +187,8 @@ class ApacheCluster implements Cluster { .setSoTimeout(Timeout.ofSeconds(10)) .build(), tlsStrategyBuilder.build()); + client.setConnectionConfigResolver(host -> connectionConfig); + return client; } private static int portOf(URI url) { @@ -192,13 +196,19 @@ class ApacheCluster implements Cluster { : url.getPort(); } + private static ConnectionConfig createConnectionConfig() { + return ConnectionConfig.custom() + .setConnectTimeout(Timeout.ofSeconds(10)).build(); + } + @SuppressWarnings("deprecation") private static RequestConfig createRequestConfig(FeedClientBuilderImpl b) { RequestConfig.Builder builder = RequestConfig.custom() - .setConnectTimeout(Timeout.ofSeconds(10)) .setConnectionRequestTimeout(Timeout.DISABLED) .setResponseTimeout(Timeout.ofSeconds(190)); - if (b.proxy != null) builder.setProxy(new HttpHost(b.proxy.getScheme(), b.proxy.getHost(), b.proxy.getPort())); + if (b.proxy != null) { + builder.setProxy(new HttpHost(b.proxy.getScheme(), b.proxy.getHost(), b.proxy.getPort())); + } return builder.build(); } |