Example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager

List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager

Introduction

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

Prototype

public MultiThreadedHttpConnectionManager() 

Source Link

Usage

From source file:edu.harvard.hmdc.dvnplugin.DVNOAIUrlCacher.java

private HttpClient getClient() {
    if (client == null) {
        client = new HttpClient(new MultiThreadedHttpConnectionManager());
    }/*from w  w  w .j av a  2s .  com*/
    return client;
}

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

public HttpImpl() {

    // Mimic behavior found in
    // http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html

    if (Validator.isNotNull(_NON_PROXY_HOSTS)) {
        String nonProxyHostsRegEx = _NON_PROXY_HOSTS;

        nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\.", "\\\\.");
        nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\*", ".*?");
        nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\|", ")|(");

        nonProxyHostsRegEx = "(" + nonProxyHostsRegEx + ")";

        _nonProxyHostsPattern = Pattern.compile(nonProxyHostsRegEx);
    }/*from  w  w w .j av a 2s  .  com*/

    MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();

    HttpConnectionManagerParams httpConnectionManagerParams = httpConnectionManager.getParams();

    httpConnectionManagerParams.setConnectionTimeout(_TIMEOUT);
    httpConnectionManagerParams.setDefaultMaxConnectionsPerHost(new Integer(_MAX_CONNECTIONS_PER_HOST));
    httpConnectionManagerParams.setMaxTotalConnections(new Integer(_MAX_TOTAL_CONNECTIONS));
    httpConnectionManagerParams.setSoTimeout(_TIMEOUT);

    _httpClient.setHttpConnectionManager(httpConnectionManager);
    _proxyHttpClient.setHttpConnectionManager(httpConnectionManager);

    if (hasProxyConfig() && Validator.isNotNull(_PROXY_USERNAME)) {
        List<String> authPrefs = new ArrayList<String>();

        if (_PROXY_AUTH_TYPE.equals("username-password")) {
            _proxyCredentials = new UsernamePasswordCredentials(_PROXY_USERNAME, _PROXY_PASSWORD);

            authPrefs.add(AuthPolicy.BASIC);
            authPrefs.add(AuthPolicy.DIGEST);
            authPrefs.add(AuthPolicy.NTLM);
        } else if (_PROXY_AUTH_TYPE.equals("ntlm")) {
            _proxyCredentials = new NTCredentials(_PROXY_USERNAME, _PROXY_PASSWORD, _PROXY_NTLM_HOST,
                    _PROXY_NTLM_DOMAIN);

            authPrefs.add(AuthPolicy.NTLM);
            authPrefs.add(AuthPolicy.BASIC);
            authPrefs.add(AuthPolicy.DIGEST);
        }

        HttpClientParams httpClientParams = _proxyHttpClient.getParams();

        httpClientParams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    }
}

From source file:com.wooki.services.parsers.XHTMLToFormattingObjects.java

public void setHttpClient(HttpClient httpClient) {
    this.httpClient = httpClient;
    HttpClientParams params = httpClient.getParams();
    // params./*from w  w w .  j a va  2s.  c o  m*/
    httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
}

From source file:edu.northwestern.jcr.adapter.xtf.persistence.XTFClient.java

/**
 * Sends an HTTP POST request and returns the GetMethod instance.
 *
 * @param url URL of the resource/* ww  w.j  av a  2 s  . c o  m*/
 * @return the PostMethod instance
 */
private PostMethod httpPost(String url) throws Exception {
    PostMethod postMethod;
    MultiThreadedHttpConnectionManager m_cManager;

    m_cManager = new MultiThreadedHttpConnectionManager();
    m_cManager.getParams().setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
    m_cManager.getParams().setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
    m_cManager.getParams().setConnectionTimeout(TIMEOUT_SECONDS * 1000);
    m_cManager.getParams().setSoTimeout(SOCKET_TIMEOUT_SECONDS * 1000);
    HttpClient client = new HttpClient(m_cManager);

    postMethod = new PostMethod(url);
    postMethod.setDoAuthentication(true);
    postMethod.getParams().setParameter("Connection", "Keep-Alive");

    try {
        client.executeMethod(postMethod);
    } catch (Exception e) {
        String msg = "error connecting to the XTF server";
        log.error(msg);
        throw new RepositoryException(msg, null);
    }

    if (postMethod.getStatusCode() != SC_OK) {
        log.warn("status code: " + postMethod.getStatusCode());
    }

    return postMethod;
}

