Example usage for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager

List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager

Introduction

In this page you can find the example usage for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager.

Prototype

public PoolingClientConnectionManager(final SchemeRegistry schreg) 

Source Link

Usage

From source file:org.apache.oozie.service.CallbackActionService.java

/**
 * Initializes the {@link CallbackActionService}.
 *
 * @param services services instance.//  www .  ja  v a  2  s.  c  om
 */
public void init(Services services) throws ServiceException {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    registry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    connectionManager = new PoolingClientConnectionManager(registry);
    connectionManager.setMaxTotal(ConfigurationService.getInt(POOL_SIZE));
}

From source file:com.telefonica.iot.tidoop.apiext.http.HttpClientFactory.java

/**
 * Constructor.//from   ww  w  . j av  a 2s  .c o m
 * @param ssl True if SSL connections are desired. False otherwise.
 */
public HttpClientFactory(boolean ssl) {
    // create the logger
    logger = Logger.getLogger(HttpClientFactory.class);

    if (ssl) {
        sslConnectionsManager = new PoolingClientConnectionManager(getSchemeRegistry());
        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("Setting default max connections per route (" + Constants.MAX_CONNS_PER_ROUTE + ")");
}

From source file:es.tid.fiware.fiwareconnectors.cygnus.http.HttpClientFactory.java

/**
 * Constructor./*from w w w. j  av a2s .c  o  m*/
 * @param ssl True if SSL connections are desired. False otherwise.
 */
public HttpClientFactory(boolean ssl) {
    // create the logger
    logger = Logger.getLogger(HttpClientFactory.class);

    if (ssl) {
        sslConnectionsManager = new PoolingClientConnectionManager(getSchemeRegistry());
        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:de.onyxbits.raccoon.gplay.PlayManager.java

/**
 * create a proxy client/*from  w ww  . j  av  a  2  s.  co 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.telefonica.iot.cosmos.hive.authprovider.HttpClientFactory.java

/**
 * Constructor./*w  w  w . ja  v a  2 s. c  o  m*/
 * @param ssl True if SSL connections are desired. False otherwise.
 */
public HttpClientFactory(boolean ssl) {
    // create the appropriate connections manager
    if (ssl) {
        sslConnectionsManager = new PoolingClientConnectionManager(getSSLSchemeRegistry());
        sslConnectionsManager.setMaxTotal(MAX_CONNS);
        sslConnectionsManager.setDefaultMaxPerRoute(MAX_CONNS_PER_ROUTE);
    } else {
        connectionsManager = new PoolingClientConnectionManager();
        connectionsManager.setMaxTotal(MAX_CONNS);
        connectionsManager.setDefaultMaxPerRoute(MAX_CONNS_PER_ROUTE);
    } // if else

    LOGGER.info("Setting max total connections (" + MAX_CONNS + ")");
    LOGGER.info("Setting default max connections per route (" + MAX_CONNS_PER_ROUTE + ")");
}

From source file:com.twitter.hbc.httpclient.RestartableHttpClient.java

public void setup() {
    DefaultHttpClient defaultClient = new DefaultHttpClient(new PoolingClientConnectionManager(schemeRegistry),
            params);/*  w  w w  . j  ava2  s .co m*/

    auth.setupConnection(defaultClient);

    if (enableGZip) {
        underlying.set(new DecompressingHttpClient(defaultClient));
    } else {
        underlying.set(defaultClient);
    }
}

From source file:cn.clxy.upload.ApacheHCUploader.java

/**
 * The timeout should be adjusted by network condition.
 * @return/*  w ww.  ja v  a  2  s .  c  o  m*/
 */
private static HttpClient createClient() {

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schReg.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schReg);
    ccm.setMaxTotal(Config.maxUpload);

    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
    HttpConnectionParams.setSoTimeout(params, Config.timeOut);

    return new DefaultHttpClient(ccm, params);
}

From source file:cn.clxy.codes.upload.ApacheHCUploader.java

/**
 * The timeout should be adjusted by network condition.
 * @return//from w  w  w .  j  a v a  2  s .  co m
 */
private static HttpClient createClient() {

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schReg.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schReg);
    ccm.setMaxTotal(Config.MAX_UPLOAD);

    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
    HttpConnectionParams.setSoTimeout(params, Config.PART_UPLOAD_TIMEOUT);

    return new DefaultHttpClient(ccm, params);
}

From source file:org.eclipse.lyo.oslc4j.bugzilla.utils.BugzillaHttpClient.java

private static HttpClient getHttpClient() {
    SSLContext sc = getTrustingSSLContext();
    SchemeSocketFactory sf = new SSLSocketFactory(sc);

    Scheme scheme = new Scheme("https", 443, sf);
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    schemeRegistry.register(scheme);/*w  w  w .  ja v  a2 s  .c  o  m*/

    sf = PlainSocketFactory.getSocketFactory();
    scheme = new Scheme("http", 80, sf);

    schemeRegistry.register(scheme);

    ClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager(schemeRegistry);
    HttpParams clientParams = new BasicHttpParams();

    clientParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT);
    clientParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT);
    clientParams.setParameter(ClientPNames.HANDLE_REDIRECTS, true);

    return new DefaultHttpClient(clientConnectionManager, clientParams);
}

From source file:com.almende.eve.transport.http.ApacheHttpClient.java

/**
 * Instantiates a new apache http client.
 *
 *//*from w w  w  .j  a v a  2s  .c  o  m*/
private ApacheHttpClient() {

    // Allow self-signed SSL certificates:
    final TrustStrategy trustStrategy = new TrustSelfSignedStrategy();
    final X509HostnameVerifier hostnameVerifier = new AllowAllHostnameVerifier();
    final SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();

    SSLSocketFactory sslSf;
    try {
        sslSf = new SSLSocketFactory(trustStrategy, hostnameVerifier);
        final Scheme https = new Scheme("https", 443, sslSf);
        schemeRegistry.register(https);
    } catch (Exception e) {
        LOG.warning("Couldn't init SSL socket, https not supported!");
    }

    // Work with PoolingClientConnectionManager
    final ClientConnectionManager connection = new PoolingClientConnectionManager(schemeRegistry);

    // Provide eviction thread to clear out stale threads.
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                while (true) {
                    synchronized (this) {
                        wait(5000);
                        connection.closeExpiredConnections();
                        connection.closeIdleConnections(30, TimeUnit.SECONDS);
                    }
                }
            } catch (final InterruptedException ex) {
            }
        }
    }).start();

    // generate httpclient
    httpClient = new DefaultHttpClient(connection);

    // Set cookie policy and persistent cookieStore
    try {
        httpClient.setCookieStore(new MyCookieStore());
    } catch (final Exception e) {
        LOG.log(Level.WARNING, "Failed to initialize persistent cookieStore!", e);
    }
    final HttpParams params = httpClient.getParams();

    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 60000);
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000);
    params.setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    params.setParameter(CoreConnectionPNames.TCP_NODELAY, true);
    httpClient.setParams(params);
}