Skip to content

Commit d43a15b

Browse files
committed
Do not use system properties when building the HttpAsyncClient (#27829)
This commit removes the usage of system properties for the HttpAsyncClient as this overrides some defaults that we intentionally change. In order to set the default SSLContext to the system context we set the SSLContext on the builder explicitly. Closes #27827
1 parent d05347b commit d43a15b

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
2929
import org.apache.http.nio.conn.SchemeIOSessionStrategy;
3030

31+
import javax.net.ssl.SSLContext;
3132
import java.security.AccessController;
33+
import java.security.NoSuchAlgorithmException;
3234
import java.security.PrivilegedAction;
3335
import java.util.Objects;
3436

@@ -200,20 +202,25 @@ private CloseableHttpAsyncClient createHttpClient() {
200202
requestConfigBuilder = requestConfigCallback.customizeRequestConfig(requestConfigBuilder);
201203
}
202204

203-
HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create().setDefaultRequestConfig(requestConfigBuilder.build())
205+
try {
206+
HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create().setDefaultRequestConfig(requestConfigBuilder.build())
204207
//default settings for connection pooling may be too constraining
205-
.setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE).setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL).useSystemProperties();
206-
if (httpClientConfigCallback != null) {
207-
httpClientBuilder = httpClientConfigCallback.customizeHttpClient(httpClientBuilder);
208-
}
209-
210-
final HttpAsyncClientBuilder finalBuilder = httpClientBuilder;
211-
return AccessController.doPrivileged(new PrivilegedAction<CloseableHttpAsyncClient>() {
212-
@Override
213-
public CloseableHttpAsyncClient run() {
214-
return finalBuilder.build();
208+
.setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE).setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL)
209+
.setSSLContext(SSLContext.getDefault());
210+
if (httpClientConfigCallback != null) {
211+
httpClientBuilder = httpClientConfigCallback.customizeHttpClient(httpClientBuilder);
215212
}
216-
});
213+
214+
final HttpAsyncClientBuilder finalBuilder = httpClientBuilder;
215+
return AccessController.doPrivileged(new PrivilegedAction<CloseableHttpAsyncClient>() {
216+
@Override
217+
public CloseableHttpAsyncClient run() {
218+
return finalBuilder.build();
219+
}
220+
});
221+
} catch (NoSuchAlgorithmException e) {
222+
throw new IllegalStateException("could not create the default ssl context", e);
223+
}
217224
}
218225

219226
/**

0 commit comments

Comments
 (0)