From 857e8d31f3940b72716721cbf63e7a514285c221 Mon Sep 17 00:00:00 2001 From: Andrew Regan Date: Wed, 4 Nov 2015 12:03:03 +0000 Subject: [PATCH] Lazily instantiate SSLConnectionSocketFactory to avoid expensive call --- .../java/io/searchbox/client/config/HttpClientConfig.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jest/src/main/java/io/searchbox/client/config/HttpClientConfig.java b/jest/src/main/java/io/searchbox/client/config/HttpClientConfig.java index 68602e6a4..c92eab675 100644 --- a/jest/src/main/java/io/searchbox/client/config/HttpClientConfig.java +++ b/jest/src/main/java/io/searchbox/client/config/HttpClientConfig.java @@ -100,7 +100,7 @@ public static class Builder extends ClientConfig.AbstractBuilder maxTotalConnectionPerRoute = new HashMap(); private CredentialsProvider credentialsProvider; - private LayeredConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory(); + private LayeredConnectionSocketFactory sslSocketFactory; private ConnectionSocketFactory plainSocketFactory = PlainConnectionSocketFactory.getSocketFactory(); private HttpRoutePlanner httpRoutePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault()); private AuthenticationStrategy proxyAuthenticationStrategy; @@ -242,6 +242,10 @@ public Builder proxy(HttpHost proxy, AuthenticationStrategy proxyAuthenticationS } public HttpClientConfig build() { + if (this.sslSocketFactory == null) { + // Lazily initialize if necessary, as the call can be expensive when done eagerly. + this.sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory(); + } return new HttpClientConfig(this); }