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:com.nebkat.junglist.bot.http.ConnectionManager.java

public static HttpClient getHttpClient() {
    if (sHttpClient == null) {
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
        schemeRegistry.register(new Scheme("https", 443, new EasySSLSocketFactory()));

        HttpParams params = new BasicHttpParams();
        params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
        connectionManager.setDefaultMaxPerRoute(30);
        connectionManager.setMaxTotal(30);

        sHttpClient = new DefaultHttpClient(connectionManager, params);

        ((DefaultHttpClient) sHttpClient).addResponseInterceptor((response, context) -> {
            if (response.containsHeader("Location")) {
                context.setAttribute(REDIRECTED, true);
            }/*from www. j  a va  2 s .c  o  m*/
        });
    }
    return sHttpClient;
}

From source file:com.liferay.portal.search.solr.http.CertAuthPoolingHttpClientFactory.java

@Override
protected PoolingClientConnectionManager createPoolingClientConnectionManager() throws Exception {

    SSLSocketFactory sslSocketFactory = _sslSocketFactoryBuilder.build();

    SchemeRegistry schemeRegistry = createSchemeRegistry(sslSocketFactory);

    return new PoolingClientConnectionManager(schemeRegistry);
}

From source file:org.apache.activemq.transport.https.HttpsClientTransport.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(
            createSchemeRegistry());// w ww  .  ja  v a  2  s  .  com
    return connectionManager;
}

From source file:com.googlesource.gerrit.plugins.github.oauth.GitHubHttpProvider.java

public GitHubHttpProvider() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    connectionManager = new PoolingClientConnectionManager(schemeRegistry);
    connectionManager.setMaxTotal(MAX_TOTAL_CONN);
    connectionManager.setDefaultMaxPerRoute(MAX_CONN_PER_ROUTE);
    HttpHost localhost = new HttpHost("locahost", 80);
    connectionManager.setMaxPerRoute(new HttpRoute(localhost), MAX_LOCALHOST_CONN);
}

From source file:com.lonepulse.zombielink.executor.ZombieConfig.java

@Override
public HttpClient httpClient() {

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));

    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setSoTimeout(params, 2 * 1000); //to simulate a socket timeout

    return new DefaultHttpClient(new PoolingClientConnectionManager(schemeRegistry), params);
}

From source file:org.ow2.proactive.scheduler.rest.utils.HttpUtility.java

public static HttpClient threadSafeClient() {
    DefaultHttpClient client = new DefaultHttpClient();
    ClientConnectionManager mgr = client.getConnectionManager();
    HttpParams params = client.getParams();
    client = new DefaultHttpClient(new PoolingClientConnectionManager(mgr.getSchemeRegistry()), params);
    return client;
}

From source file:piecework.client.LoadTester.java

public LoadTester(KeyStore keystore, SecuritySettings securitySettings) {
    ClientConnectionManager cm;/*from   w  w w .j a va  2  s  . co  m*/
    try {
        SSLSocketFactory sslSocketFactory = new SSLSocketFactory(keystore,
                new String(securitySettings.getKeystorePassword()));
        X509HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
        sslSocketFactory.setHostnameVerifier(hostnameVerifier);

        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("https", 8443, sslSocketFactory));

        cm = new PoolingClientConnectionManager(schemeRegistry);
    } catch (Exception e) {
        cm = new BasicClientConnectionManager();
    }
    this.client = new DefaultHttpClient(cm);
}

From source file:com.base.httpclient.HttpJsonClient.java

/**
 * httpClient/*  w  ww .  j  a  v  a 2  s.c o 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:org.oss.bonita.utils.bonita.RestClient.java

public RestClient(String bonitaURI) {
    this.bonitaURI = bonitaURI;
    this.httpContext = new BasicHttpContext();
    PoolingClientConnectionManager conMan = new PoolingClientConnectionManager(
            SchemeRegistryFactory.createDefault());
    conMan.setMaxTotal(200);/*  w  w  w  .java 2 s  .c o m*/
    conMan.setDefaultMaxPerRoute(200);
    this.httpClient = new DefaultHttpClient(conMan);
}

From source file:com.almende.reaal.apachehttp.ApacheHttpClient.java

/**
 * Instantiates a new apache http client.
 *
 *//*from  w w  w  . j  a  v  a  2 s .c om*/
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);

    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);
}