Example usage for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager

List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager

Introduction

In this page you can find the example usage for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager.

Prototype

public PoolingClientConnectionManager() 

Source Link

Usage

From source file:com.fun.util.HttpClientUtil.java

private HttpClientUtil(String ip, String port) {
    if (StringUtils.isNotBlank(ip) && NumberUtils.isDigits(port)) {
        HttpHost proxy = new HttpHost(ip, Integer.parseInt(port));
        DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
        this.client = this.setRoutePlanner(routePlanner).setMaxConnPerRoute(50).setMaxConnTotal(200).build();
        return;//from ww  w .j  av  a  2  s.c o  m
    }

    connectionManager = new PoolingClientConnectionManager();
    connectionManager.setDefaultMaxPerRoute(50);
    connectionManager.setMaxTotal(200);
    this.client = new DefaultHttpClient(HttpClientUtil.connectionManager);
}

From source file:com.basho.riak.client.http.util.ClientUtils.java

/**
 * Construct a new {@link HttpClient} instance given a {@link RiakConfig}.
 * //w w w.  jav  a2s .co m
 * @param config
 *            {@link RiakConfig} containing HttpClient configuration
 *            specifics.
 * @return A new {@link HttpClient}
 */
public static HttpClient newHttpClient(RiakConfig config) {

    HttpClient http = config.getHttpClient();
    ClientConnectionManager m;

    if (http == null) {
        m = new PoolingClientConnectionManager();
        if (config.getMaxConnections() != null) {
            ((PoolingClientConnectionManager) m).setMaxTotal(config.getMaxConnections());
            ((PoolingClientConnectionManager) m).setDefaultMaxPerRoute(config.getMaxConnections());
        }
        http = new DefaultHttpClient(m);

        if (config.getRetryHandler() != null) {
            ((DefaultHttpClient) http).setHttpRequestRetryHandler(config.getRetryHandler());
        }
    }

    HttpParams cp = http.getParams();
    if (config.getTimeout() != null) {
        cp.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, config.getTimeout());
        cp.setIntParameter(AllClientPNames.SO_TIMEOUT, config.getTimeout());
    }

    return http;
}

From source file:com.emc.vipr.ribbon.ViPRDataServicesServerList.java

public ViPRDataServicesServerList() {
    rfc822DateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
    try {//ww w.  j av  a 2 s  .c  om
        unmarshaller = JAXBContext.newInstance(ListDataNode.class).createUnmarshaller();
    } catch (JAXBException e) {
        throw new RuntimeException("can't create unmarshaller", e);
    }
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    cm.setDefaultMaxPerRoute(10);
    httpClient = new DefaultHttpClient(cm);
}

From source file:de.digiway.rapidbreeze.server.model.storage.provider.ShareOnlineBiz.java

public ShareOnlineBiz() {
    ClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    this.httpClient = new DefaultHttpClient(connectionManager);
    this.currentAuthenticationStatus = AuthenticationStatus.NOT_AUTHENTICATED;
}

From source file:com.barchart.http.handlers.TestCancellableRequestHandler.java

@Before
public void setUp() throws Exception {

    server = new HttpServer();

    basic = new TestRequestHandler("basic", false, 0, 0, false);
    async = new TestRequestHandler("async", true, 0, 0, false);
    asyncDelayed = new TestRequestHandler("async-delayed", true, 50, 0, false);
    clientDisconnect = new TestRequestHandler("client-disconnect", true, 500, 500, false);
    error = new TestRequestHandler("error", false, 0, 0, true);

    final HttpServerConfig config = new HttpServerConfig().requestHandler("/basic", basic)
            .address(new InetSocketAddress("localhost", 8888)).parentGroup(new NioEventLoopGroup(1))
            .childGroup(new NioEventLoopGroup(1)).requestHandler("/async", async)
            .requestHandler("/async-delayed", asyncDelayed)
            .requestHandler("/client-disconnect", clientDisconnect).requestHandler("/error", error)
            .maxConnections(1);/*from  w ww. j  a va2  s .c o m*/

    server.configure(config).listen().sync();

    client = new DefaultHttpClient(new PoolingClientConnectionManager());

}

From source file:com.proofpoint.http.client.ApacheHttpClient.java

public ApacheHttpClient(HttpClientConfig config, Set<? extends HttpRequestFilter> requestFilters) {
    Preconditions.checkNotNull(config, "config is null");
    Preconditions.checkNotNull(requestFilters, "requestFilters is null");

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(config.getMaxConnections());
    connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionsPerServer());

    BasicHttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT,
            Ints.checkedCast(config.getReadTimeout().toMillis()));
    httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
            Ints.checkedCast(config.getConnectTimeout().toMillis()));
    httpParams.setParameter(CoreConnectionPNames.SO_LINGER, 0); // do we need this?

    DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, httpParams);
    defaultHttpClient.setKeepAliveStrategy(new FixedIntervalKeepAliveStrategy(config.getKeepAliveInterval()));
    defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    this.httpClient = defaultHttpClient;

    this.requestFilters = ImmutableList.copyOf(requestFilters);
}

From source file:org.jboss.as.test.integration.jaxrs.validator.BeanValidationIntegrationTestCase.java

@Test
public void testValidRequest() throws Exception {
    DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());

    HttpGet get = new HttpGet(url + "myjaxrs/validate/5");
    HttpResponse result = client.execute(get);

    Assert.assertEquals(200, result.getStatusLine().getStatusCode());
    Assert.assertEquals("ValidatorModel{id=5}", EntityUtils.toString(result.getEntity()));
}

From source file:dk.deck.resolver.ArtifactResolverRemote.java

public ArtifactResolverRemote(List<String> repositories, String username, String password) {
    this.repositories = Collections.unmodifiableList(repositories);
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(MAX_HTTP_THREADS);
    connectionManager.setDefaultMaxPerRoute(MAX_HTTP_THREADS);
    httpclient = new DefaultHttpClient(connectionManager);

    List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);// w w  w . j a v a 2s  . co m
    authpref.add(AuthPolicy.DIGEST);
    httpclient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
    httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);

}

From source file:com.opower.rest.client.generator.executors.ApacheHttpClient4Executor.java

/**
 * Create an instance using the DefaultHttpClient.
 *//*  w ww .  j a  va2s  . c  o  m*/
public ApacheHttpClient4Executor() {
    this(new DefaultHttpClient(new PoolingClientConnectionManager()), ImmutableList.<ClientRequestFilter>of());
}

From source file:org.nuxeo.ecm.automation.client.jaxrs.impl.HttpAutomationClient.java

private void init(int httpConnectionTimeout) {
    http = new DefaultHttpClient(new PoolingClientConnectionManager());
    this.httpConnectionTimeout = httpConnectionTimeout;
    // http.setCookieSpecs(null);
    // http.setCookieStore(null);
    registerAdapter(new DocumentServiceFactory());
    registerAdapter(new BusinessServiceFactory());
}