List of usage examples for org.apache.http.conn.ssl SSLConnectionSocketFactory ALLOW_ALL_HOSTNAME_VERIFIER
X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER
To view the source code for org.apache.http.conn.ssl SSLConnectionSocketFactory ALLOW_ALL_HOSTNAME_VERIFIER.
Click Source Link
From source file:org.jboss.as.test.integration.security.common.SSLTruststoreUtil.java
public static HttpClient getHttpClientWithSSL(File keyStoreFile, String keyStorePassword, File trustStoreFile, String trustStorePassword) { try {// www.j av a 2s.co m final KeyStore truststore = loadKeyStore(trustStoreFile, trustStorePassword.toCharArray()); final KeyStore keystore = keyStoreFile != null ? loadKeyStore(keyStoreFile, keyStorePassword.toCharArray()) : null; SSLContextBuilder sslContextBuilder = SSLContexts.custom().useTLS().loadTrustMaterial(truststore); if (keyStoreFile != null) { sslContextBuilder.loadKeyMaterial(keystore, keyStorePassword.toCharArray()); } SSLContext sslContext = sslContextBuilder.build(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier()); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", socketFactory).build(); return HttpClientBuilder.create().setSSLSocketFactory(socketFactory) .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) .setConnectionManager(new PoolingHttpClientConnectionManager(registry)) .setSchemePortResolver(new DefaultSchemePortResolver()).build(); } catch (Exception e) { LOGGER.error( "Creating HttpClient with customized SSL failed. We are returning the default one instead.", e); return HttpClients.createDefault(); } }
From source file:org.opennms.core.web.HttpClientWrapper.java
protected void configureSSLContext(final HttpClientBuilder builder) { final RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder .<ConnectionSocketFactory>create(); for (final Map.Entry<String, SSLContext> entry : m_sslContext.entrySet()) { final SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(entry.getValue(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); registryBuilder.register(entry.getKey(), sslConnectionFactory); }//from w ww . j av a 2 s. c o m if (!m_sslContext.containsKey("http")) { registryBuilder.register("http", PlainConnectionSocketFactory.INSTANCE); } if (!m_sslContext.containsKey("https")) { registryBuilder.register("https", SSLConnectionSocketFactory.getSystemSocketFactory()); } final HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registryBuilder.build()); builder.setConnectionManager(ccm); }
From source file:org.teknux.jettybootstrap.test.jettybootstrap.AbstractJettyBootstrapTest.java
protected SimpleResponse get(String url) throws IllegalStateException, IOException, JettyBootstrapException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { SimpleResponse simpleResponse = new SimpleResponse(); CloseableHttpClient httpClient;// ww w. j a v a 2 s . c om 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; }