use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project nutch by apache.
the class ElasticRestIndexWriter method open.
@Override
public void open(Configuration conf, String name) throws IOException {
hosts = conf.getStrings(ElasticRestConstants.HOST);
port = conf.getInt(ElasticRestConstants.PORT, 9200);
user = conf.get(ElasticRestConstants.USER);
password = conf.get(ElasticRestConstants.PASSWORD);
https = conf.getBoolean(ElasticRestConstants.HTTPS, false);
trustAllHostnames = conf.getBoolean(ElasticRestConstants.HOSTNAME_TRUST, false);
languages = conf.getStrings(ElasticRestConstants.LANGUAGES);
separator = conf.get(ElasticRestConstants.SEPARATOR, DEFAULT_SEPARATOR);
sink = conf.get(ElasticRestConstants.SINK, DEFAULT_SINK);
// trust ALL certificates
SSLContext sslContext = null;
try {
sslContext = new SSLContextBuilder().loadTrustMaterial(new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
LOG.error("Failed to instantiate sslcontext object: \n{}", ExceptionUtils.getStackTrace(e));
throw new SecurityException();
}
// skip hostname checks
HostnameVerifier hostnameVerifier = null;
if (trustAllHostnames) {
hostnameVerifier = NoopHostnameVerifier.INSTANCE;
} else {
hostnameVerifier = new DefaultHostnameVerifier();
}
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);
SchemeIOSessionStrategy httpsIOSessionStrategy = new SSLIOSessionStrategy(sslContext, hostnameVerifier);
JestClientFactory jestClientFactory = new JestClientFactory();
if (hosts == null || hosts.length == 0 || port <= 1) {
throw new IllegalStateException("No hosts or port specified. Please set the host and port in nutch-site.xml");
}
List<String> urlsOfElasticsearchNodes = new ArrayList<String>();
for (String host : hosts) {
urlsOfElasticsearchNodes.add(new URL(https ? "https" : "http", host, port, "").toString());
}
HttpClientConfig.Builder builder = new HttpClientConfig.Builder(urlsOfElasticsearchNodes).multiThreaded(true).connTimeout(300000).readTimeout(300000);
if (https) {
if (user != null && password != null) {
builder.defaultCredentials(user, password);
}
builder.defaultSchemeForDiscoveredNodes("https").sslSocketFactory(// this only affects sync calls
sslSocketFactory).httpsIOSessionStrategy(// this only affects async calls
httpsIOSessionStrategy);
}
jestClientFactory.setHttpClientConfig(builder.build());
client = jestClientFactory.getObject();
defaultIndex = conf.get(ElasticRestConstants.INDEX, "nutch");
defaultType = conf.get(ElasticRestConstants.TYPE, "doc");
maxBulkDocs = conf.getInt(ElasticRestConstants.MAX_BULK_DOCS, DEFAULT_MAX_BULK_DOCS);
maxBulkLength = conf.getInt(ElasticRestConstants.MAX_BULK_LENGTH, DEFAULT_MAX_BULK_LENGTH);
bulkBuilder = new Bulk.Builder().defaultIndex(defaultIndex).defaultType(defaultType);
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project syndesis-qe by syndesisio.
the class RestUtils method createAllTrustingClient.
// Required in order to skip certificate validation
private static HttpClient createAllTrustingClient() throws RestClientException {
HttpClient httpclient = null;
try {
final SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial((TrustStrategy) (X509Certificate[] chain, String authType) -> true);
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).setMaxConnTotal(1000).setMaxConnPerRoute(1000).build();
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new RestClientException("Cannot create all SSL certificates trusting client", e);
}
return httpclient;
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project coprhd-controller by CoprHD.
the class WinRMTarget method createClientConnectionManager.
private HttpClientConnectionManager createClientConnectionManager() throws Exception {
SSLContextBuilder contextBuilder = SSLContexts.custom();
try {
contextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", socketFactory).build();
return (new PoolingHttpClientConnectionManager(registry));
} catch (Exception e) {
throw new HttpException(e.getMessage());
}
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project swift by luastar.
the class HttpClientUtils method createHttpClient.
/**
* 创建自定义重定向策略,支持https的调用
*
* @param url
* @return
*/
private static CloseableHttpClient createHttpClient(String url, RedirectStrategy redirectStrategy) {
try {
HttpClientBuilder httpClientBuilder = HttpClients.custom();
// 重定向策略
if (redirectStrategy != null) {
httpClientBuilder.setRedirectStrategy(redirectStrategy);
}
// https支持
if (StringUtils.isNotEmpty(url) && url.startsWith("https://")) {
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext);
httpClientBuilder.setSSLSocketFactory(sslsf);
}
return httpClientBuilder.build();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return HttpClients.createDefault();
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project SEPA by arces-wot.
the class SSLSecurityManager method getSSLHttpClient.
/**
* Gets the SSL http client.
*
* @return the SSL http client
* @throws KeyManagementException the key management exception
* @throws NoSuchAlgorithmException the no such algorithm exception
* @throws KeyStoreException the key store exception
* @throws CertificateException the certificate exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public CloseableHttpClient getSSLHttpClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
// Trust own CA and all self-signed certificates
SSLContext sslcontext = null;
sslcontext = SSLContexts.custom().loadTrustMaterial(new File(storename), password.toCharArray(), new TrustSelfSignedStrategy()).build();
// Allow TLSv1 protocol only
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { protocol }, null, this);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
Aggregations