Skip to content

Commit

Permalink
Issue splunk#117 - Added overridable method customize HttpAsyncClient…
Browse files Browse the repository at this point in the history
…Builder
  • Loading branch information
Kris Fudalewski authored and Kris Fudalewski committed Jul 10, 2019
1 parent d37f07b commit 4aea68f
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -28,6 +28,7 @@
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.util.EntityUtils;

Expand Down Expand Up @@ -290,7 +291,7 @@ private void startHttpClient() {
int maxConnTotal = sendMode == SendMode.Sequential ? 1 : 0;
if (! disableCertificateValidation) {
// create an http client that validates certificates
httpClient = HttpAsyncClients.custom()
httpClient = newHttpClientBuilder()
.setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build())
.setMaxConnTotal(maxConnTotal)
.build();
Expand All @@ -306,7 +307,7 @@ public boolean isTrusted(X509Certificate[] certificate,
try {
sslContext = SSLContexts.custom().loadTrustMaterial(
null, acceptingTrustStrategy).build();
httpClient = HttpAsyncClients.custom()
httpClient = newHttpClientBuilder()
.setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build())
.setMaxConnTotal(maxConnTotal)
.setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
Expand All @@ -317,6 +318,10 @@ public boolean isTrusted(X509Certificate[] certificate,
httpClient.start();
}

protected HttpAsyncClientBuilder newHttpClientBuilder() {
return HttpAsyncClients.custom();
}

// Currently we never close http client. This method is added for symmetry
// with startHttpClient.
private void stopHttpClient() throws SecurityException {
Expand Down

0 comments on commit 4aea68f

Please sign in to comment.