Example usage for org.apache.http.impl.client AbstractHttpClient getConnectionManager

List of usage examples for org.apache.http.impl.client AbstractHttpClient getConnectionManager

Introduction

In this page you can find the example usage for org.apache.http.impl.client AbstractHttpClient getConnectionManager.

Prototype

public synchronized final ClientConnectionManager getConnectionManager() 

Source Link

Usage

From source file:org.eclipse.mylyn.commons.http.HttpUtil.java

private static void configureHttpClientConnectionManager(AbstractHttpClient client) {

    ClientConnectionManager connectionManager = client.getConnectionManager();

    HttpConnectionParams.setConnectionTimeout(client.getParams(), CONNNECT_TIMEOUT);
    HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_TIMEOUT);

    if (connectionManager instanceof ThreadSafeClientConnManager) {
        ThreadSafeClientConnManager conMgr = (ThreadSafeClientConnManager) connectionManager;
        // FIXME fix connection leaks
        if (TEST_MODE) {
            conMgr.setDefaultMaxPerRoute(2);
        } else {//from  w  w w.  ja  va  2  s  .  c o m
            conMgr.setDefaultMaxPerRoute(100);
            conMgr.setMaxTotal(1000);
        }
    }
}

From source file:ch.cyberduck.core.http.HttpSession.java

@Override
public void close() {
    try {//from ww w. j  av a2 s  . co  m
        for (AbstractHttpClient http : clients.values()) {
            // When HttpClient instance is no longer needed, shut down the connection manager to ensure
            // immediate deallocation of all system resources
            http.getConnectionManager().shutdown();
        }
    } finally {
        clients.clear();
    }
}

From source file:com.gistlabs.mechanize.integration.test.Issue36Test.java

private AbstractHttpClient buildClient() {
    AbstractHttpClient result = MechanizeAgent.buildDefaultHttpClient();

    System.setProperty("http.proxyHost", "127.0.0.1");
    System.setProperty("http.proxyPort", "8888");

    //             HttpHost proxy = new HttpHost("localhost", 8080);
    //             result.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
            result.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault());
    result.setRoutePlanner(routePlanner);

    return result;
}

From source file:org.expath.httpclient.impl.ApacheHttpConnection.java

/**
 * Make a new Apache HTTP client, in order to serve this request.
 *//*from  w  w w . j  ava  2 s  .c o  m*/
private AbstractHttpClient makeClient() {
    AbstractHttpClient client = new DefaultHttpClient();
    HttpParams params = client.getParams();
    // use the default JVM proxy settings (http.proxyHost, etc.)
    HttpRoutePlanner route = new ProxySelectorRoutePlanner(client.getConnectionManager().getSchemeRegistry(),
            ProxySelector.getDefault());
    client.setRoutePlanner(route);
    // do follow redirections?
    params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, myFollowRedirect);
    // set the timeout if any
    if (myTimeout != null) {
        // See http://blog.jayway.com/2009/03/17/configuring-timeout-with-apache-httpclient-40/
        HttpConnectionParams.setConnectionTimeout(params, myTimeout * 1000);
        HttpConnectionParams.setSoTimeout(params, myTimeout * 1000);
    }
    // the shared cookie store
    client.setCookieStore(COOKIES);
    // the HTTP version (1.0 or 1.1)
    params.setParameter("http.protocol.version", myVersion);
    // return the just built client
    return client;
}

From source file:org.eclipse.mylyn.commons.http.HttpUtil.java

public static HttpContext getHttpContext(AbstractHttpClient client, AbstractWebLocation location,
        HttpContext previousContext, IProgressMonitor progressMonitor) {

    Assert.isNotNull(client);//from   ww  w .  ja  v a  2s .c  o m
    Assert.isNotNull(location);

    String url = location.getUrl();
    String host = getHost(url);
    int port = getPort(url);

    configureHttpClientConnectionManager(client);

    HttpContext context = previousContext;
    if (context == null) {
        context = new BasicHttpContext();
    }
    configureHttpClientProxy(client, context, location);

    AuthenticationCredentials authCreds = location.getCredentials(AuthenticationType.HTTP);
    if (authCreds != null) {
        AuthScope authScope = new AuthScope(host, port, AuthScope.ANY_REALM);
        Credentials credentials = getHttpClientCredentials(authCreds, host);

        if (credentials instanceof NTCredentials) {
            List<String> authpref = new ArrayList<String>();
            authpref.add(AuthPolicy.NTLM);
            authpref.add(AuthPolicy.BASIC);
            authpref.add(AuthPolicy.DIGEST);
            client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
        } else {
            List<String> authpref = new ArrayList<String>();
            authpref.add(AuthPolicy.BASIC);
            authpref.add(AuthPolicy.DIGEST);
            authpref.add(AuthPolicy.NTLM);
            client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
        }
        client.getCredentialsProvider().setCredentials(authScope, credentials);
    }

    if (isRepositoryHttps(url)) {
        Scheme sch = new Scheme("https", HTTPS_PORT, sslSocketFactory); //$NON-NLS-1$
        client.getConnectionManager().getSchemeRegistry().register(sch);
    } else {
        Scheme sch = new Scheme("http", HTTP_PORT, socketFactory); //$NON-NLS-1$
        client.getConnectionManager().getSchemeRegistry().register(sch);
    }

    return context;

}