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

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

Introduction

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

Prototype

public void setDefaultMaxConnectionsPerHost(int paramInt) 

Source Link

Usage

From source file:org.eclipse.ecr.core.storage.sql.RepositoryImpl.java

public RepositoryImpl(RepositoryDescriptor repositoryDescriptor) throws StorageException {
    this.repositoryDescriptor = repositoryDescriptor;
    sessions = new CopyOnWriteArrayList<SessionImpl>();
    cachePropagator = new InvalidationsPropagator();
    eventPropagator = new InvalidationsPropagator();
    repositoryEventQueue = new InvalidationsQueue("repo-" + repositoryDescriptor.name);
    try {/* ww w . j  a  v  a 2  s . co m*/
        schemaManager = Framework.getService(SchemaManager.class);
    } catch (Exception e) {
        throw new StorageException(e);
    }
    try {
        eventService = Framework.getService(EventService.class);
    } catch (Exception e) {
        throw new StorageException(e);
    }

    connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = connectionManager.getParams();
    params.setDefaultMaxConnectionsPerHost(20);
    params.setMaxTotalConnections(20);
    httpClient = new HttpClient(connectionManager);
    binaryManager = createBinaryManager();
    backend = createBackend();
    createServer();
}

From source file:org.exoplatform.services.common.HttpClientImpl.java

private void setHost(String protocol, String host, int port) throws Exception {
    MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams para = new HttpConnectionManagerParams();
    para.setConnectionTimeout(HTTP_TIMEOUT);
    para.setDefaultMaxConnectionsPerHost(10);
    para.setMaxTotalConnections(20);/*from  w  ww. j ava 2  s. c om*/
    para.setStaleCheckingEnabled(true);
    manager.setParams(para);
    http = new HttpClient(manager);
    http.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    http.getParams().setParameter("http.socket.timeout", new Integer(HTTP_TIMEOUT));
    http.getParams().setParameter("http.protocol.content-charset", "UTF-8");
    http.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
    http.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    if (port < 0)
        port = 80;
    HostConfiguration hostConfig = http.getHostConfiguration();
    hostConfig.setHost(host, port, protocol);

    String proxyHost = System.getProperty("httpclient.proxy.host");
    if (proxyHost == null || proxyHost.trim().length() < 1)
        return;
    String proxyPort = System.getProperty("httpclient.proxy.port");
    hostConfig.setProxy(proxyHost, Integer.parseInt(proxyPort));

    String username = System.getProperty("httpclient.proxy.username");
    String password = System.getProperty("httpclient.proxy.password");
    String ntlmHost = System.getProperty("httpclient.proxy.ntlm.host");
    String ntlmDomain = System.getProperty("httpclient.proxy.ntlm.domain");

    Credentials ntCredentials;
    if (ntlmHost == null || ntlmDomain == null) {
        ntCredentials = new UsernamePasswordCredentials(username, password);
    } else {
        ntCredentials = new NTCredentials(username, password, ntlmHost, ntlmDomain);
    }
    http.getState().setProxyCredentials(AuthScope.ANY, ntCredentials);
}

From source file:org.geosdi.geoplatform.services.httpclient.GeoSDIHttpClient.java

public GeoSDIHttpClient() {

    System.setProperty("jsse.enableSNIExtension", "false");
    System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setSoTimeout(30000);//from w w  w  .  ja  v a  2  s . co  m
    params.setConnectionTimeout(30000);
    params.setMaxTotalConnections(6);
    params.setDefaultMaxConnectionsPerHost(6);
    this.connectionManager.setParams(params);

    this.client = this.createHttpClient();

    //this.applySystemProxySettings();
}

From source file:org.geoserver.gss.HTTPGSSClientFactory.java

HttpClient getClient() {
    if (client == null) {
        client = new HttpClient();
        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
        // setting timeouts (one minute hard coded, TODO: make this configurable)
        params.setSoTimeout(60 * 1000);/*from  w w w  .  ja  v a2 s.c o m*/
        params.setConnectionTimeout(60 * 1000);
        params.setDefaultMaxConnectionsPerHost(1);
        MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
        manager.setParams(params);
        client.setHttpConnectionManager(manager);
    }
    return client;
}

From source file:org.geotools.data.ows.MultithreadedHttpClient.java

public MultithreadedHttpClient() {
    connectionManager = new MultiThreadedHttpConnectionManager();

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setSoTimeout(30000);// w  w w  . j  ava 2 s .co m
    params.setConnectionTimeout(30000);
    params.setMaxTotalConnections(6);
    params.setDefaultMaxConnectionsPerHost(6);

    connectionManager.setParams(params);

    client = new HttpClient(connectionManager);

    applySystemProxySettings();
}

From source file:org.hydracache.client.transport.HttpTransport.java

