List of usage examples for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager()
From source file:org.openo.nfvo.monitor.umc.drill.wrapper.resources.config.ClientConfigFactory.java
/** * create the ClientConfig for JerseyClient * * @return//from w w w . j a v a2 s .c o m */ public static ClientConfig createClientConfig() { // create the apache PoolingHttpClient PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setDefaultMaxPerRoute(10); ClientConfig clientConfig = new ClientConfig().connectorProvider(new ApacheConnectorProvider()) // specify the PoolingHttpClientConnectionManager manager .property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager) .property(ClientProperties.CONNECT_TIMEOUT, "2000").property(ClientProperties.READ_TIMEOUT, "3000") // config the serialization / deserialization provider for json .register(JacksonJsonProvider.class); return clientConfig; }
From source file:org.dbrane.cloud.util.httpclient.HttpClientHelper.java
private static void init() { if (null == cm) { synchronized (lock) { if (cm == null) { cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(50);// cm.setDefaultMaxPerRoute(5);// ?2 }/*from w ww . j ava 2s . c o m*/ } } }
From source file:org.neo4j.ogm.drivers.http.driver.HttpDriverTest.java
@Test @Ignore/*from ww w . ja v a 2 s . c o m*/ public void shouldInitialiseWithCustomHttpClient() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(1); connectionManager.setDefaultMaxPerRoute(1); CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).build(); // TODO does this still have any value? // DriverManager.register(new HttpDriver(httpClient)); // assertThat(DriverManager.getDriver()).isNotNull(); }
From source file:org.neo4j.drivers.http.driver.HttpDriverTest.java
@Test public void shouldInitialiseWithCustomHttpClient() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(1);/*from w w w. j a v a2s . c om*/ connectionManager.setDefaultMaxPerRoute(1); CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).build(); Components.setDriver(new HttpDriver(httpClient)); assertNotNull(Components.driver()); }
From source file:tv.icntv.common.HttpClientHolder.java
private static void init() { // custom builder builder = HttpClients.custom();//w w w .j a va 2 s . c o m PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(); manager.setDefaultMaxPerRoute(DEFAULT_MAX_NUM_PER_ROUTE); manager.setMaxTotal(DEFAULT_MAX_TOTAL_NUM); builder.setConnectionManager(manager); builder.setMaxConnPerRoute(DEFAULT_MAX_NUM_PER_ROUTE); builder.setMaxConnTotal(DEFAULT_MAX_TOTAL_NUM); // headers List<Header> headers = new ArrayList<Header>(); headers.add(new BasicHeader("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg," + " application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint," + " application/msword, */*")); // headers.add(new BasicHeader("Content-Type","application/xml")); headers.add(new BasicHeader("Accept-Language", "zh-cn,en-us,zh-tw,en-gb,en;")); headers.add(new BasicHeader("Accept-Charset", "gbk,gb2312,utf-8,BIG5,ISO-8859-1;")); headers.add(new BasicHeader("Connection", "Close")); headers.add(new BasicHeader("Cache-Control", "no-cache")); headers.add(new BasicHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; CIBA)")); headers.add(new BasicHeader("Accept-Encoding", "gzip,deflate,sdch")); headers.add(new BasicHeader("Connection", "close")); builder.setDefaultHeaders(headers); // retry handler builder.setRetryHandler(new HttpRequestRetryHandler() { @Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { if (executionCount >= MAX_EXECUTION_NUM) { return false; } if (exception instanceof ConnectTimeoutException) { return false; } if (exception instanceof InterruptedIOException) { return false; } if (exception instanceof UnknownHostException) { return false; } if (exception instanceof NoHttpResponseException) { return false; } if (exception instanceof SSLException) { return false; } HttpClientContext clientContext = HttpClientContext.adapt(context); HttpRequest request = clientContext.getRequest(); if (!(request instanceof HttpEntityEnclosingRequest)) { return true; } return false; } }); // build client client = builder.build(); }
From source file:com.johnson.grab.browser.HttpClientHolder.java
private static void init() { // custom builder builder = HttpClients.custom();//from w w w.ja va 2 s. co m PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(); manager.setDefaultMaxPerRoute(DEFAULT_MAX_NUM_PER_ROUTE); manager.setMaxTotal(DEFAULT_MAX_TOTAL_NUM); builder.setConnectionManager(manager); builder.setMaxConnPerRoute(DEFAULT_MAX_NUM_PER_ROUTE); builder.setMaxConnTotal(DEFAULT_MAX_TOTAL_NUM); // headers List<Header> headers = new ArrayList<Header>(); headers.add(new BasicHeader("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg," + " application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint," + " application/msword, */*")); headers.add(new BasicHeader("Accept-Language", "zh-cn,en-us,zh-tw,en-gb,en;")); headers.add(new BasicHeader("Accept-Charset", "gbk,gb2312,utf-8,BIG5,ISO-8859-1;")); headers.add(new BasicHeader("Connection", "Close")); headers.add(new BasicHeader("Cache-Control", "no-cache")); headers.add(new BasicHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; CIBA)")); headers.add(new BasicHeader("Accept-Encoding", "gzip,deflate,sdch")); headers.add(new BasicHeader("Connection", "close")); builder.setDefaultHeaders(headers); // retry handler builder.setRetryHandler(new HttpRequestRetryHandler() { @Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { if (executionCount >= MAX_EXECUTION_NUM) { return false; } if (exception instanceof ConnectTimeoutException) { return false; } if (exception instanceof InterruptedIOException) { return false; } if (exception instanceof UnknownHostException) { return false; } if (exception instanceof NoHttpResponseException) { return false; } if (exception instanceof SSLException) { return false; } HttpClientContext clientContext = HttpClientContext.adapt(context); HttpRequest request = clientContext.getRequest(); if (!(request instanceof HttpEntityEnclosingRequest)) { return true; } return false; } }); // build client client = builder.build(); }
From source file:org.tinymediamanager.scraper.util.TmmHttpClient.java
/** * instantiates a new CloseableHttpClient * /*from w ww. jav a2s .c om*/ * @return CloseableHttpClient */ public static CloseableHttpClient createHttpClient() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); // Increase default max connection per route to 5 connectionManager.setMaxTotal(5); HttpClientBuilder httpClientBuilder = HttpClients.custom().useSystemProperties(); httpClientBuilder.setConnectionManager(connectionManager); // my own retry handler HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() { @Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { if (executionCount >= 5) { // Do not retry if over max retry count return false; } if (exception instanceof InterruptedIOException) { // Timeout return false; } if (exception instanceof UnknownHostException) { // Unknown host return false; } if (exception instanceof ConnectTimeoutException) { // Connection refused return false; } if (exception instanceof SSLException) { // SSL handshake exception return false; } HttpClientContext clientContext = HttpClientContext.adapt(context); HttpRequest request = clientContext.getRequest(); boolean idempotent = !(request instanceof HttpEntityEnclosingRequest); if (idempotent) { // Retry if the request is considered idempotent return true; } return false; } }; httpClientBuilder.setRetryHandler(myRetryHandler); // set proxy if needed if ((Globals.settings.useProxy())) { setProxy(httpClientBuilder); } return httpClientBuilder.build(); }
From source file:org.neo4j.ogm.service.ComponentsTest.java
@Test public void shouldCustomiseHttpDriverClient() { if (Components.driver() instanceof HttpDriver) { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(1); connectionManager.setDefaultMaxPerRoute(1); CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).build(); Driver driver = new HttpDriver(httpClient); Components.setDriver(driver);/*from w w w . j a v a 2 s. c o m*/ Assert.assertEquals(driver, Components.driver()); } }
From source file:lh.api.showcase.server.DefaultHttpClient.java
DefaultHttpClient() { logger.info("Create default http client"); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(maxTotalConnections); connectionManager.setDefaultMaxPerRoute(maxTotalPerRouteConnections); conf = DefaultConfiguration.INSTANCE.get(); httpClient = HttpClientUtils.createHttpClient(conf.getHttpProxySettings(), connectionManager); logger.info("Default http client has " + connectionManager.getMaxTotal() + " max total connections and " + connectionManager.getDefaultMaxPerRoute() + " max connections per route"); }
From source file:org.elasticlib.common.client.ClientBuilder.java
/** * Constructor/*from w ww .j a v a2 s. c o m*/ */ public ClientBuilder() { connectionManager = new PoolingHttpClientConnectionManager(); config = new ClientConfig().property(ClientProperties.CHUNKED_ENCODING_SIZE, 8192) .property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager) .connectorProvider(new ApacheConnectorProvider()).register(MultiPartFeature.class) .register(new HeaderRestoringWriterInterceptor()); }