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

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

Introduction

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

Prototype

HttpConnectionManagerParams

Source Link

Usage

From source file:net.sourceforge.jcctray.model.HTTPCruise.java

private static HttpClient getClient(Host host) {
    SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
    HttpConnectionManagerParams connParams = new HttpConnectionManagerParams();
    connParams.setConnectionTimeout(JCCTraySettings.getInstance().getInt(ISettingsConstants.HTTP_TIMEOUT));
    connParams.setSoTimeout(JCCTraySettings.getInstance().getInt(ISettingsConstants.HTTP_TIMEOUT));
    connectionManager.setParams(connParams);
    HttpClient client = new HttpClient(connectionManager);

    client.getParams().setAuthenticationPreemptive(true);
    if (!StringUtils.isEmptyOrNull(host.getHostName()) && !StringUtils.isEmptyOrNull(host.getPassword())) {
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(host.getUsername(),
                host.getPassword());//from  w  w w. j a va2s. c  om
        client.getState().setCredentials(new AuthScope(null, -1, null, null), credentials);
    }

    return client;
}

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);
    }//from ww  w .  j  av a  2s  .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  w  w. ja  v  a  2s. c  o m*/

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

From source file:com.legstar.test.cixs.AbstractHttpClientTester.java

/**
 * Setup the static http connection pool.
 * /*  ww w.  ja  va 2s  .com*/
 * @return an http client instance
 */
protected static HttpClient createHttpClient() {

    HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();

    connectionManagerParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
    connectionManagerParams.setDefaultMaxConnectionsPerHost(DEFAULT_MAX_CONNECTIONS_PER_HOST);
    connectionManagerParams.setTcpNoDelay(TCP_NO_DELAY);
    connectionManagerParams.setSoTimeout(SOCKET_TIMEOUT);
    connectionManagerParams.setConnectionTimeout(CONNECT_TIMEOUT);

    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(connectionManagerParams);
    connectionManager.closeIdleConnections(IDLE_CONNECTION_TIMEOUT);
    return new HttpClient(connectionManager);
}

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

/**
 * Constructor/*from  w  w w  .  ja v a2 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.duowan.common.rpc.client.CommonsHttpInvokerRequestExecutor.java

/**
 * Create a new CommonsHttpInvokerRequestExecutor with a default
 * HttpClient that uses a default MultiThreadedHttpConnectionManager.
 * Sets the socket read timeout to {@link #DEFAULT_READ_TIMEOUT_MILLISECONDS}.
 * @see org.apache.commons.httpclient.HttpClient
 * @see org.apache.commons.httpclient.MultiThreadedHttpConnectionManager
 *//*w w w.  j av a  2  s  . c o m*/
public CommonsHttpInvokerRequestExecutor() {
    MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(300);
    params.setMaxTotalConnections(500);
    httpConnectionManager.setParams(params);

    this.httpClient = new HttpClient(httpConnectionManager);
    this.setReadTimeout(getReadTimeout());
    this.setConnectionTimeout(getConnectionTimeout());
}

From source file:de.fuberlin.wiwiss.marbles.loading.SemanticWebClient.java

/**
 * Constructs a new <code>SemanticWebClient</code>
 * /*from   w  w w  .  j a  v a  2s  . com*/
 * @param cacheController
 * @param spongerProvider
 * @param dataProviders
 */
public SemanticWebClient(CacheController cacheController, SpongerProvider spongerProvider,
        Collection<DataProvider> dataProviders) {
    this.cacheController = cacheController;
    this.dataProviders = dataProviders;

    /* Set connection parameters */
    HttpConnectionManagerParams httpManagerParams = new HttpConnectionManagerParams();
    httpManagerParams.setConnectionTimeout(CONNECTION_TIMEOUT * 1000);
    httpManagerParams.setTcpNoDelay(true);
    httpManagerParams.setStaleCheckingEnabled(true);

    MultiThreadedHttpConnectionManager httpManager = new MultiThreadedHttpConnectionManager();
    httpManager.setParams(httpManagerParams);

    httpClient = new HttpClient(httpManager);
    uriQueue = new DereferencingTaskQueue(httpClient, spongerProvider, 10 /* maxThreads */,
            500 * 1024 /* maxFileSize */);
}

