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

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

Introduction

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

Prototype

public HttpConnectionManagerParams getParams() 

Source Link

Usage

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

/**
 * Sends an HTTP GET request and returns the GetMethod instance.
 *
 * @param url URL of the resource/*from w w w  . j a  va  2  s . c  om*/
 * @return the GetMethod instance
 */
private GetMethod httpGet(String url) throws Exception {
    GetMethod getMethod;
    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);

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

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

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

    return getMethod;
}

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  2s .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:com.polarion.alm.ws.client.internal.connection.CommonsHTTPSender.java

protected void initialize() {
    MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager();
    this.clientProperties = CommonsHTTPClientPropertiesFactory.create();
    cm.getParams().setDefaultMaxConnectionsPerHost(clientProperties.getMaximumConnectionsPerHost());
    cm.getParams().setMaxTotalConnections(clientProperties.getMaximumTotalConnections());
    // If defined, set the default timeouts
    // Can be overridden by the MessageContext
    if (this.clientProperties.getDefaultConnectionTimeout() > 0) {
        cm.getParams().setConnectionTimeout(this.clientProperties.getDefaultConnectionTimeout());
    }//from  w w w .ja v a2s .  com
    if (this.clientProperties.getDefaultSoTimeout() > 0) {
        cm.getParams().setSoTimeout(this.clientProperties.getDefaultSoTimeout());
    }
    cm.getParams().setStaleCheckingEnabled(false);

    this.connectionManager = cm;
}

From source file:com.taobao.diamond.sdkapi.impl.DiamondSDKManagerImpl.java

public DiamondSDKManagerImpl(int connection_timeout, int require_timeout) throws IllegalArgumentException {
    if (connection_timeout < 0)
        throw new IllegalArgumentException("0[()]!");
    if (require_timeout < 0)
        throw new IllegalArgumentException("0[()]!");
    this.connection_timeout = connection_timeout;
    this.require_timeout = require_timeout;
    int maxHostConnections = 50;
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();

    connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxHostConnections);
    connectionManager.getParams().setStaleCheckingEnabled(true);
    this.client = new HttpClient(connectionManager);
    // /*w  w w  . j ava2 s. c  om*/
    client.getHttpConnectionManager().getParams().setConnectionTimeout(this.connection_timeout);
    // 1
    client.getHttpConnectionManager().getParams().setSoTimeout(60 * 1000);
    client.getParams().setContentCharset("GBK");
    log.info(": " + this.connection_timeout + "");
}

From source file:com.mengka.diamond.sdkapi.impl.DiamondSDKManagerImpl.java

public DiamondSDKManagerImpl(int connection_timeout, int require_timeout) throws IllegalArgumentException {
    if (connection_timeout < 0)
        throw new IllegalArgumentException("0[??()]!");
    if (require_timeout < 0)
        throw new IllegalArgumentException("0[??()]!");
    this.connection_timeout = connection_timeout;
    this.require_timeout = require_timeout;
    int maxHostConnections = 50;
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();

    connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxHostConnections);
    connectionManager.getParams().setStaleCheckingEnabled(true);
    this.client = new HttpClient(connectionManager);
    // //from w w  w  .j a  v  a 2s  . com
    client.getHttpConnectionManager().getParams().setConnectionTimeout(this.connection_timeout);
    // 1
    client.getHttpConnectionManager().getParams().setSoTimeout(60 * 1000);
    client.getParams().setContentCharset("GBK");
    log.info(": " + this.connection_timeout + "");
}

From source file:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java

public DiamondSDKManagerImpl(int connection_timeout, int require_timeout) throws IllegalArgumentException {
    if (connection_timeout < 0)
        throw new IllegalArgumentException("0[??()]!");
    if (require_timeout < 0)
        throw new IllegalArgumentException("0[??()]!");
    this.connection_timeout = connection_timeout;
    this.require_timeout = require_timeout;
    int maxHostConnections = 50;
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();

    connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxHostConnections);
    connectionManager.getParams().setStaleCheckingEnabled(true);
    this.client = new HttpClient(connectionManager);
    // //from  w w  w. j a  v  a2  s  . c  o m
    client.getHttpConnectionManager().getParams().setConnectionTimeout(this.connection_timeout);
    // 1
    client.getHttpConnectionManager().getParams().setSoTimeout(60 * 1000);
    client.getParams().setContentCharset("UTF-8");
    log.info(": " + this.connection_timeout + "");
}

From source file:com.jaspersoft.ireport.jasperserver.ws.CommonsHTTPSender.java

protected void initialize() {

    httpChunkStream = !IReportManager.getPreferences().getBoolean("jasperserver.preventChunkedRequests", true);

    IReportManager.getPreferences().addPreferenceChangeListener(new PreferenceChangeListener() {

        public void preferenceChange(PreferenceChangeEvent pce) {
            CommonsHTTPSender.this.httpChunkStream = !IReportManager.getPreferences()
                    .getBoolean("jasperserver.preventChunkedRequests", true);
        }/*from  ww w . ja  v a  2  s  .  c  om*/
    });

    MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager();
    this.clientProperties = CommonsHTTPClientPropertiesFactory.create();
    cm.getParams().setDefaultMaxConnectionsPerHost(clientProperties.getMaximumConnectionsPerHost());
    cm.getParams().setMaxTotalConnections(clientProperties.getMaximumTotalConnections());
    // If defined, set the default timeouts
    // Can be overridden by the MessageContext
    if (this.clientProperties.getDefaultConnectionTimeout() > 0) {
        cm.getParams().setConnectionTimeout(this.clientProperties.getDefaultConnectionTimeout());
    }
    if (this.clientProperties.getDefaultSoTimeout() > 0) {
        cm.getParams().setSoTimeout(this.clientProperties.getDefaultSoTimeout());
    }
    this.connectionManager = cm;
}

From source file:gov.va.med.imaging.proxy.ImageXChangeHttpCommonsSender.java

protected void initialize() {
    MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager();
    this.clientProperties = CommonsHTTPClientPropertiesFactory.create();
    cm.getParams().setDefaultMaxConnectionsPerHost(clientProperties.getMaximumConnectionsPerHost());
    cm.getParams().setMaxTotalConnections(clientProperties.getMaximumTotalConnections());

    // If defined, set the default timeouts
    // Can be overridden by the MessageContext
    if (this.clientProperties.getDefaultConnectionTimeout() > 0)
        cm.getParams().setConnectionTimeout(this.clientProperties.getDefaultConnectionTimeout());

    if (this.clientProperties.getDefaultSoTimeout() > 0)
        cm.getParams().setSoTimeout(this.clientProperties.getDefaultSoTimeout());

    this.connectionManager = cm;
}

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);
    }// w  w w  . j  ava2  s.c o m

    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.sittinglittleduck.DirBuster.Manager.java

private void createHttpClient() {
    Protocol protocol = Protocol.getProtocol("https");
    if (protocol == null) {
        // ZAP: Dont override an existing protocol - it causes problems with ZAP
        Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        Protocol.registerProtocol("https", easyhttps);
    }/*  w  w  w.j ava2 s . c  o  m*/
    initialState = new HttpState();

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(1000);
    connectionManager.getParams().setMaxTotalConnections(1000);

    // connectionManager.set

    httpclient = new HttpClient(connectionManager);
    // httpclient.

}