List of usage examples for org.apache.http.nio.conn.ssl SSLIOSessionStrategy SSLIOSessionStrategy
public SSLIOSessionStrategy(final SSLContext sslContext, final String[] supportedProtocols, final String[] supportedCipherSuites, final HostnameVerifier hostnameVerifier)
From source file:com.boonya.http.async.examples.nio.client.AsyncClientCustomSSL.java
public final static void main(String[] args) throws Exception { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream instream = new FileInputStream(new File("my.keystore")); try {/*from w w w . ja v a2s. c om*/ trustStore.load(instream, "nopassword".toCharArray()); } finally { instream.close(); } // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()) .build(); // Allow TLSv1 protocol only SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(sslcontext, new String[] { "TLSv1" }, null, SSLIOSessionStrategy.getDefaultHostnameVerifier()); CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).build(); try { httpclient.start(); HttpGet request = new HttpGet("https://issues.apache.org/"); Future<HttpResponse> future = httpclient.execute(request, null); HttpResponse response = future.get(); System.out.println("Response: " + response.getStatusLine()); System.out.println("Shutting down"); } finally { httpclient.close(); } System.out.println("Done"); }
From source file:com.vmware.loginsightapi.util.AsyncLogInsightConnectionStrategy.java
/** * Initializes and returns the httpClient with NoopHostnameVerifier * //from w w w . j av a 2s .c o m * @return CloseableHttpAsyncClient */ @Override public CloseableHttpAsyncClient getHttpClient() { // Trust own CA and all self-signed certs SSLContext sslcontext = NonValidatingSSLSocketFactory.getSSLContext(); // Allow TLSv1 protocol only SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(sslcontext, new String[] { "TLSv1" }, null, new NoopHostnameVerifier()); List<Header> headers = LogInsightClient.getDefaultHeaders(); asyncHttpClient = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).setDefaultHeaders(headers) .build(); asyncHttpClient.start(); return asyncHttpClient; }
From source file:com.clxcommunications.xms.ApiHttpAsyncClient.java
/** * Creates a new HTTP asynchronous client suitable for communicating with * XMS.//from ww w .j a va 2 s . com * * @param startedInternally * whether this object was created inside this SDK */ ApiHttpAsyncClient(boolean startedInternally) { this.startedInternally = startedInternally; // Allow TLSv1.2 protocol only SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(SSLContexts.createSystemDefault(), new String[] { "TLSv1.2" }, null, SSLIOSessionStrategy.getDefaultHostnameVerifier()); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout((int) DEFAULT_TIMEOUT.toMillis()) .setSocketTimeout((int) DEFAULT_TIMEOUT.toMillis()).build(); // TODO: Is this a good default setup? this.client = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).disableCookieManagement() .setMaxConnPerRoute(DEFAULT_MAX_CONN).setMaxConnTotal(DEFAULT_MAX_CONN) .setDefaultRequestConfig(requestConfig).build(); }
From source file:org.elasticsearch.xpack.core.ssl.SSLService.java
/** * This method only exists to simplify testing of {@link #sslIOSessionStrategy(Settings)} because {@link SSLIOSessionStrategy} does * not expose any of the parameters that you give it. * * @param sslContext SSL Context used to handle SSL / TCP requests * @param protocols Supported protocols// w ww .j av a 2 s . c o m * @param ciphers Supported ciphers * @param verifier Hostname verifier * @return Never {@code null}. */ SSLIOSessionStrategy sslIOSessionStrategy(SSLContext sslContext, String[] protocols, String[] ciphers, HostnameVerifier verifier) { return new SSLIOSessionStrategy(sslContext, protocols, ciphers, verifier); }
From source file:co.paralleluniverse.fibers.dropwizard.FiberHttpClientBuilder.java
private static Registry<SchemeIOSessionStrategy> convertRegistry(final SchemeRegistry oldRegistry) throws SSLInitializationException { SchemeRegistry baseRegistry = oldRegistry; //TODO: use values from old registry; Registry<SchemeIOSessionStrategy> defaultRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create() .register("http", NoopIOSessionStrategy.INSTANCE) .register("https", new SSLIOSessionStrategy(SSLContexts.createDefault(), null, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER)) .build();/*from www .ja v a2s. co m*/ return defaultRegistry; }
From source file:com.networknt.client.Client.java
private Registry<SchemeIOSessionStrategy> asyncRegistry() throws ClientException { // Allow TLSv1 protocol only Registry<SchemeIOSessionStrategy> registry = null; try {/*w ww . ja v a2 s . com*/ SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(sslContext(), new String[] { "TLSv1" }, null, hostnameVerifier()); // Create a registry of custom connection session strategies for supported // protocol schemes. registry = RegistryBuilder.<SchemeIOSessionStrategy>create() .register("http", NoopIOSessionStrategy.INSTANCE).register("https", sslSessionStrategy).build(); } catch (NoSuchAlgorithmException e) { logger.error("NoSuchAlgorithmException: ", e); throw new ClientException("NoSuchAlgorithmException: ", e); } catch (KeyManagementException e) { logger.error("KeyManagementException: ", e); throw new ClientException("KeyManagementException: ", e); } catch (IOException e) { logger.error("IOException: ", e); throw new ClientException("IOException: ", e); } return registry; }
From source file:com.liferay.petra.json.web.service.client.BaseJSONWebServiceClientImpl.java
protected SSLIOSessionStrategy getSSLIOSessionStrategy() { SSLContextBuilder sslContextBuilder = SSLContexts.custom(); SSLContext sslContext = null; try {/* ww w . ja v a 2 s.co m*/ sslContextBuilder.loadTrustMaterial(_keyStore, new TrustSelfSignedStrategy()); sslContext = sslContextBuilder.build(); sslContext.init(null, new TrustManager[] { new X509TrustManagerImpl() }, null); } catch (Exception e) { throw new RuntimeException(e); } return new SSLIOSessionStrategy(sslContext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); }