Java Code Examples for org.apache.commons.httpclient.params.HttpConnectionManagerParams#setDefaultMaxConnectionsPerHost()

The following examples show how to use org.apache.commons.httpclient.params.HttpConnectionManagerParams#setDefaultMaxConnectionsPerHost() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpClientFactory.java    From alfresco-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected HttpClient constructHttpClient()
{
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(connectionManager);
    HttpClientParams params = httpClient.getParams();
    params.setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true);
    params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true);
    if (socketTimeout != null) 
    {
        params.setSoTimeout(socketTimeout);
    }
    HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams();
    connectionManagerParams.setMaxTotalConnections(maxTotalConnections);
    connectionManagerParams.setDefaultMaxConnectionsPerHost(maxHostConnections);
    connectionManagerParams.setConnectionTimeout(connectionTimeout);

    return httpClient;
}
 
Example 2
Source File: CoreServerInitializer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private ConfigurationContext getClientConfigurationContext() throws AxisFault {
    String clientRepositoryLocation = serverConfigurationService.getFirstProperty(CLIENT_REPOSITORY_LOCATION);
    String clientAxis2XmlLocationn = serverConfigurationService.getFirstProperty(CLIENT_AXIS2_XML_LOCATION);
    ConfigurationContext clientConfigContextToReturn = ConfigurationContextFactory
            .createConfigurationContextFromFileSystem(clientRepositoryLocation, clientAxis2XmlLocationn);
    MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();

    // Set the default max connections per host
    int defaultMaxConnPerHost = 500;
    Parameter defaultMaxConnPerHostParam = clientConfigContextToReturn.getAxisConfiguration()
            .getParameter("defaultMaxConnPerHost");
    if (defaultMaxConnPerHostParam != null) {
        defaultMaxConnPerHost = Integer.parseInt((String) defaultMaxConnPerHostParam.getValue());
    }
    params.setDefaultMaxConnectionsPerHost(defaultMaxConnPerHost);

    // Set the max total connections
    int maxTotalConnections = 15000;
    Parameter maxTotalConnectionsParam = clientConfigContextToReturn.getAxisConfiguration()
            .getParameter("maxTotalConnections");
    if (maxTotalConnectionsParam != null) {
        maxTotalConnections = Integer.parseInt((String) maxTotalConnectionsParam.getValue());
    }
    params.setMaxTotalConnections(maxTotalConnections);

    params.setSoTimeout(600000);
    params.setConnectionTimeout(600000);

    httpConnectionManager.setParams(params);
    clientConfigContextToReturn
            .setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, httpConnectionManager);

    clientConfigContextToReturn.setProperty(MicroIntegratorBaseConstants.WORK_DIR, serverWorkDir);
    return clientConfigContextToReturn;
}
 
Example 3
Source File: HttpClientBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has
 * been created.
 * 
 * @return the created client.
 */
public HttpClient buildClient() {
    if (httpsProtocolSocketFactory != null) {
        Protocol.registerProtocol("https", new Protocol("https", httpsProtocolSocketFactory, 443));
    }

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication());
    clientParams.setContentCharset(getContentCharSet());
    clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
            connectionRetryAttempts, false));

    HttpConnectionManagerParams connMgrParams = new HttpConnectionManagerParams();
    connMgrParams.setConnectionTimeout(getConnectionTimeout());
    connMgrParams.setDefaultMaxConnectionsPerHost(getMaxConnectionsPerHost());
    connMgrParams.setMaxTotalConnections(getMaxTotalConnections());
    connMgrParams.setReceiveBufferSize(getReceiveBufferSize());
    connMgrParams.setSendBufferSize(getSendBufferSize());
    connMgrParams.setTcpNoDelay(isTcpNoDelay());

    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    connMgr.setParams(connMgrParams);

    HttpClient httpClient = new HttpClient(clientParams, connMgr);

    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        httpClient.setHostConfiguration(hostConfig);

        if (proxyUsername != null) {
            AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
            UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername,
                    proxyPassword);
            httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
        }
    }

    return httpClient;
}
 
Example 4
Source File: OAuthTokenValidationStubFactory.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance of MultiThreadedHttpConnectionManager using HttpClient 3.x APIs
 *
 * @param properties Properties to configure MultiThreadedHttpConnectionManager
 * @return An instance of properly configured MultiThreadedHttpConnectionManager
 */
private HttpConnectionManager createConnectionManager(Properties properties) {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    if (properties == null || properties.isEmpty()) {
        throw new IllegalArgumentException("Parameters required to initialize HttpClient instances " +
                "associated with OAuth token validation service stub are not provided");
    }
    String maxConnectionsPerHostParam = properties.getProperty("MaxConnectionsPerHost");
    if (maxConnectionsPerHostParam == null || maxConnectionsPerHostParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxConnectionsPerHost parameter is not explicitly defined. Therefore, the default, " +
                    "which is 2, will be used");
        }
    } else {
        params.setDefaultMaxConnectionsPerHost(Integer.parseInt(maxConnectionsPerHostParam));
    }

    String maxTotalConnectionsParam = properties.getProperty("MaxTotalConnections");
    if (maxTotalConnectionsParam == null || maxTotalConnectionsParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxTotalConnections parameter is not explicitly defined. Therefore, the default, " +
                    "which is 10, will be used");
        }
    } else {
        params.setMaxTotalConnections(Integer.parseInt(maxTotalConnectionsParam));
    }
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return connectionManager;
}
 
