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

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

Introduction

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

Prototype

@Deprecated
public SingleClientConnManager(final HttpParams params, final SchemeRegistry schreg) 

Source Link

Document

Creates a new simple connection manager.

Usage

From source file:com.emobc.android.utils.HttpUtils.java

/**
 * Take a client address is https by default if
 * @param https//from  w w  w  . j  a  va  2s. com
 * @return
 */
public static DefaultHttpClient getHttpClient(boolean https) {
    if (https) {
        HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

        DefaultHttpClient client = new DefaultHttpClient();

        SchemeRegistry registry = new SchemeRegistry();
        SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
        socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
        registry.register(new Scheme("https", socketFactory, 443));
        SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
        DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());

        // Set verifier      
        HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
        return httpClient;
    }
    return new DefaultHttpClient();
}

From source file:Main.java

public static DefaultHttpClient setHttpPostProxyParams(Context context, int connTimeout) {

    Log.d(TAG, "ctx, connTimeout -- called");

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

    HttpParams params = new BasicHttpParams();

    /*Log.d(TAG, "----Add Proxy---");
    HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(),
      Constants.PROXY_PORT);/*from  w w w  . j a va2  s .c  o m*/
    params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);*/

    /*if ((getWifiName(context).trim()).equalsIgnoreCase("secure-impact")) {
       Log.d(TAG, "----Add Proxy---");
       HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(),
         Constants.PROXY_PORT);
       params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }*/

    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
    params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

    HttpConnectionParams.setConnectionTimeout(params, connTimeout);
    HttpConnectionParams.setSoTimeout(params, connTimeout);

    ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry);

    DefaultHttpClient mHttpClient = new DefaultHttpClient(cm, params);

    return mHttpClient;
}

From source file:org.wso2.carbon.dynamic.client.web.proxy.util.DCRProxyUtils.java

public static DefaultHttpClient getHttpsClient() {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    // Setup the HTTPS settings to accept any certificate.
    HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

    SchemeRegistry registry = new SchemeRegistry();
    SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
    socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
    registry.register(new Scheme(Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL,
            socketFactory, DCRProxyUtils.getServerHTTPSPort()));
    SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry);
    httpClient = new DefaultHttpClient(mgr, httpClient.getParams());

    // Set verifier
    HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
    return httpClient;
}

From source file:mock.MockHttpClient.java

public ClientConnectionManager getConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    return new SingleClientConnManager(this.getParams(), registry);
}

From source file:mobisocial.musubi.util.CertifiedHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", newSslSocketFactory(), 443));
    return new SingleClientConnManager(getParams(), registry);
}

From source file:ee.vvk.ivotingverification.util.CustomHttpsClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {

    SchemeRegistry registry = new SchemeRegistry();

    registry.register(new Scheme("https", newSslSocketFactory(), 443));

    return new SingleClientConnManager(getParams(), registry);
}

From source file:edu.cwru.apo.TrustAPOHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // Register for port 8090 our SSLSocketFactory with our keystore
    // to the ConnectionManager
    registry.register(new Scheme("https", newSslSocketFactory(), 8090));
    return new SingleClientConnManager(getParams(), registry);
}

From source file:com.phonty.improved.PhontyHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", newSslSocketFactory(), 4711));
    return new SingleClientConnManager(getParams(), registry);
}

From source file:fr.cph.stock.android.web.MyHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    try {//from  w  w  w.  j  a v  a2 s . c om
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", new TrustAllSSLSocketFactory(), 443));
        return new SingleClientConnManager(getParams(), registry);
    } catch (Exception e) {
        return null;
    }

}

From source file:edu.rit.csh.androidwebnews.WebnewsHttpClient.java

/**
 * Sets up the client connection with the correct schemes
 *
 * @return ClientConnectionManager//from   w w w.ja v a  2  s.c  om
 */
@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    //registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // Register for port 443 our SSLSocketFactory with our keystore
    // to the ConnectionManager
    registry.register(new Scheme("https", newSslSocketFactory(), 443));
    return new SingleClientConnManager(getParams(), registry);
}