List of usage examples for org.apache.http.conn.socket PlainConnectionSocketFactory getSocketFactory
public static PlainConnectionSocketFactory getSocketFactory()
From source file:com.helger.pd.client.jdk6.PDClient.java
@Nonnull protected HttpClientBuilder createClientBuilder() { SSLConnectionSocketFactory aSSLSocketFactory = null; try {/*from www.java 2s .c o m*/ // Set SSL context final KeyStore aKeyStore = KeyStoreHelper.loadKeyStore(PDClientConfiguration.getKeyStorePath(), PDClientConfiguration.getKeyStorePassword()); final SSLContext aSSLContext = SSLContexts.custom().loadKeyMaterial(aKeyStore, PDClientConfiguration.getKeyStoreKeyPassword(), new PrivateKeyStrategy() { public String chooseAlias(final Map<String, PrivateKeyDetails> aAliases, final Socket aSocket) { final String sAlias = PDClientConfiguration.getKeyStoreKeyAlias(); return aAliases.containsKey(sAlias) ? sAlias : null; } }).build(); // Allow TLSv1 protocol only aSSLSocketFactory = new SSLConnectionSocketFactory(aSSLContext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); } catch (final Throwable t) { s_aLogger.error("Failed to initialize keystore for service connection! Can only use http now!", t); } try { final RegistryBuilder<ConnectionSocketFactory> aRB = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()); if (aSSLSocketFactory != null) aRB.register("https", aSSLSocketFactory); final Registry<ConnectionSocketFactory> sfr = aRB.build(); final PoolingHttpClientConnectionManager aConnMgr = new PoolingHttpClientConnectionManager(sfr); aConnMgr.setDefaultMaxPerRoute(100); aConnMgr.setMaxTotal(200); aConnMgr.setValidateAfterInactivity(1000); final ConnectionConfig aConnectionConfig = ConnectionConfig.custom() .setMalformedInputAction(CodingErrorAction.IGNORE) .setUnmappableInputAction(CodingErrorAction.IGNORE).setCharset(Consts.UTF_8).build(); aConnMgr.setDefaultConnectionConfig(aConnectionConfig); return HttpClientBuilder.create().setConnectionManager(aConnMgr); } catch (final Exception ex) { throw new InitializationException("Failed to init HTTP client", ex); } }
From source file:com.mirth.connect.connectors.http.HttpDispatcher.java
@Override public void onDeploy() throws ConnectorTaskException { this.connectorProperties = (HttpDispatcherProperties) getConnectorProperties(); // load the default configuration String configurationClass = configurationController.getProperty(connectorProperties.getProtocol(), "httpConfigurationClass"); try {//from w w w . j a v a2 s . c o m configuration = (HttpConfiguration) Class.forName(configurationClass).newInstance(); } catch (Exception e) { logger.trace("could not find custom configuration class, using default"); configuration = new DefaultHttpConfiguration(); } try { socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()); configuration.configureConnectorDeploy(this); } catch (Exception e) { throw new ConnectorTaskException(e); } if (connectorProperties.isResponseBinaryMimeTypesRegex()) { binaryMimeTypesRegexMap = new ConcurrentHashMap<String, Pattern>(); } else { binaryMimeTypesArrayMap = new ConcurrentHashMap<String, String[]>(); } }
From source file:com.mirth.connect.connectors.ws.WebServiceDispatcher.java
@Override public void onDeploy() throws ConnectorTaskException { this.connectorProperties = (WebServiceDispatcherProperties) getConnectorProperties(); // load the default configuration String configurationClass = configurationController.getProperty(connectorProperties.getProtocol(), "wsConfigurationClass"); try {/*from w w w . java2 s. com*/ configuration = (WebServiceConfiguration) Class.forName(configurationClass).newInstance(); } catch (Exception e) { logger.trace("could not find custom configuration class, using default"); configuration = new DefaultWebServiceConfiguration(); } try { socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()); configuration.configureConnectorDeploy(this); } catch (Exception e) { throw new ConnectorTaskException(e); } timeout = NumberUtils.toInt(connectorProperties.getSocketTimeout()); }
From source file:org.dcache.srm.client.HttpClientSender.java
/** * Creates the registries of socket factories to be used to establish connection to SOAP servers. *///from w w w .j av a 2s.c om protected Registry<ConnectionSocketFactory> createSocketFactoryRegistry() { return RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", new FlexibleCredentialSSLConnectionSocketFactory(sslContextFactory, supportedProtocols, supportedCipherSuites, hostnameVerifier)) .build(); }
From source file:com.bosch.cr.examples.inventorybrowser.server.ProxyServlet.java
private synchronized CloseableHttpClient getHttpClient() { if (httpClient == null) { try {// w ww . j av a 2s . co m HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); // #### ONLY FOR TEST: Trust ANY certificate (self certified, any chain, ...) SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true) .build(); httpClientBuilder.setSSLContext(sslContext); // #### ONLY FOR TEST: Do NOT verify hostname SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslConnectionSocketFactory).build(); PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry); httpClientBuilder.setConnectionManager(httpClientConnectionManager); if (props.getProperty("http.proxyHost") != null) { httpClientBuilder.setProxy(new HttpHost(props.getProperty("http.proxyHost"), Integer.parseInt(props.getProperty("http.proxyPort")))); } httpClient = httpClientBuilder.build(); } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex) { throw new RuntimeException(ex); } } return httpClient; }
From source file:com.bosch.cr.examples.jwt.CustomProxyServlet.java
private synchronized CloseableHttpClient getHttpClient() { if (httpClient == null) { try {// ww w .j a va2 s . com final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); // #### ONLY FOR TEST: Trust ANY certificate (self certified, any chain, ...) final SSLContext sslContext = new SSLContextBuilder() .loadTrustMaterial(null, (chain, authType) -> true).build(); httpClientBuilder.setSSLContext(sslContext); // #### ONLY FOR TEST: Do NOT verify hostname final SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory( sslContext, NoopHostnameVerifier.INSTANCE); final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslConnectionSocketFactory).build(); final PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry); httpClientBuilder.setConnectionManager(httpClientConnectionManager); final boolean proxyEnabled = configurationProperties .getPropertyAsBoolean(ConfigurationProperty.PROXY_ENABLED); if (proxyEnabled) { final String proxyHost = configurationProperties .getPropertyAsString(ConfigurationProperty.PROXY_HOST); final int proxyPort = configurationProperties .getPropertyAsInt(ConfigurationProperty.PROXY_PORT); final HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpClientBuilder.setProxy(proxy); } httpClient = httpClientBuilder.build(); } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex) { throw new RuntimeException(ex); } } return httpClient; }
From source file:com.bosch.cr.integration.hello_world_ui.ProxyServlet.java
/** * Create http client/*from w ww . j av a2s. c om*/ */ private synchronized CloseableHttpClient getHttpClient() { if (httpClient == null) { try { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); // #### ONLY FOR TEST: Trust ANY certificate (self certified, any chain, ...) SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true) .build(); httpClientBuilder.setSSLContext(sslContext); // #### ONLY FOR TEST: Do NOT verify hostname SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslConnectionSocketFactory).build(); PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry); httpClientBuilder.setConnectionManager(httpClientConnectionManager); if (props.getProperty("http.proxyHost") != null) { httpClientBuilder.setProxy(new HttpHost(props.getProperty("http.proxyHost"), Integer.parseInt(props.getProperty("http.proxyPort")))); } if (props.getProperty("http.proxyUser") != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost), new UsernamePasswordCredentials( props.getProperty("http.proxyUser"), props.getProperty("http.proxyPwd"))); httpClientBuilder.setDefaultCredentialsProvider(credsProvider); } httpClient = httpClientBuilder.build(); } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex) { throw new RuntimeException(ex); } } return httpClient; }
From source file:org.sonatype.nexus.internal.httpclient.HttpClientFactoryImpl.java
private ManagedClientConnectionManager createClientConnectionManager(final List<SSLContextSelector> selectors) { final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", new NexusSSLConnectionSocketFactory( (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault(), SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER, selectors)) .build();//from www. j a v a 2s . co m final ManagedClientConnectionManager connManager = new ManagedClientConnectionManager(registry); final int maxConnectionCount = SystemPropertiesHelper.getInteger(CONNECTION_POOL_MAX_SIZE_KEY, CONNECTION_POOL_MAX_SIZE_DEFAULT); final int poolSize = SystemPropertiesHelper.getInteger(CONNECTION_POOL_SIZE_KEY, CONNECTION_POOL_SIZE_DEFAULT); final int perRouteConnectionCount = Math.min(poolSize, maxConnectionCount); connManager.setMaxTotal(maxConnectionCount); connManager.setDefaultMaxPerRoute(perRouteConnectionCount); return connManager; }
From source file:com.tremolosecurity.config.util.UnisonConfigManagerImpl.java
private void initSSL() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException, FileNotFoundException, IOException { if (this.getKeyManagerFactory() == null) { return;//w w w .j av a 2 s . c o m } KeyStore cacerts = KeyStore.getInstance(KeyStore.getDefaultType()); String cacertsPath = System.getProperty("javax.net.ssl.trustStore"); if (cacertsPath == null) { cacertsPath = System.getProperty("java.home") + "/lib/security/cacerts"; } cacerts.load(new FileInputStream(cacertsPath), null); Enumeration<String> enumer = cacerts.aliases(); while (enumer.hasMoreElements()) { String alias = enumer.nextElement(); java.security.cert.Certificate cert = cacerts.getCertificate(alias); this.ks.setCertificateEntry(alias, cert); } SSLContext sslctx = SSLContexts.custom().loadTrustMaterial(this.ks) .loadKeyMaterial(this.ks, this.cfg.getKeyStorePassword().toCharArray()).build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslctx, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); PlainConnectionSocketFactory sf = PlainConnectionSocketFactory.getSocketFactory(); httpClientRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", sf) .register("https", sslsf).build(); globalHttpClientConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES) .setRedirectsEnabled(false).setAuthenticationEnabled(false).build(); }
From source file:org.jboss.as.test.integration.management.http.HttpDeploymentUploadUnitTestCase.java
private CloseableHttpClient createHttpClient() { try {//from w ww.j a va 2s . c o m final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()).build(); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(managementClient.getMgmtAddress(), managementClient.getMgmtPort()), new UsernamePasswordCredentials(Authentication.USERNAME, Authentication.PASSWORD)); return HttpClientBuilder.create().setConnectionManager(new PoolingHttpClientConnectionManager(registry)) .setDefaultCredentialsProvider(credsProvider).build(); } catch (Exception e) { throw new RuntimeException(e); } }