Example 5
Source File: ProxyFilter.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Init the parameter settings for the http client
 */
private HttpConnectionManagerParams connectionParams() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(readMaxHostConnectionSetting());
    params.setMaxTotalConnections(readMaxTotalConnectionSetting());
    return params;

}
 
Example 6
Source File: AutoscalerCloudControllerClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private AutoscalerCloudControllerClient() {
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new
            MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(AS_CC_CLIENT_MAX_CONNECTIONS_PER_HOST);
    params.setMaxTotalConnections(AS_CC_CLIENT_MAX_TOTAL_CONNECTIONS);
    multiThreadedHttpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);

    try {
        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
        ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
        XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
        int port = conf.getInt("autoscaler.cloudController.port", AutoscalerConstants
                .CLOUD_CONTROLLER_DEFAULT_PORT);
        String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost");
        String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX;
        int cloudControllerClientTimeout = conf.getInt("autoscaler.cloudController.clientTimeout", 180000);

        stub = new CloudControllerServiceStub(ctx, epr);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,
                cloudControllerClientTimeout);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean
                .TRUE);
    } catch (Exception e) {
        log.error("Could not initialize cloud controller client", e);
    }
}
 
Example 7
Source File: CloudControllerServiceClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private CloudControllerServiceClient(String epr) throws AxisFault {
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new
            MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(StratosConstants.CLOUD_CONTROLLER_CLIENT_MAX_CONNECTIONS_PER_HOST);
    params.setMaxTotalConnections(StratosConstants.CLOUD_CONTROLLER_CLIENT_MAX_TOTAL_CONNECTIONS);
    multiThreadedHttpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

    String ccSocketTimeout = System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT) == null ?
            StratosConstants.DEFAULT_CLIENT_SOCKET_TIMEOUT :
            System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT);

    String ccConnectionTimeout =
            System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT) == null ?
                    StratosConstants.DEFAULT_CLIENT_CONNECTION_TIMEOUT :
                    System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT);
    try {
        stub = new CloudControllerServiceStub(ctx, epr);
        stub._getServiceClient().getOptions()
                .setProperty(HTTPConstants.SO_TIMEOUT, Integer.valueOf(ccSocketTimeout));
        stub._getServiceClient().getOptions()
                .setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(ccConnectionTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean
                .TRUE);
    } catch (AxisFault axisFault) {
        String msg = "Could not initialize cloud controller service client";
        log.error(msg, axisFault);
        throw new AxisFault(msg, axisFault);
    }
}
 
Example 8
Source File: AutoscalerServiceClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private AutoscalerServiceClient(String epr) throws AxisFault {
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new
            MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(StratosConstants.AUTOSCALER_CLIENT_MAX_CONNECTIONS_PER_HOST);
    params.setMaxTotalConnections(StratosConstants.AUTOSCALER_CLIENT_MAX_TOTAL_CONNECTIONS);
    multiThreadedHttpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

    String autosclaerSocketTimeout = System.getProperty(StratosConstants.AUTOSCALER_CLIENT_SOCKET_TIMEOUT) == null ?
            StratosConstants.DEFAULT_CLIENT_SOCKET_TIMEOUT :
            System.getProperty(StratosConstants.AUTOSCALER_CLIENT_SOCKET_TIMEOUT);

    String autosclaerConnectionTimeout = System.getProperty(StratosConstants.AUTOSCALER_CLIENT_CONNECTION_TIMEOUT)
            == null ? StratosConstants.DEFAULT_CLIENT_CONNECTION_TIMEOUT :
            System.getProperty(StratosConstants.AUTOSCALER_CLIENT_CONNECTION_TIMEOUT);
    try {
        stub = new AutoscalerServiceStub(ctx, epr);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT,
                Integer.valueOf(autosclaerSocketTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,
                Integer.valueOf(autosclaerConnectionTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean
                .TRUE);
    } catch (AxisFault axisFault) {
        String msg = "Could not initialize autoscaler service client";
        log.error(msg, axisFault);
        throw new AxisFault(msg, axisFault);
    }
}
 
Example 9
Source File: StratosManagerServiceClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private StratosManagerServiceClient(String epr) throws AxisFault {
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new
            MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(StratosConstants.STRATOS_MANAGER_CLIENT_MAX_CONNECTIONS_PER_HOST);
    params.setMaxTotalConnections(StratosConstants.STRATOS_MANAGER_CLIENT_MAX_TOTAL_CONNECTIONS);
    multiThreadedHttpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

    String ccSocketTimeout = System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT) == null ?
            StratosConstants.DEFAULT_CLIENT_SOCKET_TIMEOUT :
            System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT);

    String ccConnectionTimeout = System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT)
            == null ?
            StratosConstants.DEFAULT_CLIENT_CONNECTION_TIMEOUT :
            System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT);
    try {
        stub = new StratosManagerServiceStub(ctx, epr);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, Integer.valueOf
                (ccSocketTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, Integer.valueOf
                (ccConnectionTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean
                .TRUE);
    } catch (AxisFault axisFault) {
        String msg = "Could not initialize stratos manager service client";
        log.error(msg, axisFault);
        throw new AxisFault(msg, axisFault);
    }
}