Example usage for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager ThreadSafeClientConnManager

List of usage examples for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager ThreadSafeClientConnManager

Introduction

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

Prototype

public ThreadSafeClientConnManager() 

Source Link

Usage

From source file:org.commonjava.couch.test.fixture.RemoteRESTFixture.java

@Override
protected void before() throws Throwable {
    super.before();

    final ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager();
    ccm.setMaxTotal(20);//  www  .  j a  v a2 s. co m

    http = new DefaultHttpClient(ccm);
}

From source file:org.wso2.developerstudio.appfactory.core.client.HttpsJaggeryClient.java

@SuppressWarnings("deprecation")
public static HttpClient wrapClient(HttpClient base, String urlStr) {
    try {//from   w w  w. j  a va  2 s . co  m
        SSLContext ctx = SSLContext.getInstance("TLS");
        X509TrustManager tm = new X509TrustManager() {

            public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        };
        ctx.init(null, new TrustManager[] { tm }, null);
        SSLSocketFactory ssf = new SSLSocketFactory(ctx);
        ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        ClientConnectionManager ccm = new ThreadSafeClientConnManager();
        SchemeRegistry sr = ccm.getSchemeRegistry();
        URL url = new URL(urlStr);
        int port = url.getPort();
        if (port == -1) {
            port = 443;
        }
        String protocol = url.getProtocol();
        if ("https".equals(protocol)) {
            if (port == -1) {
                port = 443;
            }
        } else if ("http".equals(protocol)) {
            if (port == -1) {
                port = 80;
            }
        }
        sr.register(new Scheme(protocol, ssf, port));

        return new DefaultHttpClient(ccm, base.getParams());
    } catch (Throwable ex) {
        ex.printStackTrace();
        log.error("Trust Manager Error", ex);
        return null;
    }
}

From source file:uk.co.techblue.docusign.client.DocuSignClient.java

private static HttpClient getHttpClient() {
    if (client == null) {
        synchronized (DocuSignClient.class) {
            if (client == null) {
                ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();

                int maxPerRoute = httpClientConfiguration.getDefaultMaxPerRoute();
                cm.setDefaultMaxPerRoute(maxPerRoute);
                cm.setMaxTotal(maxPerRoute);
                client = new DefaultHttpClient(cm);

                int timeout = httpClientConfiguration.getTimeout();
                String proxyHost = httpClientConfiguration.getProxyHost();

                HttpParams params = client.getParams();
                // Allowable time between packets
                HttpConnectionParams.setSoTimeout(params, timeout);
                // Allowable time to get a connection
                HttpConnectionParams.setConnectionTimeout(params, timeout);

                // Configure proxy info if necessary and defined
                if (proxyHost != null && !proxyHost.equals("")) {
                    // Configure the host and port
                    int port = httpClientConfiguration.getProxyPort();
                    HttpHost proxy = new HttpHost(proxyHost, port);

                    params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
                }//ww w  .  jav  a 2s  .  co m

            }
        }
    }

    if (logger.isDebugEnabled()) {
        logger.info("connections: "
                + ((ThreadSafeClientConnManager) client.getConnectionManager()).getConnectionsInPool());
    }

    return client;
}

From source file:cn.tiup.httpproxy.ProxyServlet.java

/** Called from {@link #init(javax.servlet.ServletConfig)}. HttpClient offers many opportunities
 * for customization. By default,//from  w w  w.j av a  2 s .  com
 * <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/SystemDefaultHttpClient.html">
 *   SystemDefaultHttpClient</a> is used if available, otherwise it falls
 * back to:
 * <pre>new DefaultHttpClient(new ThreadSafeClientConnManager(),hcParams)</pre>
 * SystemDefaultHttpClient uses PoolingClientConnectionManager. In any case, it should be thread-safe. */
protected HttpClient createHttpClient(HttpParams hcParams) {
    try {
        //as of HttpComponents v4.2, this class is better since it uses System
        // Properties:
        Class<?> clientClazz = Class.forName("org.apache.http.impl.client.SystemDefaultHttpClient");
        Constructor<?> constructor = clientClazz.getConstructor(HttpParams.class);
        return (HttpClient) constructor.newInstance(hcParams);
    } catch (ClassNotFoundException e) {
        //no problem; use v4.1 below
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    //Fallback on using older client:
    return new DefaultHttpClient(new ThreadSafeClientConnManager(), hcParams);
}