From source file:jp.pigumer.sso.WebSecurityConfig.java

MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager() {
    return new MultiThreadedHttpConnectionManager();
}

From source file:com.alfaariss.oa.profile.aselect.logout.LogoutManager.java

/**
 * Constructor. //from   w  w  w.j ava  2s . c  o m
 * @param profileID The ID of this A-Select Profile.
 * @param configurationManager The configuration manager
 * @param config The configuration section
 * @throws OAException If config could not be read or is invalid.
 */
public LogoutManager(String profileID, IConfigurationManager configurationManager, Element config)
        throws OAException {
    try {
        _logger = LogFactory.getLog(LogoutManager.class);
        _eventLogger = LogFactory.getLog(Engine.EVENT_LOGGER);

        _bEnabled = true;
        if (config != null) {
            String sEnabled = configurationManager.getParam(config, "enabled");
            if (sEnabled != null) {
                if (sEnabled.equalsIgnoreCase("FALSE"))
                    _bEnabled = false;
                else if (!sEnabled.equalsIgnoreCase("TRUE")) {
                    _logger.error("Unknown value in 'enabled' configuration item: " + sEnabled);
                    throw new OAException(SystemErrors.ERROR_CONFIG_READ);
                }
            }
        }

        if (!_bEnabled) {
            _logger.info("Logout Manager: disabled");
        } else {
            Engine engine = Engine.getInstance();
            ITGTFactory tgtFactory = engine.getTGTFactory();
            _aliasStoreSPRole = tgtFactory.getAliasStoreSP();
            _requestorPoolFactory = engine.getRequestorPoolFactory();
            _cryptoManager = engine.getCryptoManager();
            _server = engine.getServer();
            _sProfileID = profileID;

            //Create thread safe HTTP client
            MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
            _httpClient = new HttpClient(connectionManager);

            if (config != null) {
                Element eHTTP = configurationManager.getSection(config, "http");
                if (eHTTP != null)
                    readHTTPConfig(configurationManager, eHTTP);
                else
                    _logger.info(
                            "No optional 'http' section configured, using default http connection settings");
            }

            _logger.info("Logout Manager: enabled");
        }
    } catch (OAException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Could not create logout manager", e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:it.geosolutions.httpproxy.service.impl.ProxyServiceImpl.java

/**
 * Load proxy configuration when proxy config has changed
 *//*from ww  w . j a v  a  2 s.c o m*/
private void loadProxyConfig() {
    connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();

    params.setSoTimeout(proxyConfig.getSoTimeout());
    params.setConnectionTimeout(proxyConfig.getConnectionTimeout());
    params.setMaxTotalConnections(proxyConfig.getMaxTotalConnections());
    params.setDefaultMaxConnectionsPerHost(proxyConfig.getDefaultMaxConnectionsPerHost());

    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);

    configureCallbacks();
}

From source file:com.alfaariss.oa.authentication.remote.AbstractRemoteMethod.java

/**
 * @see IComponent#start(IConfigurationManager, org.w3c.dom.Element)
 *///ww  w .j  a va2s.c o  m
public void start(IConfigurationManager oConfigurationManager, Element eConfig) throws OAException {
    try {
        _configurationManager = oConfigurationManager;

        _sMethodId = _configurationManager.getParam(eConfig, "id");
        if (_sMethodId == null) {
            _logger.error("No 'id' parameter found in configuration");
            throw new OAException(SystemErrors.ERROR_CONFIG_READ);
        }

        _sFriendlyName = _configurationManager.getParam(eConfig, "friendlyname");
        if (_sFriendlyName == null) {
            _logger.error("No 'friendlyname' parameter found in configuration");
            throw new OAException(SystemErrors.ERROR_CONFIG_READ);
        }

        _bEnabled = true;
        String sEnabled = _configurationManager.getParam(eConfig, "enabled");
        if (sEnabled != null) {
            if (sEnabled.equalsIgnoreCase("FALSE"))
                _bEnabled = false;
            else if (!sEnabled.equalsIgnoreCase("TRUE")) {
                _logger.error("Unknown value in 'enabled' configuration item: " + sEnabled);
                throw new OAException(SystemErrors.ERROR_CONFIG_READ);
            }
        }

        _engine = Engine.getInstance();
        _cryptoManager = _engine.getCryptoManager();

        if (_bEnabled) {
            //Create thread safe HTTP client
            MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
            _httpClient = new HttpClient(connectionManager);

            Element eHTTP = _configurationManager.getSection(eConfig, "http");
            if (eHTTP != null)
                readHTTPConfig(eHTTP);
            else
                _logger.info("No optional 'http' section configured, using default http connection settings");

            Element eIDMapper = _configurationManager.getSection(eConfig, "idmapper");
            if (eIDMapper != null)
                _idMapper = createMapper(_configurationManager, eIDMapper);
            else
                _logger.info("No optional 'idmapper' section configured, not using ID Mapper");
        }
    } catch (OAException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Internal error during start", e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:com.google.api.ads.dfp.lib.AuthToken.java

/**
 * Makes the POST to the client login API.
 *
 * @param postMethod the {@code PostMethod} which encapsulates the URL to
 *     post against//from   w  ww. j  ava2s. c  o  m
 * @return an HTTP status code as defined by {@code HttpStatus}
 * @throws IOException if the HTTP client could not establish a
 *     connection
 */
private int postToClientLogin(PostMethod postMethod) throws IOException {
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

    setProxy(httpClient);

    HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams();

    connectionManagerParams.setTcpNoDelay(true);
    connectionManagerParams.setSoTimeout(HTTP_CLIENT_SOCKET_TIMEOUT_IN_MS);
    postMethod.addParameter("Email", email);
    postMethod.addParameter("Passwd", password);
    postMethod.addParameter("accountType", "GOOGLE");
    postMethod.addParameter("service", "gam");
    postMethod.addParameter("source", "google-dfpapi-java");

    if (captchaToken != null) {
        postMethod.addParameter("logintoken", captchaToken);
    }

    if (captchaAnswer != null) {
        postMethod.addParameter("logincaptcha", captchaAnswer);
    }

    return httpClient.executeMethod(postMethod);
}

From source file:com.intuit.autumn.client.impl.HttpCallImplWithConnectionPooling.java

private Client getClient(final HttpCallConfig<T> config) {
    // If either use connection pooling
    if (!config.getUseConnectionPooling() || client == null) {
        MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();

        if (config.getMaxConnectionPerHost().or(-1) > 0) {
            connectionManager.getParams()
                    .setDefaultMaxConnectionsPerHost(config.getMaxConnectionPerHost().get());
        } else {//from   w w  w  . j  a  v  a 2s .c o m
            connectionManager.getParams().setDefaultMaxConnectionsPerHost(20);
        }

        HttpClient httpClient = new HttpClient(connectionManager);
        ApacheHttpClientHandler clientHandler = new ApacheHttpClientHandler(httpClient);
        ClientHandler root = new ApacheHttpClient(clientHandler);
        ClientConfig config1 = new DefaultApacheHttpClientConfig();

        if (config.getProxyURL().isPresent()) {
            String proxyURLWithPort = "http://" + config.getProxyURL() + ':' + config.getProxyPort();

            config1.getProperties().put(PROPERTY_PROXY_URI, proxyURLWithPort);
        }

        client = new Client(root, config1);

        //Setting connection timeouts and read timeouts when present and doing it in the getClient method
        if (config.getConnectionTimeout().or(-1) > 0) {
            client.setConnectTimeout(config.getConnectionTimeout().get());
        }

        if (config.getReadTimeOut().or(-1) > 0) {
            client.setReadTimeout(config.getReadTimeOut().get());
        }

        //Logging the client properties
        LOGGER.info("Created a new client with the following properties set by the application {}",
                client.getProperties().toString());
    }

    return client;
}