From a43ceb895b607e223b009a6cb226cc62f5048cf9 Mon Sep 17 00:00:00 2001 From: Laura Trotta <153528055+l-trotta@users.noreply.github.com> Date: Tue, 3 Jun 2025 16:31:03 +0200 Subject: [PATCH] Added more setters in Rest5Builder (#1019) * added more configs in rest5builder * cleanup --- .../low_level/Rest5ClientBuilder.java | 34 +++++++++++++++++++ 1 file changed, 34 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..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 @@ -27,7 +27,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 +37,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 +78,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 +186,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 +398,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);