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:autohit.call.modules.SimpleHttpModule.java

/**
 * Start method for an HTTPS session. It will set the target address for the client, as well as
 * clearing any state./* www . j  a va2 s  . co  m*/
 * 
 * @param addr
 *            the address. Do not include protocol, but you may add port
 *            (ie. "www.goatland.com:443").
 * @throws CallException
 */
private void starthttps(String addr, int port) throws CallException {

    try {
        // buidl protocol
        Protocol myhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), port);

        httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
        creds = null;
        HttpState initialState = new HttpState();
        initialState.setCookiePolicy(CookiePolicy.COMPATIBILITY);
        httpClient.setState(initialState);
        httpClient.setConnectionTimeout(DEFAULT_TIMEOUT);
        httpClient.getHostConfiguration().setHost(addr, port, myhttps);

    } catch (Exception ex) {
        throw new CallException(
                "Serious fault while creating session with start method.  Session is not valid.  error="
                        + ex.getMessage(),
                CallException.CODE_MODULE_FAULT, ex);
    }

    // NO CODE AFTER THIS!
    started = true;
}

From source file:com.owncloud.android.network.OwnCloudClientUtils.java

static private MultiThreadedHttpConnectionManager getMultiThreadedConnManager() {
    if (mConnManager == null) {
        mConnManager = new MultiThreadedHttpConnectionManager();
        mConnManager.getParams().setDefaultMaxConnectionsPerHost(5);
        mConnManager.getParams().setMaxTotalConnections(5);
    }/*w ww  .  j a va  2s .c o m*/
    return mConnManager;
}

From source file:eionet.cr.harvest.PullHarvest.java

/**
 *
 * @return/*from   ww  w  .ja v  a2 s .  co m*/
 */
private EndpointHttpClient prepareEndpointHttpClient() {

    HttpConnectionManagerParams managerParams = new HttpConnectionManagerParams();
    managerParams.setDefaultMaxConnectionsPerHost(20);
    managerParams.setStaleCheckingEnabled(false);

    int httpTimeout = GeneralConfig.getIntProperty(GeneralConfig.HARVESTER_HTTP_TIMEOUT, getTimeout());
    managerParams.setConnectionTimeout(httpTimeout);
    managerParams.setSoTimeout(httpTimeout);

    HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    manager.setParams(managerParams);

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setParameter("http.useragent", URLUtil.userAgentHeader());
    clientParams.setParameter("http.protocol.max-redirects", MAX_REDIRECTIONS);

    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put("Connection", "close");
    clientParams.setParameter("additionalHTTPHeaders", headers);

    return new EndpointHttpClient(clientParams, manager);
}

From source file:com.zenkey.net.prowser.Tab.java

/**************************************************************************
 * Constructs and initializes a new <code>Tab</code> object for the
 * specified Prowser, and then visits the home page if requested.
 *
 * @param prowser/*from w  ww.j a v a  2s  . c o m*/
 * @param loadHomePage
 */
/* package */ Tab(Prowser prowser, boolean loadHomePage) {

    // Record the prowser of this Tab instance
    this.prowser = prowser;

    // Create an HttpClient instance to handle this Tab's requests
    httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

    // Set the cookies that are shared across all tabs of owning Prowser 
    httpClient.setState(prowser.getHttpState());

    // Set the default HTTP version for the HttpClient
    setHttpClientHttpVersion(prowser.getDefaultHttpVersion());

    // Set the default HTTP user-agent for the HttpClient
    setHttpClientUserAgent(prowser.getDefaultUserAgent());

    // If the home page should be loaded first into this Tab, do it
    if (loadHomePage)
        goHome();
}

From source file:com.xerox.amazonws.common.AWSQueryConnection.java

