List of usage examples for org.apache.http.conn.ssl SSLConnectionSocketFactory getSystemSocketFactory
public static SSLConnectionSocketFactory getSystemSocketFactory() throws SSLInitializationException
From source file:org.sonatype.spice.zapper.client.hc4.Hc4ClientBuilder.java
public Hc4Client build() { final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSystemSocketFactory()).build(); final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry); cm.setMaxTotal(200);//from w w w .j a v a 2 s .c om cm.setDefaultMaxPerRoute(parameters.getMaximumTrackCount()); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setConnectionManager(cm) .setUserAgent("Zapper/1.0-HC4"); if (proxyServer != null) { httpClientBuilder.setProxy(proxyServer); } if (credentialsProvider != null) { httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } return new Hc4Client(parameters, remoteUrl, httpClientBuilder.build(), preemptiveAuth ? credentialsProvider : null); }
From source file:org.callimachusproject.client.HttpClientFactory.java
private HttpClientFactory(File cacheDir) throws IOException { cacheDir.mkdirs();/*from w w w .j a v a 2s. com*/ entryFactory = new FileResourceFactory(cacheDir); decorator = new ProxyClientExecDecorator(); LayeredConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactory.getSystemSocketFactory(); connManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build()); connManager.setDefaultSocketConfig(getDefaultSocketConfig()); connManager.setDefaultConnectionConfig(getDefaultConnectionConfig()); int max = Integer.parseInt(System.getProperty("http.maxConnections", "20")); connManager.setDefaultMaxPerRoute(max); connManager.setMaxTotal(2 * max); reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE; keepAliveStrategy = new ConnectionKeepAliveStrategy() { private final long KEEPALIVE = SystemProperties.getClientKeepAliveTimeout(); private ConnectionKeepAliveStrategy delegate = DefaultConnectionKeepAliveStrategy.INSTANCE; public long getKeepAliveDuration(HttpResponse response, HttpContext context) { long ret = delegate.getKeepAliveDuration(response, context); if (ret > 0) return ret; return KEEPALIVE; } }; }
From source file:com.helger.httpclient.HttpClientFactory.java
@Nullable public LayeredConnectionSocketFactory createSSLFactory() { LayeredConnectionSocketFactory aSSLFactory = null; try {/*from w ww. j a v a 2 s .c om*/ // First try with a custom SSL context if (m_aSSLContext != null) { // Choose correct TLS configuration mode final ITLSConfigurationMode aTLSConfigMode = m_aTLSConfigurationMode != null ? m_aTLSConfigurationMode : DEFAULT_TLS_CONFIG_MODE; // Custom hostname verifier preferred HostnameVerifier aHostnameVerifier = m_aHostnameVerifier; if (aHostnameVerifier == null) aHostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier(); if (LOGGER.isDebugEnabled()) LOGGER.debug("Using the following TLS versions: " + aTLSConfigMode.getAllTLSVersionIDs()); if (LOGGER.isDebugEnabled()) LOGGER.debug("Using the following TLS cipher suites: " + aTLSConfigMode.getAllCipherSuites()); if (LOGGER.isDebugEnabled()) LOGGER.debug("Using the following hostname verifier: " + aHostnameVerifier); aSSLFactory = new SSLConnectionSocketFactory(m_aSSLContext, aTLSConfigMode.getAllTLSVersionIDsAsArray(), aTLSConfigMode.getAllCipherSuitesAsArray(), aHostnameVerifier); } } catch (final SSLInitializationException ex) { // Fall through LOGGER.warn( "Failed to init custom SSLConnectionSocketFactory - falling back to default SSLConnectionSocketFactory", ex); } if (aSSLFactory == null) { // No custom SSL context present - use system defaults try { aSSLFactory = SSLConnectionSocketFactory.getSystemSocketFactory(); } catch (final SSLInitializationException ex) { try { aSSLFactory = SSLConnectionSocketFactory.getSocketFactory(); } catch (final SSLInitializationException ex2) { // Fall through } } } return aSSLFactory; }
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 w w . java2 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); }