List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager
public PoolingClientConnectionManager(final SchemeRegistry schreg)
From source file:org.n52.oxf.util.web.PoolingConnectionManagerHttpClient.java
@Override public ClientConnectionManager getConnectionManager() { PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); // Increase max total connection to 200 cm.setMaxTotal(200);// w w w. j a v a 2 s . c om // Increase default max connection per route to 20 cm.setDefaultMaxPerRoute(20); // Increase max connections for localhost:80 to 50 HttpHost localhost8080 = new HttpHost("localhost", 8080); cm.setMaxPerRoute(new HttpRoute(localhost8080), 50); HttpHost localhost = new HttpHost("localhost", 80); cm.setMaxPerRoute(new HttpRoute(localhost), 50); return cm; }
From source file:com.impetus.client.couchdb.utils.CouchDBTestUtils.java
/** * Initiate http client.//from w w w .j a va2s . c om * * @param kunderaMetadata * the kundera metadata * @param persistenceUnit * the persistence unit * @return the http client */ public static HttpClient initiateHttpClient(final KunderaMetadata kunderaMetadata, String persistenceUnit) { PersistenceUnitMetadata pumMetadata = KunderaMetadataManager.getPersistenceUnitMetadata(kunderaMetadata, persistenceUnit); SchemeSocketFactory ssf = null; ssf = PlainSocketFactory.getSocketFactory(); SchemeRegistry schemeRegistry = new SchemeRegistry(); int port = Integer.parseInt(pumMetadata.getProperty(PersistenceProperties.KUNDERA_PORT)); String host = pumMetadata.getProperty(PersistenceProperties.KUNDERA_NODES); String userName = pumMetadata.getProperty(PersistenceProperties.KUNDERA_USERNAME); String password = pumMetadata.getProperty(PersistenceProperties.KUNDERA_PASSWORD); schemeRegistry.register(new Scheme("http", port, ssf)); PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schemeRegistry); HttpClient httpClient = new DefaultHttpClient(ccm); try { // Http params httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); // basic authentication if (userName != null && password != null) { ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(userName, password)); } // request interceptor ((DefaultHttpClient) httpClient).addRequestInterceptor(new HttpRequestInterceptor() { public void process(final HttpRequest request, final HttpContext context) throws IOException { } }); // response interceptor ((DefaultHttpClient) httpClient).addResponseInterceptor(new HttpResponseInterceptor() { public void process(final HttpResponse response, final HttpContext context) throws IOException { } }); } catch (Exception e) { throw new IllegalStateException(e); } return httpClient; }
From source file:co.forsaken.api.json.JsonWebCall.java
public JsonWebCall(String url) { _url = url;//ww w. j a v a 2s. c om SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); _connectionManager = new PoolingClientConnectionManager(schemeRegistry); _connectionManager.setMaxTotal(200); _connectionManager.setDefaultMaxPerRoute(20); }
From source file:com.twitter.hbc.httpclient.BasicClient.java
public BasicClient(String name, Hosts hosts, StreamingEndpoint endpoint, Authentication auth, boolean enableGZip, HosebirdMessageProcessor processor, ReconnectionManager reconnectionManager, RateTracker rateTracker, ExecutorService executorService, @Nullable BlockingQueue<Event> eventsQueue, HttpParams params, SchemeRegistry schemeRegistry) { Preconditions.checkNotNull(auth);//from w w w.j a va 2 s. c o m HttpClient client; if (enableGZip) { client = new RestartableHttpClient(auth, enableGZip, params, schemeRegistry); } else { DefaultHttpClient defaultClient = new DefaultHttpClient( new PoolingClientConnectionManager(schemeRegistry), params); /** Set auth **/ auth.setupConnection(defaultClient); client = defaultClient; } this.canRun = new AtomicBoolean(true); this.executorService = executorService; this.clientBase = new ClientBase(name, client, hosts, endpoint, auth, processor, reconnectionManager, rateTracker, eventsQueue); }
From source file:com.telefonica.iot.cygnus.backends.http.HttpClientFactory.java
/** * Constructor.//w ww. j a v a 2 s . c o m * @param ssl True if SSL connections are desired. False otherwise. * @param loginConfFile * @param krb5ConfFile */ public HttpClientFactory(boolean ssl, String loginConfFile, String krb5ConfFile) { // set the Kerberos parameters this.loginConfFile = loginConfFile; this.krb5ConfFile = krb5ConfFile; // create the appropriate connections manager if (ssl) { sslConnectionsManager = new PoolingClientConnectionManager(getSSLSchemeRegistry()); sslConnectionsManager.setMaxTotal(Constants.MAX_CONNS); sslConnectionsManager.setDefaultMaxPerRoute(Constants.MAX_CONNS_PER_ROUTE); } else { connectionsManager = new PoolingClientConnectionManager(); connectionsManager.setMaxTotal(Constants.MAX_CONNS); connectionsManager.setDefaultMaxPerRoute(Constants.MAX_CONNS_PER_ROUTE); } // if else LOGGER.info("Setting max total connections (" + Constants.MAX_CONNS + ")"); LOGGER.info("Settubg default max connections per route (" + Constants.MAX_CONNS_PER_ROUTE + ")"); }
From source file:gr.wavesoft.webng.io.web.WebStreams.java
public static void Initialize() { schemeRegistry = new SchemeRegistry(); // Register HTTP schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); // Register HTTPS with WebNG Extensions try {// w w w .java 2 s. c om schemeRegistry.register(new Scheme("https", 443, new SSLSocketFactory(WebNGKeyStore.getKeyStore()))); } catch (NoSuchAlgorithmException ex) { systemLogger.except(ex); } catch (KeyManagementException ex) { systemLogger.except(ex); } catch (KeyStoreException ex) { systemLogger.except(ex); } catch (UnrecoverableKeyException ex) { systemLogger.except(ex); } // Setup connection manager connectionManager = new PoolingClientConnectionManager(schemeRegistry); // Increase max total connection to 200 connectionManager.setMaxTotal(200); // Increase default max connection per route to 20 connectionManager.setDefaultMaxPerRoute(20); // Increase max connections for localhost:80 to 50 HttpHost localhost = new HttpHost("locahost", 80); connectionManager.setMaxPerRoute(new HttpRoute(localhost), 50); // Setup http client httpClient = new DefaultHttpClient(connectionManager); // Setup cookie cache //((DefaultHttpClient)httpClient).setCookieStore(WebNGCache.instanceCookieCache()); // Setup cache CacheConfig cacheConfig = new CacheConfig(); cacheConfig.setMaxCacheEntries(WebNGCache.config.MAX_ENTRIES_MEM); cacheConfig.setMaxObjectSize(WebNGCache.config.MAX_OBJECT_SIZE); cachingClient = new CachingHttpClient(httpClient, WebNGCache.instanceDiskCacheStorage(), cacheConfig); }
From source file:org.apache.chemistry.opencmis.client.bindings.spi.http.ApacheClientHttpInvoker.java
@Override protected DefaultHttpClient createHttpClient(UrlBuilder url, BindingSession session) { // set params HttpParams params = createDefaultHttpParams(session); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); // set up scheme registry and connection manager SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); registry.register(new Scheme("https", 443, getSSLSocketFactory(url, session))); // set up connection manager PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(registry); // set max connection a String keepAliveStr = System.getProperty("http.keepAlive", "true"); if ("true".equalsIgnoreCase(keepAliveStr)) { String maxConnStr = System.getProperty("http.maxConnections", "5"); int maxConn = 5; try {/*from ww w . j a va 2s.c om*/ maxConn = Integer.parseInt(maxConnStr); } catch (NumberFormatException nfe) { // ignore } connManager.setDefaultMaxPerRoute(maxConn); connManager.setMaxTotal(4 * maxConn); } // set up proxy ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(registry, null); // set up client DefaultHttpClient httpclient = new DefaultHttpClient(connManager, params); httpclient.setRoutePlanner(routePlanner); return httpclient; }
From source file:com.lonepulse.zombielink.executor.ConfigurationService.java
/** * <p>The <i>out-of-the-box</i> configuration for an instance of {@link HttpClient} which will be used * for executing all endpoint requests. Below is a detailed description of all configured properties.</p> * <br>//w w w. java 2 s . com * <ul> * <li> * <p><b>HttpClient</b></p> * <br> * <p>It registers two {@link Scheme}s:</p> * <br> * <ol> * <li><b>HTTP</b> on port <b>80</b> using sockets from {@link PlainSocketFactory#getSocketFactory}</li> * <li><b>HTTPS</b> on port <b>443</b> using sockets from {@link SSLSocketFactory#getSocketFactory}</li> * </ol> * * <p>It uses a {@link PoolingClientConnectionManager} with the maximum number of client connections * per route set to <b>4</b> and the total set to <b>128</b>.</p> * </li> * </ul> * @return the instance of {@link HttpClient} which will be used for request execution * <br><br> * @since 1.3.0 */ @Override public Configuration getDefault() { return new Configuration() { @Override public HttpClient httpClient() { try { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager pccm = new PoolingClientConnectionManager(schemeRegistry); pccm.setMaxTotal(200); pccm.setDefaultMaxPerRoute(20); return new DefaultHttpClient(pccm); } catch (Exception e) { throw new ConfigurationFailedException(e); } } }; }
From source file:org.xdi.net.SslDefaultHttpClient.java
@Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); // Register for port 443 our SSLSocketFactory with our keystore to the ConnectionManager registry.register(new Scheme("https", 443, newSslSocketFactory())); return new PoolingClientConnectionManager(registry); }
From source file:com.google.appengine.tck.teamcity.ReportsFeature.java
public void start() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, new PlainSocketFactory())); registry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); ClientConnectionManager ccm = new PoolingClientConnectionManager(registry); client = new DefaultHttpClient(ccm); }