public HttpTransport() {
    // FIXME Make this more IoC and configurable.
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();
    connectionManagerParams.setDefaultMaxConnectionsPerHost(10);
    connectionManagerParams.setMaxTotalConnections(100);
    connectionManager.setParams(connectionManagerParams);

    this.httpClient = new HttpClient(connectionManager);
}

From source file:org.jasig.portal.services.MultiThreadedHttpConnectionManagerFactoryBean.java

@Override
protected MultiThreadedHttpConnectionManager createInstance() throws Exception {
    final MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();

    final HttpConnectionManagerParams pars = multiThreadedHttpConnectionManager.getParams();
    pars.setConnectionTimeout(this.connectionTimeout);
    pars.setSoTimeout(this.soTimeout);
    pars.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    pars.setMaxTotalConnections(this.maxTotalConnections);
    pars.setDefaultMaxConnectionsPerHost(this.defaultMaxConnectionsPerHost);

    return multiThreadedHttpConnectionManager;
}

From source file:org.jboss.test.cluster.defaultcfg.web.test.CleanShutdownTestCase.java

/**
 * @see org.jboss.test.JBossClusteredTestCase#setUp()
 *//*  w w w .  java2 s  . c  o m*/
@Override
protected void setUp() throws Exception {
    super.setUp();

    this.name = ObjectName.getInstance(SERVER_NAME);
    this.server = this.getAdaptors()[0];
    this.baseURL = this.getHttpURLs()[0];

    this.manager = new MultiThreadedHttpConnectionManager();

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(MAX_THREADS);
    params.setMaxTotalConnections(MAX_THREADS);

    this.manager.setParams(params);

    this.client = new HttpClient();
}

From source file:org.jivesoftware.openfire.crowd.CrowdManager.java

private CrowdManager() {
    try {/*from  ww w.  j ava 2s  . c  om*/
        // loading crowd.properties file
        CrowdProperties crowdProps = new CrowdProperties();

        MultiThreadedHttpConnectionManager threadedConnectionManager = new MultiThreadedHttpConnectionManager();
        HttpClient hc = new HttpClient(threadedConnectionManager);

        HttpClientParams hcParams = hc.getParams();
        hcParams.setAuthenticationPreemptive(true);

        HttpConnectionManagerParams hcConnectionParams = hc.getHttpConnectionManager().getParams();
        hcConnectionParams.setDefaultMaxConnectionsPerHost(crowdProps.getHttpMaxConnections());
        hcConnectionParams.setMaxTotalConnections(crowdProps.getHttpMaxConnections());
        hcConnectionParams.setConnectionTimeout(crowdProps.getHttpConnectionTimeout());
        hcConnectionParams.setSoTimeout(crowdProps.getHttpSocketTimeout());

        crowdServer = new URI(crowdProps.getCrowdServerUrl()).resolve("rest/usermanagement/latest/");

        // setting BASIC authentication in place for connection with Crowd
        HttpState httpState = hc.getState();
        Credentials crowdCreds = new UsernamePasswordCredentials(crowdProps.getApplicationName(),
                crowdProps.getApplicationPassword());
        httpState.setCredentials(new AuthScope(crowdServer.getHost(), crowdServer.getPort()), crowdCreds);

        // setting Proxy config in place if needed
        if (StringUtils.isNotBlank(crowdProps.getHttpProxyHost()) && crowdProps.getHttpProxyPort() > 0) {
            hc.getHostConfiguration().setProxy(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort());

            if (StringUtils.isNotBlank(crowdProps.getHttpProxyUsername())
                    || StringUtils.isNotBlank(crowdProps.getHttpProxyPassword())) {
                Credentials proxyCreds = new UsernamePasswordCredentials(crowdProps.getHttpProxyUsername(),
                        crowdProps.getHttpProxyPassword());
                httpState.setProxyCredentials(
                        new AuthScope(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort()),
                        proxyCreds);
            }
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("HTTP Client config");
            LOG.debug(crowdServer.toString());
            LOG.debug("Max connections:" + hcConnectionParams.getMaxTotalConnections());
            LOG.debug("Socket timeout:" + hcConnectionParams.getSoTimeout());
            LOG.debug("Connect timeout:" + hcConnectionParams.getConnectionTimeout());
            LOG.debug("Proxy host:" + crowdProps.getHttpProxyHost() + ":" + crowdProps.getHttpProxyPort());
            LOG.debug("Crowd application name:" + crowdProps.getApplicationName());
        }

        client = hc;
    } catch (Exception e) {
        LOG.error("Failure to load the Crowd manager", e);
    }
}

From source file:org.lockss.util.urlconn.LockssUrlConnectionPool.java

public void setMultiThreaded(int maxConn, int maxPerHost) {
    MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = cm.getParams();
    params.setMaxTotalConnections(maxConn);
    params.setDefaultMaxConnectionsPerHost(maxPerHost);
    setTimeouts(params);//from   www.  j a  v  a 2  s.c  om
    hcConnManager = cm;
    if (httpClient != null) {
        httpClient.setHttpConnectionManager(cm);
    }
}