use of org.apache.hc.core5.ssl.SSLContextBuilder in project geo-platform by geosdi.
the class GeoSDIHttpClient5 method createClientConnectionManager.
/**
* @return {@link HttpClientConnectionManager}
*/
HttpClientConnectionManager createClientConnectionManager() {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, (chain, authType) -> true);
SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSF).build());
cm.setMaxTotal(10);
cm.setDefaultMaxPerRoute(3);
return cm;
} catch (Exception ex) {
ex.printStackTrace();
throw new IllegalStateException(ex);
}
}
use of org.apache.hc.core5.ssl.SSLContextBuilder in project geo-platform by geosdi.
the class GPAbstractServerConnector method createDefaultSSLConnectionSocketFactory.
/**
* @return {@link SSLConnectionSocketFactory}
*/
protected SSLConnectionSocketFactory createDefaultSSLConnectionSocketFactory() {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, (chain, authType) -> true);
return new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
} catch (Exception ex) {
logger.warn("#####################Error to createDefaultSSLConnectionSocketFactory cause : {}\n", ex.getMessage());
ex.printStackTrace();
}
return SSLConnectionSocketFactory.getSocketFactory();
}
use of org.apache.hc.core5.ssl.SSLContextBuilder in project commons-vfs by apache.
the class Http5FileProvider method createSSLContext.
/**
* Create {@link SSLContext} for HttpClient. Invoked by {@link #createHttpClientBuilder(Http5FileSystemConfigBuilder, GenericFileName, FileSystemOptions)}.
*
* @param builder Configuration options builder for HTTP4 provider
* @param fileSystemOptions The FileSystem options
* @return a {@link SSLContext} for HttpClient
* @throws FileSystemException if an error occurs
*/
protected SSLContext createSSLContext(final Http5FileSystemConfigBuilder builder, final FileSystemOptions fileSystemOptions) throws FileSystemException {
try {
final SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.setKeyStoreType(builder.getKeyStoreType(fileSystemOptions));
File keystoreFileObject = null;
final String keystoreFile = builder.getKeyStoreFile(fileSystemOptions);
if (!StringUtils.isEmpty(keystoreFile)) {
keystoreFileObject = new File(keystoreFile);
}
if (keystoreFileObject != null && keystoreFileObject.exists()) {
final String keystorePass = builder.getKeyStorePass(fileSystemOptions);
final char[] keystorePassChars = keystorePass != null ? keystorePass.toCharArray() : null;
sslContextBuilder.loadTrustMaterial(keystoreFileObject, keystorePassChars, TrustAllStrategy.INSTANCE);
} else {
sslContextBuilder.loadTrustMaterial(TrustAllStrategy.INSTANCE);
}
return sslContextBuilder.build();
} catch (final KeyStoreException e) {
throw new FileSystemException("Keystore error. " + e.getMessage(), e);
} catch (final KeyManagementException e) {
throw new FileSystemException("Cannot retrieve keys. " + e.getMessage(), e);
} catch (final NoSuchAlgorithmException e) {
throw new FileSystemException("Algorithm error. " + e.getMessage(), e);
} catch (final CertificateException e) {
throw new FileSystemException("Certificate error. " + e.getMessage(), e);
} catch (final IOException e) {
throw new FileSystemException("Cannot open key file. " + e.getMessage(), e);
}
}
use of org.apache.hc.core5.ssl.SSLContextBuilder in project selenide by selenide.
the class DownloadFileWithHttpRequest method createTrustingHttpClient.
/**
* configure HttpClient to ignore self-signed certs
* as described here: http://literatejava.com/networks/ignore-ssl-certificate-errors-apache-httpclient-4-4/
*/
@CheckReturnValue
@Nonnull
protected CloseableHttpClient createTrustingHttpClient() throws IOException {
try {
HttpClientBuilder builder = HttpClientBuilder.create();
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustAllStrategy()).build();
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
builder.setConnectionManager(connMgr);
return builder.build();
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.apache.hc.core5.ssl.SSLContextBuilder in project geo-platform by geosdi.
the class GPServerProxy method createClientConnectionManager.
/**
* @return {@link HttpClientConnectionManager}
*/
HttpClientConnectionManager createClientConnectionManager() {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, (chain, authType) -> true);
SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSF).build());
cm.setMaxTotal(10);
cm.setDefaultMaxPerRoute(3);
return cm;
} catch (Exception ex) {
ex.printStackTrace();
throw new IllegalStateException(ex);
}
}
Aggregations