点击(此处)折叠或打开
-
private HttpResponse handleCertificateExceptionAndRetry(IOException e,
-
HttpRequestBase method,
-
HttpClientBuilder client,
-
@Nullable HttpContext context)
-
throws IOException {
-
if (!isCertificateException(e)) {
-
throw e;
-
}
-
-
if (isTrusted(method.getURI().getAuthority())) {
-
// creating a special configuration that allows connections to non-trusted HTTPS hosts
-
try {
-
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
-
sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy() {
-
@Override
-
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
-
return true;
-
}
-
});
-
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
-
sslContextBuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
-
-
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
-
.register("https", sslConnectionSocketFactory)
-
.build();
-
-
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
-
client.setConnectionManager(connectionManager);
-
} catch (Exception sslException) {
-
throw Throwables.propagate(sslException);
-
}
-
return client.build().execute(method, context);
-
}
-
throw e;
- }