List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager setMaxTotal
public void setMaxTotal(final int max)
From source file:org.openrepose.core.services.httpclient.impl.HttpConnectionPoolProvider.java
public static HttpClient genClient(PoolType poolConf) { PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); cm.setDefaultMaxPerRoute(poolConf.getHttpConnManagerMaxPerRoute()); cm.setMaxTotal(poolConf.getHttpConnManagerMaxTotal()); //Set all the params up front, instead of mutating them? Maybe this matters HttpParams params = new BasicHttpParams(); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, poolConf.getHttpSocketTimeout()); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, poolConf.getHttpConnectionTimeout()); params.setParameter(CoreConnectionPNames.TCP_NODELAY, poolConf.isHttpTcpNodelay()); params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, poolConf.getHttpConnectionMaxHeaderCount()); params.setParameter(CoreConnectionPNames.MAX_LINE_LENGTH, poolConf.getHttpConnectionMaxLineLength()); params.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, poolConf.getHttpSocketBufferSize()); params.setBooleanParameter(CHUNKED_ENCODING_PARAM, poolConf.isChunkedEncoding()); final String uuid = UUID.randomUUID().toString(); params.setParameter(CLIENT_INSTANCE_ID, uuid); //Pass in the params and the connection manager DefaultHttpClient client = new DefaultHttpClient(cm, params); SSLContext sslContext = ProxyUtilities.getTrustingSslContext(); SSLSocketFactory ssf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = cm.getSchemeRegistry(); Scheme scheme = new Scheme("https", DEFAULT_HTTPS_PORT, ssf); registry.register(scheme);//from ww w . j a va 2 s . com client.setKeepAliveStrategy(new ConnectionKeepAliveWithTimeoutStrategy(poolConf.getKeepaliveTimeout())); LOG.info("HTTP connection pool {} with instance id {} has been created", poolConf.getId(), uuid); return client; }
From source file:org.eclipse.aether.transport.http.GlobalState.java
public static ClientConnectionManager newConnectionManager(SslConfig sslConfig) { SchemeRegistry schemeReg = new SchemeRegistry(); schemeReg.register(new Scheme("http", 80, new PlainSocketFactory())); schemeReg.register(new Scheme("https", 443, new SslSocketFactory(sslConfig))); PoolingClientConnectionManager connMgr = new PoolingClientConnectionManager(schemeReg); connMgr.setMaxTotal(100); connMgr.setDefaultMaxPerRoute(50);/*from w w w . j a v a 2 s . com*/ return connMgr; }
From source file:org.fcrepo.federation.fedora3.itests.FedoraFederationIT.java
@BeforeClass public static void ingestTestObjects() throws FedoraClientException, MalformedURLException { PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); connectionManager.setMaxTotal(Integer.MAX_VALUE); connectionManager.setDefaultMaxPerRoute(5); connectionManager.closeIdleConnections(3, TimeUnit.SECONDS); client = new DefaultHttpClient(connectionManager); String fedoraUrl = "http://localhost:" + System.getProperty("servlet.port") + "/fedora"; fc = new FedoraClient(new FedoraCredentials(fedoraUrl, "fedoraAdmin", "fc")); pid = "it:1"; ingestFoxml(pid);//from w ww. ja va2 s .com dsid = "SIMPLE_TEXT"; }
From source file:com.amazonaws.http.ConnectionManagerFactory.java
public static PoolingClientConnectionManager createPoolingClientConnManager(ClientConfiguration config, HttpParams httpClientParams) {//from w w w.ja v a 2s .c o m PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager( SchemeRegistryFactory.createDefault(), config.getConnectionTTL(), TimeUnit.MILLISECONDS); connectionManager.setDefaultMaxPerRoute(config.getMaxConnections()); connectionManager.setMaxTotal(config.getMaxConnections()); if (config.useReaper()) { IdleConnectionReaper.registerConnectionManager(connectionManager); } return connectionManager; }
From source file:com.unboundid.scim.sdk.examples.ClientExample.java
/** * Create an SSL-enabled Wink client config from the provided information. * The returned client config may be used to create a SCIM service object. * IMPORTANT: This should not be used in production because no validation * is performed on the server certificate returned by the SCIM service. * * @param userName The HTTP Basic Auth user name. * @param password The HTTP Basic Auth password. * * @return An Apache Wink client config. *//* ww w . j a va2 s. c o m*/ public static ClientConfig createHttpBasicClientConfig(final String userName, final String password) { SSLSocketFactory sslSocketFactory; try { final SSLContext sslContext = SSLContext.getInstance("TLS"); // Do not use these settings in production. sslContext.init(null, new TrustManager[] { new BlindTrustManager() }, new SecureRandom()); sslSocketFactory = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (KeyManagementException e) { throw new RuntimeException(e.getLocalizedMessage()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getLocalizedMessage()); } final HttpParams params = new BasicHttpParams(); DefaultHttpClient.setDefaultHttpParams(params); params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, true); params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true); final SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, sslSocketFactory)); final PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(schemeRegistry); mgr.setMaxTotal(200); mgr.setDefaultMaxPerRoute(20); final DefaultHttpClient httpClient = new DefaultHttpClient(mgr, params); final Credentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); ClientConfig clientConfig = new ApacheHttpClientConfig(httpClient); clientConfig.setBypassHostnameVerification(true); return clientConfig; }
From source file:de.onyxbits.raccoon.gplay.PlayManager.java
/** * create a proxy client//from w w w . j ava 2 s .c o m * * @return either a client or null if none is configured * @throws KeyManagementException * @throws NumberFormatException * if that port could not be parsed. * @throws NoSuchAlgorithmException */ private static HttpClient createProxyClient(PlayProfile profile) throws KeyManagementException, NoSuchAlgorithmException { if (profile.getProxyAddress() == null) { return null; } PoolingClientConnectionManager connManager = new PoolingClientConnectionManager( SchemeRegistryFactory.createDefault()); connManager.setMaxTotal(100); connManager.setDefaultMaxPerRoute(30); DefaultHttpClient client = new DefaultHttpClient(connManager); client.getConnectionManager().getSchemeRegistry().register(Utils.getMockedScheme()); HttpHost proxy = new HttpHost(profile.getProxyAddress(), profile.getProxyPort()); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (profile.getProxyUser() != null && profile.getProxyPassword() != null) { client.getCredentialsProvider().setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(profile.getProxyUser(), profile.getProxyPassword())); } return client; }
From source file:com.base.httpclient.HttpJsonClient.java
/** * httpClient/*from w w w .ja v a2 s .co m*/ * @return */ public static DefaultHttpClient getHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); HttpParams httpParams = new BasicHttpParams(); cm.setMaxTotal(10);// cm.setDefaultMaxPerRoute(5);// ? HttpConnectionParams.setConnectionTimeout(httpParams, 60000);// HttpConnectionParams.setSoTimeout(httpParams, 60000);//? HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(httpParams, false); httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); DefaultHttpClient httpClient = new DefaultHttpClient(cm, httpParams); //httpClient.setCookieStore(null); httpClient.getCookieStore().clear(); httpClient.getCookieStore().getCookies().clear(); // httpClient.setHttpRequestRetryHandler(new HttpJsonClient().new HttpRequestRetry());//? return httpClient; }
From source file:com.aliyun.oss.common.comm.HttpClientFactory.java
public static PoolingClientConnectionManager createConnectionManager(ClientConfiguration config, HttpParams httpClientParams) {/* ww w. java 2s .c o m*/ PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager( SchemeRegistryFactory.createDefault(), config.getConnectionTTL(), TimeUnit.MILLISECONDS); connectionManager.setDefaultMaxPerRoute(config.getMaxConnections()); connectionManager.setMaxTotal(config.getMaxConnections()); if (config.isUseReaper()) { IdleConnectionReaper.registerConnectionManager(connectionManager); } return connectionManager; }
From source file:com.amazonaws.services.dynamodbv2.http.ConnectionManagerFactory.java
public static PoolingClientConnectionManager createPoolingClientConnManager(ClientConfiguration config, HttpParams httpClientParams) {/*from w ww. ja v a 2s . c o m*/ PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager( SchemeRegistryFactory.createDefault(), config.getConnectionTTL(), TimeUnit.MILLISECONDS, new DelegatingDnsResolver(config.getDnsResolver())); connectionManager.setDefaultMaxPerRoute(config.getMaxConnections()); connectionManager.setMaxTotal(config.getMaxConnections()); if (config.useReaper()) { IdleConnectionReaper.registerConnectionManager(connectionManager); } return connectionManager; }
From source file:com.google.apphosting.vmruntime.VmApiProxyDelegate.java
private static ClientConnectionManager createConnectionManager() { PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); connectionManager.setMaxTotal(VmApiProxyEnvironment.MAX_CONCURRENT_API_CALLS); connectionManager.setDefaultMaxPerRoute(VmApiProxyEnvironment.MAX_CONCURRENT_API_CALLS); return connectionManager; }