Example usage for org.apache.http.conn.params ConnPerRouteBean setMaxForRoute

List of usage examples for org.apache.http.conn.params ConnPerRouteBean setMaxForRoute

Introduction

In this page you can find the example usage for org.apache.http.conn.params ConnPerRouteBean setMaxForRoute.

Prototype

public void setMaxForRoute(final HttpRoute route, final int max) 

Source Link

Usage

From source file:net.ecfirm.ec.ec1.net.EcNetHelper.java

public static DefaultHttpClient getThreadSafeClient() {
    DefaultHttpClient client = new DefaultHttpClient();
    ClientConnectionManager mgr = client.getConnectionManager();
    /////////*from  ww w . jav a 2 s .  co m*/
    client.getParams().setParameter("http.protocol.expect-continue", false);
    client.getParams().setParameter("http.connection.timeout", EcConst.NET_HTTP_CONN_TIMEOUT);
    //client.getParams().setParameter("http.socket.timeout", );
    ////////
    HttpParams params = client.getParams();
    ////////
    ConnManagerParams.setMaxTotalConnections(params, EcConst.NET_HTTP_CONN);
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(EcConst.NET_HTTP_CONN_PER_ROUTE);
    HttpHost localhost = new HttpHost("localhost", 80);
    connPerRoute.setMaxForRoute(new HttpRoute(localhost), EcConst.NET_HTTP_CONN_PER_ROUTE);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
    mgr.getSchemeRegistry().register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    mgr.getSchemeRegistry().register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ////////
    client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);
    return client;
}

From source file:com.bbxiaoqu.api.AndroidHttpClient.java

/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 *
 * @param userAgent to report in your HTTP requests
 * @param context to use for caching SSL sessions (may be null for no caching)
 * @return AndroidHttpClient for you to use for all your requests.
 *//* w w  w.  j a  v a2  s  .  c o  m*/
public static AndroidHttpClient newInstance(String userAgent, Context context) {
    HttpParams params = new BasicHttpParams();

    // Turn off stale checking.  Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // Default connection and socket timeout of 20 seconds.  Tweak to taste.
    HttpConnectionParams.setConnectionTimeout(params, 20000);
    HttpConnectionParams.setSoTimeout(params, 20000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Increase max total connection to 60
    ConnManagerParams.setMaxTotalConnections(params, 60);
    // Increase default max connection per route to 20
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(20);
    // Increase max connections for localhost:80 to 20
    HttpHost localhost = new HttpHost("locahost", 80);
    connPerRoute.setMaxForRoute(new HttpRoute(localhost), 20);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);

    // Don't handle redirects -- return them to the caller.  Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);

    // Use a session cache for SSL sockets
    //        SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);
    //        SSLCertificateSocketFactory.getDefault (30 * 1000);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

    // We use a factory method to modify superclass initialization
    // parameters without the funny call-a-static-method dance.
    return new AndroidHttpClient(manager, params);
}

From source file:com.appassit.http.AndroidHttpClient.java

/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 * //w w w  .  ja v  a 2 s.com
 * @param userAgent
 *            to report in your HTTP requests
 * @param context
 *            to use for caching SSL sessions (may be null for no caching)
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent, Context context) {
    HttpParams params = new BasicHttpParams();
    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // Default connection and socket timeout of 20 seconds. Tweak to taste.
    HttpConnectionParams.setConnectionTimeout(params, 20000);
    HttpConnectionParams.setSoTimeout(params, 20000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Increase max total connection to 60
    ConnManagerParams.setMaxTotalConnections(params, 60);
    // Increase default max connection per route to 20
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(20);
    // Increase max connections for localhost:80 to 20
    HttpHost localhost = new HttpHost("locahost", 80);
    connPerRoute.setMaxForRoute(new HttpRoute(localhost), 20);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);

    // Don't handle redirects -- return them to the caller. Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);

    // Use a session cache for SSL sockets
    // SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);
    // SSLCertificateSocketFactory.getDefault (30 * 1000);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

    // We use a factory method to modify superclass initialization
    // parameters without the funny call-a-static-method dance.
    return new AndroidHttpClient(manager, params);
}

From source file:ro.zg.netcell.connectors.HttpConnectionManager.java

private void initHttpClient() {
    ConfigurationData cfgData = dataSourceDefinition.getConfigData();

    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, Integer
            .parseInt(cfgData.getParameterValue(DataSourceConfigParameters.MAX_TOTAL_CONNECTIONS).toString()));
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(10);
    HttpHost localhost = new HttpHost("locahost", 80);
    connPerRoute.setMaxForRoute(new HttpRoute(localhost), 50);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
    ConnManagerParams.setTimeout(params, Long
            .parseLong(cfgData.getParameterValue(DataSourceConfigParameters.CONNECTION_TIMEOUT).toString()));

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

    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);

    /* set config params */
    ConfigurationData configData = dataSourceDefinition.getConfigData();
    Map<String, UserInputParameter> userInputParams = configData.getUserInputParams();
    for (UserInputParameter uip : userInputParams.values()) {
        params.setParameter(uip.getInnerName(), uip.getValue());
    }/*from   ww  w .  jav  a  2  s  . c o m*/

    HttpConnectionParams.setSoTimeout(params, 25000);
    httpClient = new DefaultHttpClient(cm, params);

}

From source file:org.onsteroids.eve.api.connector.http.PooledHttpApiConnection.java

/**
 * Initializses and configures the http client connection pool.
 *///w w  w.j  a v  a2s .  co  m
private void initializeHttpClient() {
    LOG.debug("Configuring the HttpClientPool with a maximum of {} connections", maxConnections);
    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, maxConnections);
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(maxConnections);
    HttpHost serverHost = new HttpHost(serverUri.getHost(), serverUri.getPort());
    connPerRoute.setMaxForRoute(new HttpRoute(serverHost), maxConnections);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);

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

    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    httpClient = new DefaultHttpClient(cm, params);
}

From source file:org.mulgara.scon.Connection.java

/**
 * Set up some basic properties for a thread-safe client connection factory.
 * @return A new connection manager// ww w  . j a v  a  2s  .  c o m
 */
private ClientConnectionManager getConnectionManager() {
    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, 200);
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(20);

    int port = endpoint.getPort();
    if (port == -1)
        port = endpoint.getDefaultPort();
    HttpHost host = new HttpHost(endpoint.getHost(), port);

    connPerRoute.setMaxForRoute(new HttpRoute(host), 50);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    return new ThreadSafeClientConnManager(params, schemeRegistry);
}