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

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

Introduction

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

Prototype

public int getMaxTotalConnections() 

Source Link

Usage

From source file:com.zimbra.common.util.ZimbraHttpConnectionManager.java

private static String dumpParams(String notes, HttpConnectionManagerParams connMgrParams,
        HttpClientParams clientParams) {
    // dump httpclient package defaults if params is null
    if (connMgrParams == null)
        connMgrParams = new HttpConnectionManagerParams();
    if (clientParams == null)
        clientParams = new HttpClientParams();

    StringBuilder sb = new StringBuilder();

    sb.append("======== " + notes + "========\n");

    sb.append("HttpConnectionManagerParams DefaultMaxConnectionsPerHost  : "
            + connMgrParams.getDefaultMaxConnectionsPerHost() + "\n");
    sb.append("HttpConnectionManagerParams MaxTotalConnections           : "
            + connMgrParams.getMaxTotalConnections() + "\n");

    sb.append("HttpConnectionParams ConnectionTimeout                    : "
            + connMgrParams.getConnectionTimeout() + "\n");
    sb.append(// w  w w  . ja v  a  2  s  .  co  m
            "HttpConnectionParams Linger                               : " + connMgrParams.getLinger() + "\n");
    sb.append("HttpConnectionParams ReceiveBufferSize                    : "
            + connMgrParams.getReceiveBufferSize() + "\n");
    sb.append("HttpConnectionParams SendBufferSize                       : " + connMgrParams.getSendBufferSize()
            + "\n");
    sb.append("HttpConnectionParams SoTimeout                            : " + connMgrParams.getSoTimeout()
            + "\n");
    sb.append("HttpConnectionParams TcpNoDelay                           : " + connMgrParams.getTcpNoDelay()
            + "\n");
    sb.append("HttpConnectionParams isStaleCheckingEnabled               : "
            + connMgrParams.isStaleCheckingEnabled() + "\n");

    // sb.append("HttpClientParams ALLOW_CIRCULAR_REDIRECTS            (no corresponding method?)
    sb.append("HttpClientParams ConnectionManagerClass               : "
            + clientParams.getConnectionManagerClass().getName() + "\n");
    sb.append("HttpClientParams ConnectionManagerTimeout             : "
            + clientParams.getConnectionManagerTimeout() + "\n");
    // sb.append("HttpClientParams MAX_REDIRECTS                       (no corresponding method?)
    sb.append("HttpClientParams isAuthenticationPreemptive()         : "
            + clientParams.isAuthenticationPreemptive() + "\n");
    // sb.append("HttpClientParams REJECT_RELATIVE_REDIRECT            (no corresponding method?)

    return sb.toString();
}

From source file:org.apache.camel.component.http.HttpConnectionManagerSettingTest.java

@Test
public void testHttpConnectionManagerSettingConfiguration() {
    HttpEndpoint endpoint = (HttpEndpoint) context
            .getEndpoint("http://www.google.com?httpConnectionManager.maxTotalConnections=300");
    HttpConnectionManagerParams params = endpoint.getHttpConnectionManager().getParams();
    assertEquals("Get the wrong parameter.", 300, params.getMaxTotalConnections());
}

From source file:org.bibsonomy.recommender.tags.WebserviceTagRecommender.java

/**
 * inits the recommender/*w  w w. j  av a 2  s  .com*/
 */
public WebserviceTagRecommender() {
    // Create an instance of HttpClient.
    connectionManager = new IdleClosingConnectionManager();// MultiThreadedHttpConnectionManager();
    client = new HttpClient(connectionManager);

    // set default timeouts
    final HttpConnectionManagerParams connectionParams = connectionManager.getParams();
    connectionParams.setSoTimeout(SOCKET_TIMEOUT_MS);
    connectionParams.setConnectionTimeout(HTTP_CONNECTION_TIMEOUT_MS);
    connectionManager.setParams(connectionParams);
    log.debug("MAXCONNECTIONS: " + connectionParams.getMaxTotalConnections());
    log.debug("MAXCONNECTIONSPERHOST: " + connectionParams.getDefaultMaxConnectionsPerHost());

    // handle idle connections
    connectionManager.closeIdleConnections(IDLE_TIMEOUT_MS);
    idleConnectionHandler = new IdleConnectionTimeoutThread();
    idleConnectionHandler.addConnectionManager(connectionManager);
    idleConnectionHandler.start();

    this.renderer = new RendererFactory(new UrlRenderer("/api/")).getRenderer(RenderingFormat.XML);
}

From source file:org.eclipse.mylyn.commons.tests.net.WebUtilTest.java

public void testConfigureClient() throws Exception {
    WebLocation location = new WebLocation(TestUrl.DEFAULT.getHttpOk().toString());

    WebUtil.createHostConfiguration(client, location, null /*monitor*/);

    HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
    assertEquals(CoreUtil.TEST_MODE ? 2 : MAX_HTTP_HOST_CONNECTIONS_DEFAULT,
            params.getMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION));
    assertEquals(CoreUtil.TEST_MODE ? 20 : MAX_HTTP_TOTAL_CONNECTIONS_DEFAULT, params.getMaxTotalConnections());
}

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

private CrowdManager() {
    try {//ww w . j a  va2  s . c o m
        // 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.mule.transport.http.HttpConnectorTestCase.java

@Test
public void testProperties() throws Exception {
    HttpConnector c = (HttpConnector) getConnector();

    c.setSendBufferSize(1024);//from  ww w .  j  a va2s  .c  o m
    assertEquals(1024, c.getSendBufferSize());
    c.setSendBufferSize(0);
    assertEquals(TcpConnector.DEFAULT_BUFFER_SIZE, c.getSendBufferSize());

    int maxDispatchers = c.getMaxTotalDispatchers();
    HttpConnectionManagerParams params = c.getClientConnectionManager().getParams();
    assertEquals(maxDispatchers, params.getDefaultMaxConnectionsPerHost());
    assertEquals(maxDispatchers, params.getMaxTotalConnections());

    // all kinds of timeouts are now being tested in TcpConnectorTestCase
}