@Override
public void init() throws Exception {
super.init();
if (client == null) {
client = new HttpClient(new SslContextFactory());
client.setExecutor(new ExecutorThreadPool(threadPool));
// configure timeout if set
if (connectTimeout != -1) {
client.setConnectTimeout(connectTimeout);
}
if (idleTimeout != -1) {
client.setIdleTimeout(idleTimeout);
}
client.setMaxConnectionsPerDestination(maxConnectionsPerDestination);
client.setMaxRequestsQueuedPerDestination(maxRequestsQueuedPerDestination);
//Configure SSL - if relevant
if (transportSSLEnabled) {
KeyStoreManagement keyStore = KeyStoreManagement.getKeyStoreManagement(httpsKeystoreType, httpsKeystore, httpsKeyPassword);
if (jmxControl != null && keyStore != null) {
jmxControl.registerMBean("CoUGAR:name=AsyncHttpClientKeyStore,beanName="+beanName, keyStore);
}
KeyStoreManagement trustStore = KeyStoreManagement.getKeyStoreManagement(httpsTruststoreType, httpsTruststore, httpsTrustPassword);
if (jmxControl != null) {
jmxControl.registerMBean("CoUGAR:name=AsyncHttpClientTrustStore,beanName="+beanName, trustStore);
}
if (trustStore == null) {
throw new IllegalStateException("This configuration ostensibly supports TLS, yet doesn't provide valid truststore configuration");
}
final SslContextFactory sslContextFactory = client.getSslContextFactory();
com.betfair.cougar.netutil.SslContextFactory factory = new com.betfair.cougar.netutil.SslContextFactory();
factory.setTrustManagerFactoryKeyStore(trustStore.getKeyStore());
if (keyStore != null) {
factory.setKeyManagerFactoryKeyStore(keyStore.getKeyStore());
factory.setKeyManagerFactoryKeyStorePassword(httpsKeyPassword);
}
SSLContext context = factory.newInstance();
if (hostnameVerificationDisabled) {
context.getDefaultSSLParameters().setEndpointIdentificationAlgorithm(null);
LOGGER.warn("CRITICAL SECURITY CHECKS ARE DISABLED: server SSL certificate hostname " +
"verification is turned off.");
}
else {
context.getDefaultSSLParameters().setEndpointIdentificationAlgorithm("https");
}
sslContextFactory.setSslContext(context);
}
client.start();
clientCreated = true;
}