Example usage for org.apache.commons.httpclient.params HttpConnectionManagerParams setMaxTotalConnections

List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams setMaxTotalConnections

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpConnectionManagerParams setMaxTotalConnections.

Prototype

public void setMaxTotalConnections(int paramInt) 

Source Link

Usage

From source file:com.duowan.common.rpc.client.CommonsHttpInvokerRequestExecutor.java

/**
 * Create a new CommonsHttpInvokerRequestExecutor with a default
 * HttpClient that uses a default MultiThreadedHttpConnectionManager.
 * Sets the socket read timeout to {@link #DEFAULT_READ_TIMEOUT_MILLISECONDS}.
 * @see org.apache.commons.httpclient.HttpClient
 * @see org.apache.commons.httpclient.MultiThreadedHttpConnectionManager
 *///w  w  w. j a va 2  s.  c o m
public CommonsHttpInvokerRequestExecutor() {
    MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(300);
    params.setMaxTotalConnections(500);
    httpConnectionManager.setParams(params);

    this.httpClient = new HttpClient(httpConnectionManager);
    this.setReadTimeout(getReadTimeout());
    this.setConnectionTimeout(getConnectionTimeout());
}

From source file:com.itude.mobile.mobbl.server.http.HttpDelegate.java

private HttpDelegate() {
    logger.debug("HttpDelegate.HttpDelegate()");

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams connectionParameters = connectionManager.getParams();
    connectionParameters.setDefaultMaxConnectionsPerHost(CONNECTIONS_PER_HOST);
    connectionParameters.setMaxTotalConnections(TOTAL_CONNECTIONS);
    connectionParameters.setConnectionTimeout(CONNECTION_TIMEOUT);

    httpClient = new HttpClient(connectionManager);
}

From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java

/**
 * Create the {@link HttpClient} object/* ww w . j  a  v  a  2s .  co  m*/
 */
private void createClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setConnectionTimeout(TIMEOUT_MS);
    params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS);
    params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);
    configureCredentials();
    if (StringUtils.isNotBlank(System.getProperty("http.proxyHost"))) {
        log.debug("A HTTP Proxy is configured");
        System.setProperty("java.net.useSystemProxies", "true");
        Proxy proxy = chooseProxy();
        if (proxy.type() == Type.HTTP && proxy.address() instanceof InetSocketAddress) {
            // convert the socket address to an ProxyHost
            final InetSocketAddress isa = (InetSocketAddress) proxy.address();
            // assume default scheme (http)
            ProxyHost proxyHost = new ProxyHost(getHost(isa), isa.getPort());
            httpClient.getHostConfiguration().setProxyHost(proxyHost);
            if (StringUtils.isNotBlank(System.getProperty("http.proxyUser"))) {
                String user = System.getProperty("http.proxyUser");
                String password = System.getProperty("http.proxyPassword");
                httpClient.getState().setProxyCredentials(new AuthScope(getHost(isa), isa.getPort()),
                        new UsernamePasswordCredentials(user, password));
            }
        }
    }
}

From source file:com.xerox.amazonws.common.AWSQueryConnection.java

private void configureHttpClient() {
    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams connParams = connMgr.getParams();
    connParams.setMaxTotalConnections(maxConnections);
    connParams.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxConnections);
    connMgr.setParams(connParams);// www.ja v  a 2  s  .  c om
    hc = new HttpClient(connMgr);
    // NOTE: These didn't seem to help in my initial testing
    //         hc.getParams().setParameter("http.tcp.nodelay", true);
    //         hc.getParams().setParameter("http.connection.stalecheck", false); 
    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        hc.setHostConfiguration(hostConfig);
        log.info("Proxy Host set to " + proxyHost + ":" + proxyPort);
        if (proxyUser != null && !proxyUser.trim().equals("")) {
            if (proxyDomain != null) {
                hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort),
                        new NTCredentials(proxyUser, proxyPassword, proxyHost, proxyDomain));
            } else {
                hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort),
                        new UsernamePasswordCredentials(proxyUser, proxyPassword));
            }
        }
    }
}

