// obey JSSE defined system properties
config.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER,
new PoolingClientConnectionManager(SchemeRegistryFactory.createSystemDefault()));
final ApacheHttpClient4 client = ApacheHttpClient4.create(config);
// set UA
client.getClientHandler().getHttpClient().getParams().setParameter(
CoreProtocolPNames.USER_AGENT, "Nexus-Client/" + discoverClientVersion()
);
// "tweak" HTTPS scheme as requested
final TrustStrategy trustStrategy;
switch (connectionInfo.getSslCertificateValidation()) {
case NONE:
trustStrategy = new TrustStrategy()
{
@Override
public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
return true;
}
};
break;
case LAX:
trustStrategy = new TrustSelfSignedStrategy();
break;
default:
trustStrategy = null;
}
final X509HostnameVerifier hostnameVerifier;
switch (connectionInfo.getSslCertificateHostnameValidation()) {
case NONE:
hostnameVerifier = new AllowAllHostnameVerifier();
break;
case STRICT:
hostnameVerifier = new StrictHostnameVerifier();
break;
default:
hostnameVerifier = new BrowserCompatHostnameVerifier();
}
try {
final SSLSocketFactory ssf = new SSLSocketFactory(trustStrategy, hostnameVerifier);
final Scheme tweakedHttpsScheme = new Scheme("https", 443, ssf);
client.getClientHandler().getHttpClient().getConnectionManager().getSchemeRegistry().register(tweakedHttpsScheme);
}
catch (Exception e) {
Throwables.propagate(e);
}
// NXCM-4547 JERSEY-1293 Enforce proxy setting on httpclient
enforceProxyUri(config, client);
if (LOG.isDebugEnabled()) {
client.addFilter(new LoggingFilter());
}
client.addFilter(new RequestFilters());
return client;
}