Example usage for org.apache.commons.httpclient.params HostParams setIntParameter

List of usage examples for org.apache.commons.httpclient.params HostParams setIntParameter

Introduction

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

Prototype

public void setIntParameter(String paramString, int paramInt) 

Source Link

Usage

From source file:com.liferay.portal.util.HttpImpl.java

public HostConfiguration getHostConfiguration(String location) throws IOException {

    if (_log.isDebugEnabled()) {
        _log.debug("Location is " + location);
    }/* w w  w.j av a  2 s .  c o m*/

    HostConfiguration hostConfiguration = new HostConfiguration();

    hostConfiguration.setHost(new URI(location, false));

    if (isProxyHost(hostConfiguration.getHost())) {
        hostConfiguration.setProxy(_PROXY_HOST, _PROXY_PORT);
    }

    HttpConnectionManager httpConnectionManager = _httpClient.getHttpConnectionManager();

    HttpConnectionManagerParams httpConnectionManagerParams = httpConnectionManager.getParams();

    int defaultMaxConnectionsPerHost = httpConnectionManagerParams.getMaxConnectionsPerHost(hostConfiguration);

    int maxConnectionsPerHost = GetterUtil.getInteger(PropsUtil.get(
            HttpImpl.class.getName() + ".max.connections.per.host", new Filter(hostConfiguration.getHost())));

    if ((maxConnectionsPerHost > 0) && (maxConnectionsPerHost != defaultMaxConnectionsPerHost)) {

        httpConnectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, maxConnectionsPerHost);
    }

    int timeout = GetterUtil.getInteger(
            PropsUtil.get(HttpImpl.class.getName() + ".timeout", new Filter(hostConfiguration.getHost())));

    if (timeout > 0) {
        HostParams hostParams = hostConfiguration.getParams();

        hostParams.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, timeout);
        hostParams.setIntParameter(HttpConnectionParams.SO_TIMEOUT, timeout);
    }

    return hostConfiguration;
}