List of usage examples for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager( final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory)
From source file:com.tremolosecurity.provisioning.core.providers.TremoloTarget.java
@Override public void init(Map<String, Attribute> cfg, ConfigManager cfgMgr, String name) throws ProvisioningException { this.name = name; this.cfgMgr = cfgMgr; if (cfg.get("createUsersWF") == null) { throw new ProvisioningException("Create user workflow not specified"); }/*from ww w .j ava 2s . c o m*/ this.createUserWF = cfg.get("createUsersWF").getValues().get(0); if (cfg.get("deleteUserWF") == null) { throw new ProvisioningException("Delete user workflow not specified"); } this.deleteUserWF = cfg.get("deleteUserWF").getValues().get(0); if (cfg.get("setUserPasswordWF") == null) { throw new ProvisioningException("Set user password workflow not specified"); } this.setUserPasswordWF = cfg.get("setUserPasswordWF").getValues().get(0); if (cfg.get("syncUserWF") == null) { throw new ProvisioningException("Synchronize user workflow not specified"); } this.syncUserWF = cfg.get("syncUserWF").getValues().get(0); if (cfg.get("uidAttrName") == null) { throw new ProvisioningException("User identifier attribute name not found"); } this.uidAttrName = cfg.get("uidAttrName").getValues().get(0); if (cfg.get("wfUrlBase") == null) { throw new ProvisioningException("WorkflowImpl URL base not specified"); } this.wfUrlBase = cfg.get("wfUrlBase").getValues().get(0); try { URL url = new URL(this.wfUrlBase); if (url.getPort() > 0) { this.port = url.getPort(); } else { this.port = 443; } } catch (MalformedURLException e) { throw new ProvisioningException("Could not configure target", e); } phcm = new PoolingHttpClientConnectionManager(cfgMgr.getHttpClientSocketRegistry()); httpclient = HttpClients.custom().setConnectionManager(phcm).build(); }
From source file:com.helger.pd.client.jdk6.PDClient.java
@Nonnull protected HttpClientBuilder createClientBuilder() { SSLConnectionSocketFactory aSSLSocketFactory = null; try {//from w w w. jav a2 s .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.tremolosecurity.scale.config.ScaleCommonConfig.java
public HttpClientInfo createHttpClientInfo() { SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslctx, new AllowAllHostnameVerifier()); PlainConnectionSocketFactory sf = PlainConnectionSocketFactory.getSocketFactory(); Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create().register("http", sf) .register("https", sslsf).build(); RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY) .setRedirectsEnabled(true).build(); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(r); return new HttpClientInfo(cm, globalConfig); }
From source file:eu.europa.esig.dss.client.http.commons.CommonsDataLoader.java
private HttpClientConnectionManager getConnectionManager() throws DSSException { RegistryBuilder<ConnectionSocketFactory> socketFactoryRegistryBuilder = RegistryBuilder.create(); socketFactoryRegistryBuilder = setConnectionManagerSchemeHttp(socketFactoryRegistryBuilder); socketFactoryRegistryBuilder = setConnectionManagerSchemeHttps(socketFactoryRegistryBuilder); final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( socketFactoryRegistryBuilder.build()); connectionManager.setMaxTotal(getConnectionsMaxTotal()); connectionManager.setDefaultMaxPerRoute(getConnectionsMaxPerRoute()); LOG.debug("PoolingHttpClientConnectionManager: max total: " + connectionManager.getMaxTotal()); LOG.debug(/*from w w w . j a v a 2s . c o m*/ "PoolingHttpClientConnectionManager: max per route: " + connectionManager.getDefaultMaxPerRoute()); return connectionManager; }
From source file:com.bosch.cr.examples.inventorybrowser.server.ProxyServlet.java
private synchronized CloseableHttpClient getHttpClient() { if (httpClient == null) { try {// w ww . j a va 2s . c o 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 {//from w ww . j a v a 2 s . c o m 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:org.dcache.srm.client.HttpClientSender.java
/** * Creates the connection manager to be used to manage connections to SOAP servers. *//* w w w .j av a 2 s. c o m*/ protected PoolingHttpClientConnectionManager createConnectionManager() { PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager( createSocketFactoryRegistry()); cm.setMaxTotal(clientProperties.getMaximumTotalConnections()); cm.setDefaultMaxPerRoute(clientProperties.getMaximumConnectionsPerHost()); SocketConfig.Builder socketOptions = SocketConfig.custom(); if (clientProperties.getDefaultSoTimeout() > 0) { socketOptions.setSoTimeout(clientProperties.getDefaultSoTimeout()); } cm.setDefaultSocketConfig(socketOptions.build()); return cm; }
From source file:com.bosch.cr.integration.hello_world_ui.ProxyServlet.java
/** * Create http client/*ww w.j ava 2 s. 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.apache.solr.client.solrj.impl.HttpClientUtil.java
/** test usage subject to change @lucene.experimental */ static PoolingHttpClientConnectionManager createPoolingConnectionManager() { return new PoolingHttpClientConnectionManager(schemaRegistryProvider.getSchemaRegistry()); }