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: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);
    // //from  ww w. jav a2  s. c o  m
    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:net.bpelunit.framework.control.run.TestCaseRunner.java

public void run() {
    // Pool connections to avoid socket leaks
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    // Increase maximum per host, as most will use the same host (localhost)
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(10);

    fClient = new HttpClient(connectionManager);

    try {/*w w  w. j a  v  a  2s  .c o m*/
        fLogger.info("Initiating testCase " + fTestCase.getName());
        fServer.startTest(this);

        final List<Thread> threads = new ArrayList<Thread>();
        startPartnerTracks(threads);
        waitForPartnerTracksOrError();

        if (fProblemOccurred || fAbortedByUser) {
            checkPartnerTracksForProblems();
            interruptAllThreads(threads);
            waitForPartnerTracks();
        } else {
            fLogger.info("Test case passed.");
        }
        fLogger.debug("All threads returned.");

        fLogger.info("Stopping testCase " + fTestCase.getName());
        fServer.stopTest(this);
    } finally {
        connectionManager.shutdown();
    }
}

From source file:com.bugclipse.fogbugz.api.client.FogBugzClient.java

public FogBugzClient(String repositoryUrl, String username, String password, Proxy proxy) {
    this.repositoryUrl = repositoryUrl;
    this.username = username;
    this.password = password;
    this.proxy = proxy;
    this.httpClient = new HttpClient();
    httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
}

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);
    // /*w w w. j  a  v  a 2 s  . c  o m*/
    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);
    // /* 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:de.codecentric.jira.jenkins.plugin.servlet.RecentBuildsServlet.java

public RecentBuildsServlet(TemplateRenderer templateRenderer, JiraAuthenticationContext authenticationContext,
        PluginSettingsFactory settingsFactory, ApplicationProperties applicationProperties) {
    this.templateRenderer = templateRenderer;
    this.authenticationContext = authenticationContext;
    this.client = new HttpClient(new MultiThreadedHttpConnectionManager());
    this.serverList = new ServerList(settingsFactory);

    //test if jiraversion < 4.3
    IsPriorToJiraVersion isPrior = new IsPriorToJiraVersion(applicationProperties);
    isPrior.setmaxMajorVersion(4);/* w  w  w.j  av a2 s.c o m*/
    isPrior.setmaxMinorVersion(3);
    this.old = isPrior.shouldDisplay(null);

    client.getParams().setAuthenticationPreemptive(true);

    //set SSLContext to accept all certificates
    try {
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
        SSLContext.setDefault(ctx);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    SecureProtocolSocketFactory secureProtocolSocketFactory = new SSLProtocolSocketFactory();

    Protocol.registerProtocol("https",
            new Protocol("https", (ProtocolSocketFactory) secureProtocolSocketFactory, 443));

}

From source file:de.codecentric.jira.jenkins.plugin.servlet.OverviewServlet.java

public OverviewServlet(TemplateRenderer templateRenderer, JiraAuthenticationContext authenticationContext,
        PluginSettingsFactory settingsFactory, ApplicationProperties applicationProperties) {
    this.templateRenderer = templateRenderer;
    this.authenticationContext = authenticationContext;
    this.serverList = new ServerList(settingsFactory);
    this.client = new HttpClient(new MultiThreadedHttpConnectionManager());

    //test if jiraversion < 4.3
    IsPriorToJiraVersion isPrior = new IsPriorToJiraVersion(applicationProperties);
    isPrior.setmaxMajorVersion(4);//from  w ww  .  ja v  a2s  .  c o m
    isPrior.setmaxMinorVersion(3);
    this.old = isPrior.shouldDisplay(null);

    client.getParams().setAuthenticationPreemptive(true);

    //set SSLContext to accept all certificates
    try {
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
        SSLContext.setDefault(ctx);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    SecureProtocolSocketFactory secureProtocolSocketFactory = new SSLProtocolSocketFactory();

    Protocol.registerProtocol("https",
            new Protocol("https", (ProtocolSocketFactory) secureProtocolSocketFactory, 443));
}

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: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  ava2  s. c o  m
 * @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.unc.lib.dl.util.TripleStoreQueryServiceMulgaraImpl.java

public TripleStoreQueryServiceMulgaraImpl() {
    this.multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
    this.httpClient = new HttpClient(this.multiThreadedHttpConnectionManager);
    this.mapper = new ObjectMapper();
    this.collections = null;
}