Search in sources :

Example 1 with ConnPerRouteBean

use of org.apache.http.conn.params.ConnPerRouteBean in project Libraries-for-Android-Developers by eoecn.

the class AsyncHttpClient method setMaxConnections.

/**
     * Sets maximum limit of parallel connections
     *
     * @param maxConnections maximum parallel connections, must be at least 1
     */
public void setMaxConnections(int maxConnections) {
    if (maxConnections < 1)
        maxConnections = DEFAULT_MAX_CONNECTIONS;
    this.maxConnections = maxConnections;
    final HttpParams httpParams = this.httpClient.getParams();
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(this.maxConnections));
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) ConnPerRouteBean(org.apache.http.conn.params.ConnPerRouteBean)

Example 2 with ConnPerRouteBean

use of org.apache.http.conn.params.ConnPerRouteBean in project SmartAndroidSource by jaychou2012.

the class AbstractAjaxCallback method getClient.

private static DefaultHttpClient getClient() {
    if (client == null || !REUSE_CLIENT) {
        AQUtility.debug("creating http client");
        HttpParams httpParams = new BasicHttpParams();
        //httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        HttpConnectionParams.setConnectionTimeout(httpParams, NET_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParams, NET_TIMEOUT);
        //ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(NETWORK_POOL));
        ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(25));
        //Added this line to avoid issue at: http://stackoverflow.com/questions/5358014/android-httpclient-oom-on-4g-lte-htc-thunderbolt
        HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", ssf == null ? SSLSocketFactory.getSocketFactory() : ssf, 443));
        ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, registry);
        client = new DefaultHttpClient(cm, httpParams);
    }
    return client;
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) BasicHttpParams(org.apache.http.params.BasicHttpParams) ConnPerRouteBean(org.apache.http.conn.params.ConnPerRouteBean) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 3 with ConnPerRouteBean

use of org.apache.http.conn.params.ConnPerRouteBean in project SmartAndroidSource by jaychou2012.

the class AsyncHttpClient method setMaxConnections.

/**
	 * Sets maximum limit of parallel connections
	 * 
	 * @param maxConnections
	 *            maximum parallel connections, must be at least 1
	 */
public void setMaxConnections(int maxConnections) {
    if (maxConnections < 1)
        maxConnections = DEFAULT_MAX_CONNECTIONS;
    this.maxConnections = maxConnections;
    final HttpParams httpParams = this.httpClient.getParams();
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(this.maxConnections));
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) ConnPerRouteBean(org.apache.http.conn.params.ConnPerRouteBean)

Example 4 with ConnPerRouteBean

use of org.apache.http.conn.params.ConnPerRouteBean in project musicbrainz-android by jdamcd.

the class HttpClient method setupParams.

private static HttpParams setupParams() {
    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setTimeout(params, TIMEOUT);
    ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(MAX_CONNECTIONS));
    ConnManagerParams.setMaxTotalConnections(params, MAX_CONNECTIONS);
    HttpConnectionParams.setSoTimeout(params, TIMEOUT);
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    return params;
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) BasicHttpParams(org.apache.http.params.BasicHttpParams) ConnPerRouteBean(org.apache.http.conn.params.ConnPerRouteBean)

Example 5 with ConnPerRouteBean

use of org.apache.http.conn.params.ConnPerRouteBean in project ignition by mttkay.

the class IgnitedHttp method setupHttpClient.

protected void setupHttpClient() {
    BasicHttpParams httpParams = new BasicHttpParams();
    ConnManagerParams.setTimeout(httpParams, DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS));
    ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
    HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_SOCKET_TIMEOUT);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUserAgent(httpParams, DEFAULT_HTTP_USER_AGENT);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    if (IgnitedDiagnostics.ANDROID_API_LEVEL >= 7) {
        schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    } else {
        // used to work around a bug in Android 1.6:
        // http://code.google.com/p/android/issues/detail?id=1946
        // TODO: is there a less rigorous workaround for this?
        schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
    }
    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
    httpClient = new DefaultHttpClient(cm, httpParams);
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) EasySSLSocketFactory(com.github.ignition.support.http.ssl.EasySSLSocketFactory) BasicHttpParams(org.apache.http.params.BasicHttpParams) ConnPerRouteBean(org.apache.http.conn.params.ConnPerRouteBean) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Aggregations

ConnPerRouteBean (org.apache.http.conn.params.ConnPerRouteBean)12 BasicHttpParams (org.apache.http.params.BasicHttpParams)11 HttpParams (org.apache.http.params.HttpParams)8 Scheme (org.apache.http.conn.scheme.Scheme)7 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)7 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)7 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 TTransportException (com.evernote.thrift.transport.TTransportException)1 EasySSLSocketFactory (com.github.ignition.support.http.ssl.EasySSLSocketFactory)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 SSLException (javax.net.ssl.SSLException)1 EasySSLSocketFactory (org.apache.commons.httpclient.contrib.ssl.EasySSLSocketFactory)1 ConnectionReuseStrategy (org.apache.http.ConnectionReuseStrategy)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 AuthScope (org.apache.http.auth.AuthScope)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1