use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project ddf by codice.
the class HttpSolrClientFactory method getSecureHttpClient.
private static CloseableHttpClient getSecureHttpClient(boolean retryRequestsOnError) {
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(getSslContext(), getProtocols(), getCipherSuites(), SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
HttpRequestRetryHandler solrRetryHandler = new SolrHttpRequestRetryHandler();
HttpClientBuilder builder = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory).setDefaultCookieStore(new BasicCookieStore()).setMaxConnTotal(128).setMaxConnPerRoute(32);
if (retryRequestsOnError) {
builder.setRetryHandler(solrRetryHandler);
}
return builder.build();
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project iTest by e-government-ua.
the class DeleteTask method createHttpClient_AcceptsUntrustedCerts.
public HttpClient createHttpClient_AcceptsUntrustedCerts() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
HttpClientBuilder b = HttpClientBuilder.create();
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
b.setSslcontext(sslContext);
HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, (X509HostnameVerifier) hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
b.setConnectionManager(connMgr);
HttpClient client = b.build();
return client;
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project gocd by gocd.
the class GoAgentServerHttpClientBuilder method build.
public CloseableHttpClient build() throws Exception {
HttpClientBuilder builder = HttpClients.custom();
builder.useSystemProperties();
builder.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build()).setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE);
HostnameVerifier hostnameVerifier = sslVerificationMode.verifier();
TrustStrategy trustStrategy = sslVerificationMode.trustStrategy();
KeyStore trustStore = agentTruststore();
SSLContextBuilder sslContextBuilder = SSLContextBuilder.create().useProtocol(systemEnvironment.get(SystemEnvironment.GO_SSL_TRANSPORT_PROTOCOL_TO_BE_USED_BY_AGENT));
if (trustStore != null || trustStrategy != null) {
sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
}
sslContextBuilder.loadKeyMaterial(agentKeystore(), keystorePassword().toCharArray());
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContextBuilder.build(), hostnameVerifier);
builder.setSSLSocketFactory(sslConnectionSocketFactory);
return builder.build();
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project docker-maven-plugin by fabric8io.
the class HttpPingChecker method ping.
private boolean ping() throws IOException {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(HTTP_PING_TIMEOUT).setConnectTimeout(HTTP_PING_TIMEOUT).setConnectionRequestTimeout(HTTP_PING_TIMEOUT).setRedirectsEnabled(false).build();
CloseableHttpClient httpClient;
if (allowAllHosts) {
SSLContextBuilder builder = new SSLContextBuilder();
try {
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false)).setSSLSocketFactory(socketFactory).build();
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new IOException("Unable to set self signed strategy on http wait: " + e, e);
}
} else {
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false)).build();
}
try {
CloseableHttpResponse response = httpClient.execute(RequestBuilder.create(method.toUpperCase()).setUri(url).build());
try {
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode == 501) {
throw new IllegalArgumentException("Invalid or not supported HTTP method '" + method.toUpperCase() + "' for checking " + url);
}
return responseCode >= statusMin && responseCode <= statusMax;
} finally {
response.close();
}
} finally {
httpClient.close();
}
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project jetty-bootstrap by teknux-org.
the class AbstractJettyBootstrapTest method get.
protected SimpleResponse get(String url) throws IllegalStateException, IOException, JettyBootstrapException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
SimpleResponse simpleResponse = new SimpleResponse();
CloseableHttpClient httpClient;
HttpGet httpGet;
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIMEOUT).build();
if (ssl) {
SSLContextBuilder sSLContextBuilder = new SSLContextBuilder();
sSLContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sSLConnectionSocketFactory = new SSLConnectionSocketFactory(sSLContextBuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
httpClient = HttpClients.custom().setSSLSocketFactory(sSLConnectionSocketFactory).build();
httpGet = new HttpGet("https://" + HOST + ":" + getPort() + url);
} else {
httpClient = HttpClients.createDefault();
httpGet = new HttpGet("http://" + HOST + ":" + getPort() + url);
}
httpGet.setConfig(requestConfig);
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpGet);
simpleResponse.setStatusCode(response.getStatusLine().getStatusCode());
simpleResponse.setContent(IOUtils.toString(response.getEntity().getContent()));
} finally {
if (response != null) {
response.close();
}
httpClient.close();
}
return simpleResponse;
}
Aggregations