From source file:com.creditease.bdp.axis2.transport.http.HTTPSender.java

@Override
protected HttpClient getHttpClient(MessageContext msgContext) {
    ConfigurationContext configContext = msgContext.getConfigurationContext();

    HttpClient httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);

    if (httpClient == null) {
        httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
    }//from   w w  w.j a  v  a 2 s  . c  om

    if (httpClient != null) {
        return httpClient;
    }

    synchronized (this) {
        httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);

        if (httpClient == null) {
            httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
        }

        if (httpClient != null) {
            return httpClient;
        }

        HttpConnectionManager connManager = (HttpConnectionManager) msgContext
                .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
        if (connManager == null) {
            connManager = (HttpConnectionManager) msgContext
                    .getProperty(HTTPConstants.MUTTITHREAD_HTTP_CONNECTION_MANAGER);
        }
        if (connManager == null) {
            // reuse HttpConnectionManager
            synchronized (configContext) {
                connManager = (HttpConnectionManager) configContext
                        .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
                if (connManager == null) {
                    log.trace("Making new ConnectionManager");
                    connManager = new MultiThreadedHttpConnectionManager();
                    // NOTE: Added by CJ
                    Integer maxConnectionPerHostConf = (Integer) msgContext
                            .getProperty(Constants.MAX_CONNECTIONS_PER_HOST);
                    Integer maxConnectionTotalConf = (Integer) msgContext
                            .getProperty(Constants.MAX_CONNECTIONS_TOTAL);
                    if (maxConnectionPerHostConf != null || maxConnectionTotalConf != null) {
                        HttpConnectionManagerParams param = new HttpConnectionManagerParams();
                        if (maxConnectionPerHostConf != null) {
                            param.setDefaultMaxConnectionsPerHost(maxConnectionPerHostConf);
                        }
                        if (maxConnectionTotalConf != null) {
                            param.setMaxTotalConnections(maxConnectionTotalConf);
                        }
                        connManager.setParams(param);
                    }
                    configContext.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connManager);
                }
            }
        }
        /*
         * Create a new instance of HttpClient since the way
         * it is used here it's not fully thread-safe.
         */
        httpClient = new HttpClient(connManager);

        // Set the default timeout in case we have a connection pool starvation to 30sec
        httpClient.getParams().setConnectionManagerTimeout(30000);

        // Get the timeout values set in the runtime
        initializeTimeouts(msgContext, httpClient);

        return httpClient;
    }
}

From source file:fr.aliasource.webmail.server.proxy.client.http.ProxyClient.java

private HttpClient createHttpClient() {
    mtConMan = new MultiThreadedHttpConnectionManager();
    HttpClient ret = new HttpClient(mtConMan);
    HttpConnectionManagerParams mp = ret.getHttpConnectionManager().getParams();
    mp.setDefaultMaxConnectionsPerHost(4);
    mp.setMaxTotalConnections(8);
    return ret;/*  w  w  w .j a va  2  s  .  co  m*/
}

From source file:com.iflytek.spider.protocol.httpclient.Http.java

/**
 * Configures the HTTP client// w  ww. j a v  a2s. c o m
 */