From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java

/**
 * Create the {@link HttpClient} object//w ww  . j  a v  a  2 s . co  m
 */
private void createClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setConnectionTimeout(TIMEOUT_MS);
    params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS);
    params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);
    configureCredentials();
    if (StringUtils.isNotBlank(System.getProperty("http.proxyHost"))) {
        log.debug("A HTTP Proxy is configured");
        System.setProperty("java.net.useSystemProxies", "true");
        Proxy proxy = chooseProxy();
        if (proxy.type() == Type.HTTP && proxy.address() instanceof InetSocketAddress) {
            // convert the socket address to an ProxyHost
            final InetSocketAddress isa = (InetSocketAddress) proxy.address();
            // assume default scheme (http)
            ProxyHost proxyHost = new ProxyHost(getHost(isa), isa.getPort());
            httpClient.getHostConfiguration().setProxyHost(proxyHost);
            if (StringUtils.isNotBlank(System.getProperty("http.proxyUser"))) {
                String user = System.getProperty("http.proxyUser");
                String password = System.getProperty("http.proxyPassword");
                httpClient.getState().setProxyCredentials(new AuthScope(getHost(isa), isa.getPort()),
                        new UsernamePasswordCredentials(user, password));
            }
        }
    }
}

From source file:cn.leancloud.diamond.client.processor.ServerAddressProcessor.java

private void initHttpClient() {
    HostConfiguration hostConfiguration = new HostConfiguration();

    SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
    connectionManager.closeIdleConnections(5000L);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    connectionManager.setParams(params);

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

From source file:com.creditease.bdp.axis2.transport.http.HTTPSender.java

@Override
protected HttpClient getHttpClient(MessageContext msgContext) {
    ConfigurationContext configContext = msgContext.getConfigurationContext();

    HttpClient httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);

    if (httpClient == null) {
        httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
    }// w  w w.ja va2 s.c o m

    if (httpClient != null) {
        return httpClient;
    }

    synchronized (this) {
        httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);

        if (httpClient == null) {
            httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
        }

        if (httpClient != null) {
            return httpClient;
        }

        HttpConnectionManager connManager = (HttpConnectionManager) msgContext
                .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
        if (connManager == null) {
            connManager = (HttpConnectionManager) msgContext
                    .getProperty(HTTPConstants.MUTTITHREAD_HTTP_CONNECTION_MANAGER);
        }
        if (connManager == null) {
            // reuse HttpConnectionManager
            synchronized (configContext) {
                connManager = (HttpConnectionManager) configContext
                        .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
                if (connManager == null) {
                    log.trace("Making new ConnectionManager");
                    connManager = new MultiThreadedHttpConnectionManager();
                    // NOTE: Added by CJ
                    Integer maxConnectionPerHostConf = (Integer) msgContext
                            .getProperty(Constants.MAX_CONNECTIONS_PER_HOST);
                    Integer maxConnectionTotalConf = (Integer) msgContext
                            .getProperty(Constants.MAX_CONNECTIONS_TOTAL);
                    if (maxConnectionPerHostConf != null || maxConnectionTotalConf != null) {
                        HttpConnectionManagerParams param = new HttpConnectionManagerParams();
                        if (maxConnectionPerHostConf != null) {
                            param.setDefaultMaxConnectionsPerHost(maxConnectionPerHostConf);
                        }
                        if (maxConnectionTotalConf != null) {
                            param.setMaxTotalConnections(maxConnectionTotalConf);
                        }
                        connManager.setParams(param);
                    }
                    configContext.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connManager);
                }
            }
        }
        /*
         * Create a new instance of HttpClient since the way
         * it is used here it's not fully thread-safe.
         */
        httpClient = new HttpClient(connManager);

        // Set the default timeout in case we have a connection pool starvation to 30sec
        httpClient.getParams().setConnectionManagerTimeout(30000);

        // Get the timeout values set in the runtime
        initializeTimeouts(msgContext, httpClient);

        return httpClient;
    }
}