From 14cdb60d0301f7b54f2b95d21eb1be0224129942 Mon Sep 17 00:00:00 2001 From: Laura Trotta Date: Tue, 3 Jun 2025 16:07:01 +0200 Subject: [PATCH 1/2] added more configs in rest5builder --- .../low_level/Rest5ClientBuilder.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Rest5ClientBuilder.java b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Rest5ClientBuilder.java index 4df40f375..e9feb0ac7 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Rest5ClientBuilder.java +++ b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Rest5ClientBuilder.java @@ -20,6 +20,7 @@ package co.elastic.clients.transport.rest5_client.low_level; +import org.apache.hc.client5.http.auth.CredentialsProvider; import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy; @@ -27,7 +28,9 @@ import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder; import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager; import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder; +import org.apache.hc.client5.http.routing.HttpRoutePlanner; import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy; import org.apache.hc.core5.util.Timeout; import org.apache.hc.core5.util.VersionInfo; @@ -35,6 +38,7 @@ import javax.net.ssl.SSLContext; import java.io.IOException; import java.io.InputStream; +import java.net.ProxySelector; import java.security.NoSuchAlgorithmException; import java.util.List; import java.util.Locale; @@ -75,6 +79,9 @@ public final class Rest5ClientBuilder { private Header[] defaultHeaders = EMPTY_HEADERS; private Rest5Client.FailureListener failureListener; private SSLContext sslContext; + private HttpHost proxy; + private ProxySelector proxySelector; + private HttpRoutePlanner routePlanner; private String pathPrefix; private NodeSelector nodeSelector = NodeSelector.ANY; private boolean strictDeprecationMode = false; @@ -180,6 +187,24 @@ public Rest5ClientBuilder setSSLContext(SSLContext sslContext) { return this; } + public Rest5ClientBuilder setProxy(HttpHost proxy) { + Objects.requireNonNull(proxy, "proxy must not be null"); + this.proxy = proxy; + return this; + } + + public Rest5ClientBuilder setProxySelector(ProxySelector proxySelector) { + Objects.requireNonNull(proxySelector, "proxy selector must not be null"); + this.proxySelector = proxySelector; + return this; + } + + public Rest5ClientBuilder setRoutePlanner(HttpRoutePlanner routePlanner) { + Objects.requireNonNull(routePlanner, "route planner must not be null"); + this.routePlanner = routePlanner; + return this; + } + /** * Sets the default request headers, which will be sent along with each request. *

@@ -374,6 +399,16 @@ private CloseableHttpAsyncClient createHttpClient() { .setTargetAuthenticationStrategy(new DefaultAuthenticationStrategy()) .setThreadFactory(new RestClientThreadFactory()); + if (this.proxy != null) { + httpClientBuilder.setProxy(this.proxy); + } + if (this.proxySelector != null) { + httpClientBuilder.setProxySelector(this.proxySelector); + } + if (this.routePlanner != null) { + httpClientBuilder.setRoutePlanner(this.routePlanner); + } + return httpClientBuilder.build(); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("could not create the default ssl context", e); From 0b13d8448e23c2ca0a3a968fc6797d83cc9b21e0 Mon Sep 17 00:00:00 2001 From: Laura Trotta Date: Tue, 3 Jun 2025 16:09:22 +0200 Subject: [PATCH 2/2] cleanup --- .../transport/rest5_client/low_level/Rest5ClientBuilder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Rest5ClientBuilder.java b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Rest5ClientBuilder.java index e9feb0ac7..b4d5f573e 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Rest5ClientBuilder.java +++ b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Rest5ClientBuilder.java @@ -20,7 +20,6 @@ package co.elastic.clients.transport.rest5_client.low_level; -import org.apache.hc.client5.http.auth.CredentialsProvider; import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy;