use of lucee.runtime.net.http.sni.DefaultHttpClientConnectionOperatorImpl in project Lucee by lucee.
the class HttpGetWithBody method ssl.
private void ssl(HttpClientBuilder builder) throws PageException {
try {
// SSLContext sslcontext = SSLContexts.createSystemDefault();
SSLContext sslcontext = SSLContext.getInstance("TLSv1.2");
if (!StringUtil.isEmpty(this.clientCert)) {
if (this.clientCertPassword == null)
this.clientCertPassword = "";
File ksFile = new File(this.clientCert);
KeyStore clientStore = KeyStore.getInstance("PKCS12");
clientStore.load(new FileInputStream(ksFile), this.clientCertPassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(clientStore, this.clientCertPassword.toCharArray());
sslcontext.init(kmf.getKeyManagers(), null, new java.security.SecureRandom());
} else {
sslcontext.init(null, null, new java.security.SecureRandom());
}
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactoryImpl(sslcontext, new DefaultHostnameVerifierImpl());
builder.setSSLSocketFactory(sslsf);
Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(new DefaultHttpClientConnectionOperatorImpl(reg), null, -1, // TODO review -1 setting
TimeUnit.MILLISECONDS);
builder.setConnectionManager(cm);
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
Aggregations