Skip to content

Commit 58f6bf9

Browse files
Added more setters in Rest5Builder (#1019) (#1020)
* added more configs in rest5builder * cleanup Co-authored-by: Laura Trotta <153528055+l-trotta@users.noreply.github.com>
1 parent 0411577 commit 58f6bf9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/Rest5ClientBuilder.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@
2727
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
2828
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
2929
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
30+
import org.apache.hc.client5.http.routing.HttpRoutePlanner;
3031
import org.apache.hc.core5.http.Header;
32+
import org.apache.hc.core5.http.HttpHost;
3133
import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
3234
import org.apache.hc.core5.util.Timeout;
3335
import org.apache.hc.core5.util.VersionInfo;
3436

3537
import javax.net.ssl.SSLContext;
3638
import java.io.IOException;
3739
import java.io.InputStream;
40+
import java.net.ProxySelector;
3841
import java.security.NoSuchAlgorithmException;
3942
import java.util.List;
4043
import java.util.Locale;
@@ -75,6 +78,9 @@ public final class Rest5ClientBuilder {
7578
private Header[] defaultHeaders = EMPTY_HEADERS;
7679
private Rest5Client.FailureListener failureListener;
7780
private SSLContext sslContext;
81+
private HttpHost proxy;
82+
private ProxySelector proxySelector;
83+
private HttpRoutePlanner routePlanner;
7884
private String pathPrefix;
7985
private NodeSelector nodeSelector = NodeSelector.ANY;
8086
private boolean strictDeprecationMode = false;
@@ -180,6 +186,24 @@ public Rest5ClientBuilder setSSLContext(SSLContext sslContext) {
180186
return this;
181187
}
182188

189+
public Rest5ClientBuilder setProxy(HttpHost proxy) {
190+
Objects.requireNonNull(proxy, "proxy must not be null");
191+
this.proxy = proxy;
192+
return this;
193+
}
194+
195+
public Rest5ClientBuilder setProxySelector(ProxySelector proxySelector) {
196+
Objects.requireNonNull(proxySelector, "proxy selector must not be null");
197+
this.proxySelector = proxySelector;
198+
return this;
199+
}
200+
201+
public Rest5ClientBuilder setRoutePlanner(HttpRoutePlanner routePlanner) {
202+
Objects.requireNonNull(routePlanner, "route planner must not be null");
203+
this.routePlanner = routePlanner;
204+
return this;
205+
}
206+
183207
/**
184208
* Sets the default request headers, which will be sent along with each request.
185209
* <p>
@@ -374,6 +398,16 @@ private CloseableHttpAsyncClient createHttpClient() {
374398
.setTargetAuthenticationStrategy(new DefaultAuthenticationStrategy())
375399
.setThreadFactory(new RestClientThreadFactory());
376400

401+
if (this.proxy != null) {
402+
httpClientBuilder.setProxy(this.proxy);
403+
}
404+
if (this.proxySelector != null) {
405+
httpClientBuilder.setProxySelector(this.proxySelector);
406+
}
407+
if (this.routePlanner != null) {
408+
httpClientBuilder.setRoutePlanner(this.routePlanner);
409+
}
410+
377411
return httpClientBuilder.build();
378412
} catch (NoSuchAlgorithmException e) {
379413
throw new IllegalStateException("could not create the default ssl context", e);

0 commit comments

Comments
 (0)