private void configureHttpClient() {
    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams connParams = connMgr.getParams();
    connParams.setMaxTotalConnections(maxConnections);
    connParams.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxConnections);
    connMgr.setParams(connParams);//  w w  w  .  jav  a2 s.c  o  m
    hc = new HttpClient(connMgr);
    // NOTE: These didn't seem to help in my initial testing
    //         hc.getParams().setParameter("http.tcp.nodelay", true);
    //         hc.getParams().setParameter("http.connection.stalecheck", false); 
    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        hc.setHostConfiguration(hostConfig);
        log.info("Proxy Host set to " + proxyHost + ":" + proxyPort);
        if (proxyUser != null && !proxyUser.trim().equals("")) {
            if (proxyDomain != null) {
                hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort),
                        new NTCredentials(proxyUser, proxyPassword, proxyHost, proxyDomain));
            } else {
                hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort),
                        new UsernamePasswordCredentials(proxyUser, proxyPassword));
            }
        }
    }
}

From source file:it.infn.mw.iam.config.saml.SamlConfig.java

@Bean
public MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager() {

    return new MultiThreadedHttpConnectionManager();
}

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);
    }//from  w ww  . j a  v  a  2s  .  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.

}

From source file:mitm.common.sms.transport.clickatell.ClickatellSMSTransport.java

private synchronized MultiThreadedHttpConnectionManager getConnectionManager() {
    if (connectionManager == null) {
        connectionManager = new MultiThreadedHttpConnectionManager();
    }/*ww w  .j a  va 2  s  .  c  om*/

    return connectionManager;
}

From source file:com.idega.slide.business.IWSlideServiceBean.java

@SuppressWarnings("deprecation")
private HttpClient getHttpClient(HttpURL url, UsernamePasswordCredentials credentials) throws Exception {
    HttpSession currentSession = getCurrentSession();

    HttpState state = new WebdavState();
    AuthScope authScope = new AuthScope(url.getHost(), url.getPort());
    state.setCredentials(authScope, credentials);
    if (currentSession != null) {
        IWTimestamp iwExpires = new IWTimestamp(System.currentTimeMillis());
        iwExpires.setMinute(iwExpires.getMinute() + 30);
        Date expires = new Date(iwExpires.getTimestamp().getTime());

        boolean secure = url instanceof HttpsURL;

        Cookie cookie = new Cookie(url.getHost(), CoreConstants.PARAMETER_SESSION_ID, currentSession.getId(),
                CoreConstants.SLASH, expires, secure);
        state.addCookie(cookie);/*from   w w  w .j  a va2 s .  co  m*/
    }

    HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
    client.setState(state);

    HostConfiguration hostConfig = client.getHostConfiguration();
    hostConfig.setHost(url);

    Credentials hostCredentials = null;

    if (credentials == null) {
        String userName = url.getUser();
        if (userName != null && userName.length() > 0) {
            hostCredentials = new UsernamePasswordCredentials(userName, url.getPassword());
        }
    }

    if (hostCredentials != null) {
        HttpState clientState = client.getState();
        clientState.setCredentials(null, url.getHost(), hostCredentials);
        clientState.setAuthenticationPreemptive(true);
    }

    return client;
}

From source file:com.cloud.utils.UriUtils.java

public static InputStream getInputStreamFromUrl(String url, String user, String password) {

    try {/*from w ww  . j a v a2s  .  co m*/
        Pair<String, Integer> hostAndPort = validateUrl(url);
        HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
        if ((user != null) && (password != null)) {
            httpclient.getParams().setAuthenticationPreemptive(true);
            Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
            httpclient.getState().setCredentials(
                    new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM),
                    defaultcreds);
            s_logger.info("Added username=" + user + ", password=" + password + "for host "
                    + hostAndPort.first() + ":" + hostAndPort.second());
        }
        // Execute the method.
        GetMethod method = new GetMethod(url);
        int statusCode = httpclient.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            s_logger.error("Failed to read from URL: " + url);
            return null;
        }

        return method.getResponseBodyAsStream();
    } catch (Exception ex) {
        s_logger.error("Failed to read from URL: " + url);
        return null;
    }
}