private void configureClient() {

    // Set up an HTTPS socket factory that accepts self-signed certs.
    Protocol https = new Protocol("https", new DummySSLProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", https);

    HttpConnectionManagerParams params = connectionManager.getParams();
    params.setConnectionTimeout(timeout);
    params.setSoTimeout(timeout);
    params.setSendBufferSize(BUFFER_SIZE);
    params.setReceiveBufferSize(BUFFER_SIZE);
    params.setMaxTotalConnections(maxThreadsTotal);

    params.setDefaultMaxConnectionsPerHost(maxThreadsTotal);

    // executeMethod(HttpMethod) seems to ignore the connection timeout on
    // the connection manager.
    // set it explicitly on the HttpClient.
    client.getParams().setConnectionManagerTimeout(timeout);

    HostConfiguration hostConf = client.getHostConfiguration();
    ArrayList headers = new ArrayList();
    // Set the User Agent in the header
    headers.add(new Header("User-Agent", userAgent));
    // prefer English
    headers.add(new Header("Accept-Language", acceptLanguage));
    // prefer UTF-8
    headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7"));
    // prefer understandable formats
    headers.add(new Header("Accept",
            "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"));
    // accept gzipped content
    headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate"));
    hostConf.getParams().setParameter("http.default-headers", headers);

    // HTTP proxy server details
    if (useProxy) {
        hostConf.setProxy(proxyHost, proxyPort);

        if (proxyUsername.length() > 0) {

            AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm);

            NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword,
                    this.agentHost, this.proxyRealm);

            client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
        }
    }

}

From source file:com.sa.npopa.samples.hbase.rest.client.Client.java

private void initialize(Cluster cluster, boolean sslEnabled) {
    this.cluster = cluster;
    this.sslEnabled = sslEnabled;
    MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams managerParams = manager.getParams();
    managerParams.setConnectionTimeout(2000); // 2 s
    managerParams.setDefaultMaxConnectionsPerHost(10);
    managerParams.setMaxTotalConnections(100);
    extraHeaders = new ConcurrentHashMap<String, String>();
    this.httpClient = new HttpClient(manager);
    HttpClientParams clientParams = httpClient.getParams();
    clientParams.setVersion(HttpVersion.HTTP_1_1);

}

From source file:com.iflytek.spider.protocol.httpclient.HttpSimply.java

/**
 * Configures the HTTP client//from w  w w .java 2  s  . c  om
 */
private void configureClient() {

    // Set up an HTTPS socket factory that accepts self-signed certs.
    Protocol https = new Protocol("https", new DummySSLProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", https);

    HttpConnectionManagerParams params = connectionManager.getParams();
    params.setConnectionTimeout(timeout);
    //params.setSoTimeout(timeout); timeouttimeout
    params.setSendBufferSize(BUFFER_SIZE);
    params.setReceiveBufferSize(BUFFER_SIZE);
    params.setMaxTotalConnections(maxThreadsTotal);

    params.setDefaultMaxConnectionsPerHost(maxThreadsTotal);

    // executeMethod(HttpMethod) seems to ignore the connection timeout on
    // the connection manager.
    // set it explicitly on the HttpClient.
    client.getParams().setConnectionManagerTimeout(timeout);

    HostConfiguration hostConf = client.getHostConfiguration();
    ArrayList headers = new ArrayList();
    // Set the User Agent in the header
    headers.add(new Header("User-Agent", userAgent));
    // prefer English
    headers.add(new Header("Accept-Language", acceptLanguage));
    // prefer UTF-8
    headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7"));
    // prefer understandable formats
    headers.add(new Header("Accept",
            "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"));
    // accept gzipped content
    headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate"));
    hostConf.getParams().setParameter("http.default-headers", headers);

    // HTTP proxy server details
    if (useProxy) {
        hostConf.setProxy(proxyHost, proxyPort);

        if (proxyUsername.length() > 0) {

            AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm);

            NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword,
                    this.agentHost, this.proxyRealm);

            client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
        }
    }

}

From source file:it.geosolutions.httpproxy.service.impl.ProxyServiceImpl.java

/**
 * Load proxy configuration when proxy config has changed
 *///from   w w  w  . j a v a2 s.  c o m
private void loadProxyConfig() {
    connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();

    params.setSoTimeout(proxyConfig.getSoTimeout());
    params.setConnectionTimeout(proxyConfig.getConnectionTimeout());
    params.setMaxTotalConnections(proxyConfig.getMaxTotalConnections());
    params.setDefaultMaxConnectionsPerHost(proxyConfig.getDefaultMaxConnectionsPerHost());

    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);

    configureCallbacks();
}