List of usage examples for org.apache.http.conn.ssl SSLConnectionSocketFactory getSocketFactory
public static SSLConnectionSocketFactory getSocketFactory() throws SSLInitializationException
cacerts
file in the security properties directory). From source file:com.ninjas.movietime.conf.vendor.metrics.InstrumentedHttpClientConnectionManager.java
protected static Registry<ConnectionSocketFactory> getDefaultRegistry() { return RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSocketFactory()).build(); }
From source file:com.jivesoftware.os.routing.bird.http.client.HttpClientFactoryProvider.java
public HttpClientFactory createHttpClientFactory(Collection<HttpClientConfiguration> configurations, boolean latentClient) { HttpClientConfig httpClientConfig = locateConfig(configurations, HttpClientConfig.class, HttpClientConfig.newBuilder().build()); HttpClientSSLConfig sslConfig = locateConfig(configurations, HttpClientSSLConfig.class, null); String scheme;/* w ww . j a v a2 s. c om*/ PoolingHttpClientConnectionManager poolingHttpClientConnectionManager; if (sslConfig != null && sslConfig.isUseSsl()) { LayeredConnectionSocketFactory sslSocketFactory; if (sslConfig.getCustomSSLSocketFactory() != null) { sslSocketFactory = sslConfig.getCustomSSLSocketFactory(); } else { sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory(); } scheme = "https"; poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager( RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build()); } else { scheme = "http"; poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(); } if (httpClientConfig.getMaxConnections() > 0) { poolingHttpClientConnectionManager.setMaxTotal(httpClientConfig.getMaxConnections()); } else { poolingHttpClientConnectionManager.setMaxTotal(Integer.MAX_VALUE); } if (httpClientConfig.getMaxConnectionsPerHost() > 0) { poolingHttpClientConnectionManager.setDefaultMaxPerRoute(httpClientConfig.getMaxConnectionsPerHost()); } else { poolingHttpClientConnectionManager.setDefaultMaxPerRoute(Integer.MAX_VALUE); } poolingHttpClientConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout( httpClientConfig.getSocketTimeoutInMillis() > 0 ? httpClientConfig.getSocketTimeoutInMillis() : 0) .build()); Closeable closeable; HttpClientConnectionManager clientConnectionManager; clientConnectionManager = poolingHttpClientConnectionManager; closeable = poolingHttpClientConnectionManager; return (OAuthSigner signer, String host, int port) -> { HttpClientBuilder httpClientBuilder = HttpClients.custom() .setConnectionManager(clientConnectionManager); CloseableHttpClient client = httpClientBuilder.build(); HttpClient httpClient = new ApacheHttpClient441BackedHttpClient(scheme, host, port, signer, client, closeable, httpClientConfig.getCopyOfHeadersForEveryRequest()); if (latentClient) { httpClient = new LatentHttpClient(httpClient); } return httpClient; }; }
From source file:com.serphacker.serposcope.scraper.http.extensions.CloseableBasicHttpClientConnectionManager.java
private static Registry<ConnectionSocketFactory> getDefaultRegistry() { return RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSocketFactory()).build(); }
From source file:org.talend.dataprep.configuration.HttpClient.java
/** * @return the http connection manager.//from w ww. j a va 2s . c o m */ @Bean(destroyMethod = "shutdown") public PoolingHttpClientConnectionManager getConnectionManager() { // fallback to default implementation if (sslSocketFactory == null) { sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory(); } PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build()); connectionManager.setMaxTotal(maxPoolSize); connectionManager.setDefaultMaxPerRoute(maxPerRoute); return connectionManager; }
From source file:info.bonjean.beluga.connection.BelugaHTTPClient.java
private BelugaHTTPClient() { BelugaConfiguration configuration = BelugaConfiguration.getInstance(); HttpClientBuilder clientBuilder = HttpClients.custom(); // timeout/*from w w w .j a v a 2s . co m*/ RequestConfig config = RequestConfig.custom().setConnectTimeout(TIMEOUT).setSocketTimeout(TIMEOUT) .setConnectionRequestTimeout(TIMEOUT).build(); clientBuilder.setDefaultRequestConfig(config); switch (configuration.getConnectionType()) { case PROXY_DNS: Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSocketFactory()).build(); BelugaDNSResolver dnsOverrider = new BelugaDNSResolver(DNSProxy.PROXY_DNS); connectionManager = new PoolingHttpClientConnectionManager(registry, dnsOverrider); break; case HTTP_PROXY: HttpHost proxy = new HttpHost(configuration.getProxyHost(), configuration.getProxyPort(), "http"); clientBuilder.setProxy(proxy); break; default: } // limit the pool size connectionManager.setDefaultMaxPerRoute(2); // add interceptor, currently for debugging only clientBuilder.addInterceptorFirst(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext context) throws HttpException, IOException { HttpInetConnection connection = (HttpInetConnection) context .getAttribute(HttpCoreContext.HTTP_CONNECTION); log.debug("Remote address: " + connection.getRemoteAddress()); // TODO: reimplement blacklisting for DNS proxy by maintaining a // map [DNS IP,RESOLVED IP] in the DNS resolver for reverse // lookup } }); // finally create the HTTP client clientBuilder.setConnectionManager(connectionManager); httpClient = clientBuilder.build(); }
From source file:nya.miku.wishmaster.http.client.ExtendedHttpClient.java
/** * ? SSL//from www. ja v a 2 s. c o m * @param safe ??, ? false, ? */ private static LayeredConnectionSocketFactory obtainSSLSocketFactory(boolean safe) { if (safe) { return SSLConnectionSocketFactory.getSocketFactory(); } else { try { if (unsafe_ssl_context == null) unsafe_ssl_context = SSLContexts.custom().loadTrustMaterial(null, TRUST_ALL).build(); return new SSLConnectionSocketFactory(unsafe_ssl_context, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Exception e) { Logger.e(TAG, "cannot instantiate the unsafe SSL socket factory", e); return SSLConnectionSocketFactory.getSocketFactory(); } } }
From source file:com.fourspaces.couchdb.Session.java
/** * Constructor for obtaining a Session with an HTTP-AUTH username/password * and (optionally) a secure connection This isn't supported by CouchDB - * you need a proxy in front to use this * * @param host - hostname//from w w w. j a va2 s . co m * @param port - port to use * @param user - username * @param pass - password * @param usesAuth * @param secure - use an SSL connection? */ public Session(String host, int port, String user, String pass, boolean usesAuth, boolean secure) { this.host = host; this.port = port; this.user = user; this.pass = pass; this.usesAuth = usesAuth; this.secure = secure; PlainConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory(); LayeredConnectionSocketFactory sslsf = SSLConnectionSocketFactory.getSocketFactory(); Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", plainsf).register("https", sslsf).build(); this.connManager = new PoolingHttpClientConnectionManager(r); this.requestConfig = RequestConfig.custom().setConnectTimeout(15 * 1000).setSocketTimeout((30 * 1000)) .setAuthenticationEnabled(usesAuth).build(); this.httpContext = HttpClientContext.create(); if (user != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, pass)); this.httpContext.setCredentialsProvider(credsProvider); } this.httpClient = createHttpClient(); }
From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItemAsyncTest.java
@Test public void testWithClientCertificate() { HttpClientConfigImpl config = context.registerInjectActivateService(new HttpClientConfigImpl(), ImmutableMap.<String, Object>builder() .put(KEYSTORE_PATH_PROPERTY, CertificateLoaderTest.KEYSTORE_PATH) .put(KEYSTORE_PASSWORD_PROPERTY, CertificateLoaderTest.KEYSTORE_PASSWORD) .put(TRUSTSTORE_PATH_PROPERTY, CertificateLoaderTest.TRUSTSTORE_PATH) .put(TRUSTSTORE_PASSWORD_PROPERTY, CertificateLoaderTest.TRUSTSTORE_PASSWORD).build()); HttpClientItem item = new HttpClientItem(config); HttpAsyncClient client = item.getHttpAsyncClient(); Registry<SchemeIOSessionStrategy> schemeRegistry = HttpClientTestUtils.getSchemeRegistry(client); SchemeIOSessionStrategy schemeSocketFactory = schemeRegistry.lookup("https"); assertNotEquals(schemeSocketFactory, SSLConnectionSocketFactory.getSocketFactory()); item.close();//from w w w.j av a 2 s . com }
From source file:io.wcm.caravan.commons.httpasyncclient.impl.HttpClientItemAsyncTest.java
@Test public void testWithClientCertificate() { HttpClientConfigImpl config = context.registerInjectActivateService(new HttpClientConfigImpl(), ImmutableMap.<String, Object>builder() .put(KEYSTORE_PATH_PROPERTY, CertificateLoaderTest.KEYSTORE_PATH) .put(KEYSTORE_PASSWORD_PROPERTY, CertificateLoaderTest.KEYSTORE_PASSWORD) .put(TRUSTSTORE_PATH_PROPERTY, CertificateLoaderTest.TRUSTSTORE_PATH) .put(TRUSTSTORE_PASSWORD_PROPERTY, CertificateLoaderTest.TRUSTSTORE_PASSWORD).build()); HttpAsyncClientItem item = new HttpAsyncClientItem(config); HttpAsyncClient client = item.getHttpAsyncClient(); Registry<SchemeIOSessionStrategy> schemeRegistry = HttpClientTestUtils.getSchemeRegistry(client); SchemeIOSessionStrategy schemeSocketFactory = schemeRegistry.lookup("https"); assertNotEquals(schemeSocketFactory, SSLConnectionSocketFactory.getSocketFactory()); item.close();// w w w . ja v a 2 s . c o m }