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

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

Introduction

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

Prototype

public void setMaxConnectionsPerHost(HostConfiguration paramHostConfiguration, int paramInt) 

Source Link

Usage

From source file:com.ms.commons.utilities.HttpClientUtils.java

public static synchronized void init() {
    if (connectionManager != null) {
        return;/* w ww  .j  ava  2  s  . co m*/
    }
    connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setConnectionTimeout(10000);
    params.setSoTimeout(20000);
    params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 1000);
    params.setMaxTotalConnections(10000);
    connectionManager.setParams(params);
    client = new HttpClient(connectionManager);
    client.getParams().setParameter("http.protocol.max-redirects", 3);
}

From source file:ac.elements.io.Signature.java

/**
 * Configure HttpClient with set of defaults as well as configuration from
 * AmazonEC2Config instance./*from   w  ww  .j  a v  a 2 s  .c  o  m*/
 * 
 * @return the http client
 */
private static HttpClient configureHttpClient() {

    /* Set http client parameters */
    HttpClientParams httpClientParams = new HttpClientParams();
    httpClientParams.setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
    httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
            if (executionCount > MAX_RETRY_ERROR) {
                log.warn("Maximum Number of Retry attempts " + "reached, will not retry");
                return false;
            }
            log.warn("Retrying request. Attempt " + executionCount);
            if (exception instanceof NoHttpResponseException) {
                log.warn("Retrying on NoHttpResponseException");
                return true;
            }
            if (exception instanceof InterruptedIOException) {
                log.warn("Will not retry on InterruptedIOException", exception);
                return false;
            }
            if (exception instanceof UnknownHostException) {
                log.warn("Will not retry on UnknownHostException", exception);
                return false;
            }
            if (!method.isRequestSent()) {
                log.warn("Retrying on failed sent request");
                return true;
            }
            return false;
        }
    });

    /* Set host configuration */
    HostConfiguration hostConfiguration = new HostConfiguration();

    /* Set connection manager parameters */
    HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();
    connectionManagerParams.setConnectionTimeout(50000);
    connectionManagerParams.setSoTimeout(50000);
    connectionManagerParams.setStaleCheckingEnabled(true);
    connectionManagerParams.setTcpNoDelay(true);
    connectionManagerParams.setMaxTotalConnections(MAX_CONNECTIONS);
    connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, MAX_CONNECTIONS);

    /* Set connection manager */
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(connectionManagerParams);

    /* Set http client */
    httpClient = new HttpClient(httpClientParams, connectionManager);

    /* Set proxy if configured */
    // if (config.isSetProxyHost() && config.isSetProxyPort()) {
    // log.info("Configuring Proxy. Proxy Host: " + config.getProxyHost() +
    // "Proxy Port: " + config.getProxyPort() );
    // hostConfiguration.setProxy(config.getProxyHost(),
    // config.getProxyPort());
    // if (config.isSetProxyUsername() && config.isSetProxyPassword()) {
    // httpClient.getState().setProxyCredentials (new AuthScope(
    // config.getProxyHost(),
    // config.getProxyPort()),
    // new UsernamePasswordCredentials(
    // config.getProxyUsername(),
    // config.getProxyPassword()));
    //        
    // }
    // }
    httpClient.setHostConfiguration(hostConfiguration);
    return httpClient;
}

From source file:fr.dutra.confluence2wordpress.xmlrpc.CommonsXmlRpcTransportFactory.java

public CommonsXmlRpcTransportFactory(URL url, String proxyHost, int proxyPort, int maxConnections) {
    this.url = url;
    HostConfiguration hostConf = new HostConfiguration();
    hostConf.setHost(url.getHost(), url.getPort());
    if (proxyHost != null && proxyPort != -1) {
        hostConf.setProxy(proxyHost, proxyPort);
    }/*w w  w.j  a v  a  2 s. com*/
    HttpConnectionManagerParams connParam = new HttpConnectionManagerParams();
    connParam.setMaxConnectionsPerHost(hostConf, maxConnections);
    connParam.setMaxTotalConnections(maxConnections);
    MultiThreadedHttpConnectionManager conMgr = new MultiThreadedHttpConnectionManager();
    conMgr.setParams(connParam);
    client = new HttpClient(conMgr);
    client.setHostConfiguration(hostConf);
}

From source file:com.taobao.metamorphosis.client.http.SimpleHttpClient.java

protected void initHttpClient(HttpClientConfig config) {
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(config.getHost(), config.getPort());

    connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.closeIdleConnections(config.getPollingIntervalTime() * 4000);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(config.isConnectionStaleCheckingEnabled());
    params.setMaxConnectionsPerHost(hostConfiguration, config.getMaxHostConnections());
    params.setMaxTotalConnections(config.getMaxTotalConnections());
    params.setConnectionTimeout(config.getTimeout());
    params.setSoTimeout(60 * 1000);/*w ww .j a  v a 2  s .c  om*/

    connectionManager.setParams(params);
    httpclient = new HttpClient(connectionManager);
    httpclient.setHostConfiguration(hostConfiguration);
}

From source file:com.trendmicro.hdfs.webdav.test.MiniClusterTestUtil.java

public HttpClient getClient() {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost");
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxConnectionsPerHost(hostConfig, 100);
    connectionManager.setParams(params);
    HttpClient client = new HttpClient(connectionManager);
    client.setHostConfiguration(hostConfig);
    return client;
}

From source file:com.silverpeas.openoffice.windows.webdav.WebdavManager.java

/**
 * Prepare HTTP connections to the WebDav server
 *
 * @param host the webdav server host name.
 * @param login the login for the user on the webdav server.
 * @param password the login for the user on the webdav server.
 *///  ww w.jav  a  2s. c o m
public WebdavManager(String host, String login, String password) {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(host);
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams connectionParams = new HttpConnectionManagerParams();
    int maxHostConnections = 20;
    connectionParams.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    connectionManager.setParams(connectionParams);
    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setParameter(HttpClientParams.CREDENTIAL_CHARSET, "UTF-8");
    clientParams.setParameter(HttpClientParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    client = new HttpClient(clientParams, connectionManager);
    Credentials creds = new UsernamePasswordCredentials(login, password);
    client.getState().setCredentials(AuthScope.ANY, creds);
    client.setHostConfiguration(hostConfig);
}

From source file:de.kp.ames.webdav.WebDAVClient.java

/**
 * Constructor/*w w  w  .  j av  a 2  s . c  om*/
 * 
 * @param alias
 * @param keypass
 * @param uri
 */
public WebDAVClient(String alias, String keypass, String uri) {

    /*
     * Register request uri
     */
    this.uri = uri;

    /*
     * Setup HttpClient
     */
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(uri);

    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();

    int maxHostConnections = 200;
    params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);

    connectionManager.setParams(params);

    client = new HttpClient(connectionManager);
    client.setHostConfiguration(hostConfig);

    Credentials creds = new UsernamePasswordCredentials(alias, keypass);
    client.getState().setCredentials(AuthScope.ANY, creds);

}

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  .  j a  va2  s.  co m
    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.taobao.diamond.client.impl.DefaultDiamondPublisher.java

private void initHttpClient() {
    if (MockServer.isTestMode()) {
        return;/*www  .  j  a v  a 2s  . co m*/
    }
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(domainNamePos.get()),
            diamondConfigure.getPort());
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.closeIdleConnections(60 * 1000);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
    params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    params.setSoTimeout(requestTimeout);

    connectionManager.setParams(params);

    httpClient = new HttpClient(connectionManager);
    httpClient.setHostConfiguration(hostConfiguration);
}

From source file:com.taobao.diamond.client.impl.DefaultDiamondSubscriber.java

protected void initHttpClient() {
    if (MockServer.isTestMode()) {
        return;/*  ww  w  . j ava  2  s. c o m*/
    }
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
            diamondConfigure.getPort());

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.closeIdleConnections(diamondConfigure.getPollingIntervalTime() * 4000);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
    params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    // 1,
    // boyan@taobao.com
    params.setSoTimeout(60 * 1000);

    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);
    httpClient.setHostConfiguration(hostConfiguration);
}