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:org.intalio.tempo.workflow.tas.nuxeo.NuxeoStorageStrategy.java

/**
 * Everything we need to do to have an authenticated http client
 * /*from w  w  w  .j a  v  a 2s .  c  o m*/
 * @throws URIException
 */
private void initHttpClient() throws URIException {
    httpclient = new HttpClient();
    HostConfiguration hostConfig = new HostConfiguration();
    org.apache.commons.httpclient.URI uri = new org.apache.commons.httpclient.URI(getNuxeoRestUrl(), false);
    hostConfig.setHost(uri);
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    int maxHostConnections = 20;
    params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    connectionManager.setParams(params);
    httpclient = new HttpClient(connectionManager);
    httpclient.setHostConfiguration(hostConfig);
    Credentials creds = new UsernamePasswordCredentials(userName, password);
    AuthScope authScope = new AuthScope(hostConfig.getHost(), hostConfig.getPort());
    httpclient.getState().setCredentials(authScope, creds);
    httpclient.getParams().setAuthenticationPreemptive(true);
}

From source file:org.intalio.tempo.workflow.tas.sling.SlingStorageStrategy.java

public void init() throws HttpException, IOException {
    HostConfiguration hostConfig = new HostConfiguration();
    // hostConfig.setHost("www.somehost.com");
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    int maxHostConnections = 20;
    params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    connectionManager.setParams(params);
    httpclient = new HttpClient(connectionManager);
    Credentials creds = new UsernamePasswordCredentials(userName, password);
    httpclient.getState().setCredentials(AuthScope.ANY, creds);
    httpclient.setHostConfiguration(hostConfig);

    MkColMethod col = new MkColMethod(getUploadFolder());
    int ret = httpclient.executeMethod(col);
    log.debug(MessageFormatter.format("Created folder {0} in sling: {1}", getUploadFolder(), ret));
}

From source file:org.jasig.portal.security.provider.SamlAssertionFilter.java

@Override
protected void initFilterBean() throws ServletException {
    this.connectionManager = new MultiThreadedHttpConnectionManager();
    final HttpConnectionManagerParams params = this.connectionManager.getParams();
    params.setMaxTotalConnections(this.maxTotalConnections);
    params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, this.maxTotalConnections);
    params.setConnectionTimeout(this.connectionTimeout);
    params.setSoTimeout(this.readTimeout);

    this.httpClient = new HttpClient(this.connectionManager);
}

From source file:org.mimacom.maven.plugins.liferay.prepare.MultithreadedDownloader.java

MultithreadedDownloader(int threads) {
    this.threads = threads;
    MultiThreadedHttpConnectionManager conMgr = new MultiThreadedHttpConnectionManager();
    HostConfiguration hc = new HostConfiguration();
    HttpConnectionManagerParams params = conMgr.getParams();
    params.setMaxConnectionsPerHost(hc, 10);
    httpClient = new HttpClient(conMgr);
    httpClient.setHostConfiguration(hc);
}

From source file:org.nuxeo.ecm.webdav.JackRabbitParallelBench.java

private HttpClient createClient() {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost", PORT);

    //HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManager connectionManager = new SimpleHttpConnectionManager(true);
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxConnectionsPerHost(hostConfig, 10);
    connectionManager.setParams(params);

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

    Credentials creds = new UsernamePasswordCredentials(LOGIN, PASSWD);
    client.getState().setCredentials(AuthScope.ANY, creds);

    return client;
}

From source file:org.nuxeo.ecm.webdav.JackrabbitWebdavClientTest.java

@BeforeClass
public static void setUp() {
    // Setup code
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost", PORT);

    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    int maxHostConnections = 20;
    params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    connectionManager.setParams(params);

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

    Credentials creds = new UsernamePasswordCredentials("userId", "pw");
    client.getState().setCredentials(AuthScope.ANY, creds);
}

From source file:org.nuxeo.ecm.webdav.ParallelBench.java

private HttpClient createClient() {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost", PORT);

    // HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManager connectionManager = new SimpleHttpConnectionManager(true);
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxConnectionsPerHost(hostConfig, 10);
    connectionManager.setParams(params);

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

    Credentials creds = new UsernamePasswordCredentials(LOGIN, PASSWD);
    client.getState().setCredentials(AuthScope.ANY, creds);

    return client;
}

From source file:org.nuxeo.ecm.webdav.WebDavClientTest.java

protected static HttpClient createClient(String username, String password) {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost", WebDavServerFeature.PORT);

    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    int maxHostConnections = 20;
    params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    connectionManager.setParams(params);

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

    Credentials creds = new UsernamePasswordCredentials(username, password);
    httpClient.getState().setCredentials(AuthScope.ANY, creds);
    httpClient.getParams().setAuthenticationPreemptive(true);
    return httpClient;
}

From source file:voldemort.client.HttpStoreClientFactory.java

public HttpStoreClientFactory(ClientConfig config) {
    super(config);
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    this.httpClient = new HttpClient(connectionManager);
    this.httpClient.setHostConfiguration(hostConfig);
    HttpClientParams clientParams = this.httpClient.getParams();
    clientParams.setConnectionManagerTimeout(config.getConnectionTimeout(TimeUnit.MILLISECONDS));
    clientParams.setSoTimeout(config.getSocketTimeout(TimeUnit.MILLISECONDS));
    clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
    clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    clientParams.setParameter("http.useragent", VOLDEMORT_USER_AGENT);
    HttpConnectionManagerParams managerParams = this.httpClient.getHttpConnectionManager().getParams();
    managerParams.setConnectionTimeout(config.getConnectionTimeout(TimeUnit.MILLISECONDS));
    managerParams.setMaxTotalConnections(config.getMaxTotalConnections());
    managerParams.setStaleCheckingEnabled(false);
    managerParams.setMaxConnectionsPerHost(httpClient.getHostConfiguration(),
            config.getMaxConnectionsPerNode());
    this.reroute = config.getRoutingTier().equals(RoutingTier.SERVER);
    this.requestFormatFactory = new RequestFormatFactory();
}

From source file:voldemort.performance.HttpClientBench.java

private static HttpClient createClient() {
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(connectionManager);
    HttpClientParams clientParams = httpClient.getParams();
    clientParams.setConnectionManagerTimeout(DEFAULT_CONNECTION_MANAGER_TIMEOUT);
    clientParams.setSoTimeout(500);/*from   w  ww  .jav a 2 s  .  c  o m*/
    clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
    clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    clientParams.setBooleanParameter("http.tcp.nodelay", false);
    clientParams.setIntParameter("http.socket.receivebuffer", 60000);
    clientParams.setParameter("http.useragent", VOLDEMORT_USER_AGENT);
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost");
    hostConfig.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    httpClient.setHostConfiguration(hostConfig);
    HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams();
    managerParams.setConnectionTimeout(DEFAULT_CONNECTION_MANAGER_TIMEOUT);
    managerParams.setMaxTotalConnections(DEFAULT_MAX_CONNECTIONS);
    managerParams.setMaxConnectionsPerHost(httpClient.getHostConfiguration(), DEFAULT_MAX_HOST_CONNECTIONS);
    managerParams.setStaleCheckingEnabled(false);

    return httpClient;
}