List of usage examples for org.apache.http.impl.conn PoolingHttpClientConnectionManager setDefaultMaxPerRoute
public void setDefaultMaxPerRoute(final int max)
From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItem.java
private static PoolingHttpClientConnectionManager buildConnectionManager(HttpClientConfig config, SSLContext sslContext) {// w ww .ja v a 2 s . c om // scheme configuration ConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext); Registry<ConnectionSocketFactory> schemeRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build(); // pooling settings PoolingHttpClientConnectionManager conmgr = new PoolingHttpClientConnectionManager(schemeRegistry); conmgr.setMaxTotal(config.getMaxTotalConnections()); conmgr.setDefaultMaxPerRoute(config.getMaxConnectionsPerHost()); return conmgr; }
From source file:com.ibm.watson.app.common.util.http.HttpClientBuilder.java
public static CloseableHttpClient buildDefaultHttpClient(Credentials cred) { // Use custom cookie store if necessary. CookieStore cookieStore = new BasicCookieStore(); // Use custom credentials provider if necessary. CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); RequestConfig defaultRequestConfig;/*from w w w .j a v a 2 s . co m*/ //private DefaultHttpClient client; connManager.setMaxTotal(200); connManager.setDefaultMaxPerRoute(50); try { SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); // Create a registry of custom connection socket factories for supported // protocol schemes. Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLConnectionSocketFactory(builder.build())).build(); } catch (Exception e) { logger.warn(MessageKey.AQWEGA02000W_unable_init_ssl_context.getMessage(), e); } // Create global request configuration defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BEST_MATCH) .setExpectContinueEnabled(true) .setTargetPreferredAuthSchemes( Arrays.asList(AuthSchemes.BASIC, AuthSchemes.NTLM, AuthSchemes.DIGEST)) .setAuthenticationEnabled(true).build(); if (cred != null) credentialsProvider.setCredentials(AuthScope.ANY, cred); return HttpClients.custom().setConnectionManager(connManager).setDefaultCookieStore(cookieStore) .setDefaultCredentialsProvider(credentialsProvider).setDefaultRequestConfig(defaultRequestConfig) .build(); }
From source file:com.granita.icloudcalsync.webdav.DavHttpClient.java
@SuppressLint("LogTagMismatch") public static CloseableHttpClient create() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry);// w w w .j a va 2 s . c o m // limits per DavHttpClient (= per DavSyncAdapter extends AbstractThreadedSyncAdapter) connectionManager.setMaxTotal(3); // max. 3 connections in total connectionManager.setDefaultMaxPerRoute(2); // max. 2 connections per host HttpClientBuilder builder = HttpClients.custom().useSystemProperties() .setConnectionManager(connectionManager).setDefaultRequestConfig(defaultRqConfig) .setRetryHandler(DavHttpRequestRetryHandler.INSTANCE) .setRedirectStrategy(DavRedirectStrategy.INSTANCE) .setUserAgent("DAVdroid/" + Constants.APP_VERSION); if (Log.isLoggable("Wire", Log.DEBUG)) { Log.i(TAG, "Wire logging active, disabling HTTP compression"); builder = builder.disableContentCompression(); } return builder.build(); }
From source file:com.launchkey.sdk.LaunchKeyClient.java
private static Transport getTransport(Config config, Crypto crypto) { HttpClient httpClient;//from w w w. j av a 2s. c o m if (config.getApacheHttpClient() != null) { httpClient = config.getApacheHttpClient(); } else { int ttlSecs = config.getHttpClientConnectionTTLSecs() == null ? DEFAULT_HTTP_CLIENT_TTL_SECS : config.getHttpClientConnectionTTLSecs(); int maxClients = config.getHttpMaxClients() == null ? DEFAULT_HTTP_CLIENT_MAX_CLIENTS : config.getHttpMaxClients(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(ttlSecs, TimeUnit.SECONDS); connectionManager.setMaxTotal(maxClients); connectionManager.setDefaultMaxPerRoute(maxClients); // Set max per route as there is only one route httpClient = HttpClients.custom().setConnectionManager(connectionManager).build(); } String baseUrl = config.getAPIBaseURL() == null ? DEFAULT_API_BASE_URL : config.getAPIBaseURL(); return new ApacheHttpClientTransport(httpClient, baseUrl, crypto); }
From source file:ee.ria.xroad.common.opmonitoring.OpMonitoringDaemonHttpClient.java
/** * Creates HTTP client./* w w w . j a v a 2 s.c om*/ * @param authKey the client's authentication key * @param clientMaxTotalConnections client max total connections * @param clientMaxConnectionsPerRoute client max connections per route * @param connectionTimeoutMilliseconds connection timeout in milliseconds * @param socketTimeoutMilliseconds socket timeout in milliseconds * @return HTTP client * @throws Exception if creating a HTTPS client and SSLContext * initialization fails */ public static CloseableHttpClient createHttpClient(InternalSSLKey authKey, int clientMaxTotalConnections, int clientMaxConnectionsPerRoute, int connectionTimeoutMilliseconds, int socketTimeoutMilliseconds) throws Exception { log.trace("createHttpClient()"); RegistryBuilder<ConnectionSocketFactory> sfr = RegistryBuilder.<ConnectionSocketFactory>create(); if ("https".equalsIgnoreCase(OpMonitoringSystemProperties.getOpMonitorDaemonScheme())) { sfr.register("https", createSSLSocketFactory(authKey)); } else { sfr.register("http", PlainConnectionSocketFactory.INSTANCE); } PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(sfr.build()); cm.setMaxTotal(clientMaxTotalConnections); cm.setDefaultMaxPerRoute(clientMaxConnectionsPerRoute); cm.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).build()); RequestConfig.Builder rb = RequestConfig.custom().setConnectTimeout(connectionTimeoutMilliseconds) .setConnectionRequestTimeout(connectionTimeoutMilliseconds) .setSocketTimeout(socketTimeoutMilliseconds); HttpClientBuilder cb = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(rb.build()); // Disable request retry cb.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); return cb.build(); }
From source file:fr.treeptik.cloudunit.docker.JSONClient.java
private static HttpClientConnectionManager getConnectionFactory(String certPath, int maxConnections) throws IOException { PoolingHttpClientConnectionManager ret = new PoolingHttpClientConnectionManager( getSslFactoryRegistry(certPath)); ret.setDefaultMaxPerRoute(maxConnections); return ret;/*from w ww . j av a 2s. co m*/ }
From source file:com.pearson.pdn.demos.chainoflearning.EventingUtility.java
static void init() { if (client == null) { PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setDefaultMaxPerRoute(50); cm.setMaxTotal(100);// w w w.j a v a 2 s. c om client = HttpClientBuilder.create().setConnectionManager(cm).build(); } }
From source file:com.spectralogic.ds3client.NetworkClientImpl.java
private static CloseableHttpClient createDefaultClient(final ConnectionDetails connectionDetails) { final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setDefaultMaxPerRoute(MAX_CONNECTION_PER_ROUTE); connectionManager.setMaxTotal(MAX_CONNECTION_TOTAL); if (connectionDetails.isHttps() && !connectionDetails.isCertificateVerification()) { try {/*from www . j a va2 s. c om*/ final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { return true; } }).useTLS().build(); final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier()); return HttpClients.custom().setConnectionManager(connectionManager).setSSLSocketFactory(sslsf) .build(); } catch (final NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { throw new SSLSetupException(e); } } else { return HttpClients.custom().setConnectionManager(connectionManager).build(); } }
From source file:ee.ria.xroad.common.request.ManagementRequestClient.java
private static CloseableHttpClient createHttpClient(KeyManager km, TrustManager tm) throws Exception { RegistryBuilder<ConnectionSocketFactory> sfr = RegistryBuilder.<ConnectionSocketFactory>create(); sfr.register("http", PlainConnectionSocketFactory.INSTANCE); SSLContext ctx = SSLContext.getInstance(CryptoUtils.SSL_PROTOCOL); ctx.init(km != null ? new KeyManager[] { km } : null, tm != null ? new TrustManager[] { tm } : null, new SecureRandom()); SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(ctx, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); sfr.register("https", sf); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(sfr.build()); cm.setMaxTotal(CLIENT_MAX_TOTAL_CONNECTIONS); cm.setDefaultMaxPerRoute(CLIENT_MAX_CONNECTIONS_PER_ROUTE); int timeout = SystemProperties.getClientProxyTimeout(); int socketTimeout = SystemProperties.getClientProxyHttpClientTimeout(); RequestConfig.Builder rb = RequestConfig.custom(); rb.setConnectTimeout(timeout);/*from www. j a v a2 s . c om*/ rb.setConnectionRequestTimeout(timeout); rb.setSocketTimeout(socketTimeout); HttpClientBuilder cb = HttpClients.custom(); cb.setConnectionManager(cm); cb.setDefaultRequestConfig(rb.build()); // Disable request retry cb.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); return cb.build(); }
From source file:com.moviejukebox.tools.YamjHttpClientBuilder.java
@SuppressWarnings("resource") private static YamjHttpClient buildHttpClient() { LOG.trace("Create new YAMJ http client"); // create proxy HttpHost proxy = null;/*from w ww .ja v a 2s. c o m*/ CredentialsProvider credentialsProvider = null; if (StringUtils.isNotBlank(PROXY_HOST) && PROXY_PORT > 0) { proxy = new HttpHost(PROXY_HOST, PROXY_PORT); if (StringUtils.isNotBlank(PROXY_USERNAME) && StringUtils.isNotBlank(PROXY_PASSWORD)) { credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(PROXY_HOST, PROXY_PORT), new UsernamePasswordCredentials(PROXY_USERNAME, PROXY_PASSWORD)); } } PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); connManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT_SOCKET).build()); connManager.setMaxTotal(20); connManager.setDefaultMaxPerRoute(2); CacheConfig cacheConfig = CacheConfig.custom().setMaxCacheEntries(1000).setMaxObjectSize(8192).build(); HttpClientBuilder builder = CachingHttpClientBuilder.create().setCacheConfig(cacheConfig) .setConnectionManager(connManager).setProxy(proxy) .setDefaultCredentialsProvider(credentialsProvider) .setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(TIMEOUT_READ) .setConnectTimeout(TIMEOUT_CONNECT).setSocketTimeout(TIMEOUT_SOCKET) .setCookieSpec(CookieSpecs.IGNORE_COOKIES).setProxy(proxy).build()); // show status showStatus(); // build the client YamjHttpClient wrapper = new YamjHttpClient(builder.build(), connManager); wrapper.setUserAgentSelector(new WebBrowserUserAgentSelector()); wrapper.addGroupLimit(".*", 1); // default limit, can be overwritten // First we have to read/create the rules String maxDownloadSlots = PropertiesUtil.getProperty("mjb.MaxDownloadSlots"); if (StringUtils.isNotBlank(maxDownloadSlots)) { LOG.debug("Using download limits: {}", maxDownloadSlots); Pattern pattern = Pattern.compile(",?\\s*([^=]+)=(\\d+)"); Matcher matcher = pattern.matcher(maxDownloadSlots); while (matcher.find()) { String group = matcher.group(1); try { final Integer maxResults = Integer.valueOf(matcher.group(2)); wrapper.addGroupLimit(group, maxResults); LOG.trace("Added download slot '{}' with max results {}", group, maxResults); } catch (NumberFormatException error) { LOG.debug("Rule '{}' is no valid regexp, ignored", group); } } } return wrapper; }