Created
June 3, 2014 08:15
-
-
Save tmarcus87/e7da2f90fd962cedc780 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HttpClientFactoryV43 { | |
private BasicHttpClientConnectionManager connectionManager; | |
public HttpClientFactoryV43() { | |
try { | |
SSLContext sslContext = new SSLContextBuilder() | |
.loadTrustMaterial( | |
null, | |
new TrustSelfSignedStrategy()) | |
.loadTrustMaterial( | |
null, | |
new TrustStrategy() { | |
@Override public boolean isTrusted(X509Certificate[] chain, String authType) | |
throws CertificateException { | |
return true; | |
} | |
}) | |
.build(); | |
SSLConnectionSocketFactory sslConnectionSocketFactory = | |
new SSLConnectionSocketFactory( | |
sslContext, | |
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); | |
Registry<ConnectionSocketFactory> registry = | |
RegistryBuilder.<ConnectionSocketFactory>create() | |
.register("http", PlainConnectionSocketFactory.getSocketFactory()) | |
.register("https", sslConnectionSocketFactory) | |
.build(); | |
connectionManager = new BasicHttpClientConnectionManager(registry); | |
} catch (NoSuchAlgorithmException e) { | |
throw new RuntimeException(e); | |
} catch (KeyManagementException e) { | |
throw new RuntimeException(e); | |
} catch (KeyStoreException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public HttpClient insecureClient() { | |
RequestConfig config = | |
RequestConfig.custom() | |
.setSocketTimeout(1000) | |
.setConnectTimeout(1000) | |
.setConnectionRequestTimeout(1000) | |
.setStaleConnectionCheckEnabled(true) | |
.build(); | |
return HttpClients.custom() | |
.setDefaultRequestConfig(config) | |
.setMaxConnPerRoute(100) | |
.setMaxConnTotal(100) | |
.disableAutomaticRetries() | |
.disableConnectionState() | |
.disableContentCompression() | |
.disableRedirectHandling() | |
.setConnectionManager(connectionManager) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment