List of usage examples for org.apache.http.impl.conn PoolingHttpClientConnectionManager setMaxTotal
public void setMaxTotal(final int max)
From source file:com.hybris.datahub.outbound.utils.RestTemplateUtil.java
private RestTemplate initializationTemplate() { final ConnectionConfig connConfig = ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build(); final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(100000).build(); final RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder .<ConnectionSocketFactory>create(); final ConnectionSocketFactory plainSF = new PlainConnectionSocketFactory(); registryBuilder.register("http", plainSF); registryBuilder.register("https", setUpSSL()); final Registry<ConnectionSocketFactory> registry = registryBuilder.build(); final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry); connManager.setDefaultConnectionConfig(connConfig); connManager.setDefaultSocketConfig(socketConfig); connManager.setMaxTotal(1000); connManager.setDefaultMaxPerRoute(1000); final HttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connManager).build(); final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( httpClient);/* w ww . ja v a 2 s. c o m*/ clientHttpRequestFactory.setConnectTimeout(50000); clientHttpRequestFactory.setReadTimeout(30000); // clientHttpRequestFactory.setConnectionRequestTimeout(200); restTemplate = new RestTemplate(); restTemplate.setRequestFactory(clientHttpRequestFactory); restTemplate.setErrorHandler(new DefaultResponseErrorHandler()); return restTemplate; }
From source file:com.arvato.thoroughly.util.RestTemplateUtil.java
@PostConstruct private RestTemplate initializationTemplate() { ConnectionConfig connConfig = ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build(); SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(100000).build(); RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder .<ConnectionSocketFactory>create(); ConnectionSocketFactory plainSF = new PlainConnectionSocketFactory(); registryBuilder.register("http", plainSF); registryBuilder.register("https", setUpSSL()); Registry<ConnectionSocketFactory> registry = registryBuilder.build(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry); connManager.setDefaultConnectionConfig(connConfig); connManager.setDefaultSocketConfig(socketConfig); connManager.setMaxTotal(1000); connManager.setDefaultMaxPerRoute(1000); HttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connManager).build(); HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( httpClient);/* w w w . j a v a 2 s . c o m*/ clientHttpRequestFactory.setConnectTimeout(30000); clientHttpRequestFactory.setReadTimeout(30000); clientHttpRequestFactory.setConnectionRequestTimeout(30000); restTemplate = new RestTemplate(); restTemplate.setRequestFactory(clientHttpRequestFactory); restTemplate.setErrorHandler(new DefaultResponseErrorHandler()); reInitMessageConverter(restTemplate); return restTemplate; }
From source file:de.hybris.platform.marketplaceintegrationbackoffice.utils.MarketplaceintegrationbackofficeRestTemplateUtil.java
private RestTemplate initializationTemplate() { final ConnectionConfig connConfig = ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build(); final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(100000).build(); final RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder .<ConnectionSocketFactory>create(); final ConnectionSocketFactory plainSF = new PlainConnectionSocketFactory(); registryBuilder.register("http", plainSF); registryBuilder.register("https", setUpSSL()); final Registry<ConnectionSocketFactory> registry = registryBuilder.build(); final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry); connManager.setDefaultConnectionConfig(connConfig); connManager.setDefaultSocketConfig(socketConfig); connManager.setMaxTotal(1000); connManager.setDefaultMaxPerRoute(1000); final HttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connManager).build(); final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( httpClient);/* w ww .j a va 2 s.c o m*/ clientHttpRequestFactory.setConnectTimeout(5000); clientHttpRequestFactory.setReadTimeout(5000); clientHttpRequestFactory.setConnectionRequestTimeout(200); restTemplate = new RestTemplate(); restTemplate.setRequestFactory(clientHttpRequestFactory); restTemplate.setErrorHandler(new DefaultResponseErrorHandler()); return restTemplate; }
From source file:org.apache.hadoop.gateway.shell.Hadoop.java
private CloseableHttpClient createClient(ClientContext clientContext) throws GeneralSecurityException { // SSL/* w ww . java 2 s . com*/ HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE; TrustStrategy trustStrategy = null; if (clientContext.connection().secure()) { hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier(); } else { trustStrategy = TrustSelfSignedStrategy.INSTANCE; System.out.println("**************** WARNING ******************\n" + "This is an insecure client instance and may\n" + "leave the interactions subject to a man in\n" + "the middle attack. Please use the login()\n" + "method instead of loginInsecure() for any\n" + "sensitive or production usecases.\n" + "*******************************************"); } KeyStore trustStore = getTrustStore(); SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, trustStrategy).build(); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", new SSLConnectionSocketFactory(sslContext, hostnameVerifier)).build(); // Pool PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry); connectionManager.setMaxTotal(clientContext.pool().maxTotal()); connectionManager.setDefaultMaxPerRoute(clientContext.pool().defaultMaxPerRoute()); ConnectionConfig connectionConfig = ConnectionConfig.custom() .setBufferSize(clientContext.connection().bufferSize()).build(); connectionManager.setDefaultConnectionConfig(connectionConfig); SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(clientContext.socket().keepalive()) .setSoLinger(clientContext.socket().linger()) .setSoReuseAddress(clientContext.socket().reuseAddress()) .setSoTimeout(clientContext.socket().timeout()).setTcpNoDelay(clientContext.socket().tcpNoDelay()) .build(); connectionManager.setDefaultSocketConfig(socketConfig); // Auth URI uri = URI.create(clientContext.url()); host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); CredentialsProvider credentialsProvider = null; if (clientContext.username() != null && clientContext.password() != null) { credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(host.getHostName(), host.getPort()), new UsernamePasswordCredentials(clientContext.username(), clientContext.password())); AuthCache authCache = new BasicAuthCache(); BasicScheme authScheme = new BasicScheme(); authCache.put(host, authScheme); context = new BasicHttpContext(); context.setAttribute(org.apache.http.client.protocol.HttpClientContext.AUTH_CACHE, authCache); } return HttpClients.custom().setConnectionManager(connectionManager) .setDefaultCredentialsProvider(credentialsProvider).build(); }
From source file:ee.ria.xroad.proxy.clientproxy.ClientProxy.java
private HttpClientConnectionManager getClientConnectionManager() throws Exception { RegistryBuilder<ConnectionSocketFactory> sfr = RegistryBuilder.create(); sfr.register("http", PlainConnectionSocketFactory.INSTANCE); if (SystemProperties.isSslEnabled()) { sfr.register("https", createSSLSocketFactory()); }/*from w w w . j a v a 2s .com*/ SocketConfig.Builder sockBuilder = SocketConfig.custom().setTcpNoDelay(true); sockBuilder.setSoLinger(SystemProperties.getClientProxyHttpClientSoLinger()); sockBuilder.setSoTimeout(SystemProperties.getClientProxyHttpClientTimeout()); SocketConfig socketConfig = sockBuilder.build(); PoolingHttpClientConnectionManager poolingManager = new PoolingHttpClientConnectionManager(sfr.build()); poolingManager.setMaxTotal(SystemProperties.getClientProxyPoolTotalMaxConnections()); poolingManager.setDefaultMaxPerRoute(SystemProperties.getClientProxyPoolDefaultMaxConnectionsPerRoute()); poolingManager.setDefaultSocketConfig(socketConfig); poolingManager.setValidateAfterInactivity( SystemProperties.getClientProxyValidatePoolConnectionsAfterInactivityMs()); return poolingManager; }
From source file:org.kaaproject.kaa.server.verifiers.facebook.verifier.FacebookUserVerifier.java
@Override public void start() { LOG.info("facebook user verifier started"); tokenVerifiersPool = new ThreadPoolExecutor(0, configuration.getMaxParallelConnections(), MAX_SEC_FACEBOOK_REQUEST_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); httpClient = HttpClients.custom().setConnectionManager(connectionManager).build(); // Increase max total connection connectionManager.setMaxTotal(configuration.getMaxParallelConnections()); }
From source file:com.redhat.red.offliner.ftest.SinglePlaintextDownloadOfTarballFTest.java
@Test public void testGenericTarballDownload() throws Exception { // Generate some test content String path = contentGenerator.newArtifactPath("tar.gz"); Map<String, byte[]> entries = new HashMap<>(); entries.put(contentGenerator.newArtifactPath("jar"), contentGenerator.newBinaryContent(2400)); entries.put(contentGenerator.newArtifactPath("jar"), contentGenerator.newBinaryContent(2400)); final File tgz = makeTarball(entries); System.out.println("tar content array has length: " + tgz.length()); // We only need one repo server. ExpectationServer server = new ExpectationServer(); server.start();/*from w ww .j a va 2 s . c om*/ String url = server.formatUrl(path); // Register the generated content by writing it to the path within the repo server's dir structure. // This way when the path is requested it can be downloaded instead of returning a 404. server.expect("GET", url, (req, resp) -> { // Content-Length: 47175 // Content-Type: application/x-gzip resp.setHeader("Content-Encoding", "x-gzip"); resp.setHeader("Content-Type", "application/x-gzip"); byte[] raw = FileUtils.readFileToByteArray(tgz); ByteArrayOutputStream baos = new ByteArrayOutputStream(); GzipCompressorOutputStream gzout = new GzipCompressorOutputStream(baos); gzout.write(raw); gzout.finish(); byte[] content = baos.toByteArray(); resp.setHeader("Content-Length", Long.toString(content.length)); OutputStream respStream = resp.getOutputStream(); respStream.write(content); respStream.flush(); System.out.println("Wrote content with length: " + content.length); }); final PoolingHttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(); ccm.setMaxTotal(1); final HttpClientBuilder builder = HttpClients.custom().setConnectionManager(ccm); CloseableHttpClient client = builder.build(); HttpGet get = new HttpGet(url); // get.setHeader( "Accept-Encoding", "gzip,deflate" ); Boolean result = client.execute(get, (response) -> { Arrays.stream(response.getAllHeaders()).forEach((h) -> System.out.println("Header:: " + h)); Header contentEncoding = response.getEntity().getContentEncoding(); if (contentEncoding == null) { contentEncoding = response.getFirstHeader("Content-Encoding"); } System.out.printf("Got content encoding: %s\n", contentEncoding == null ? "None" : contentEncoding.getValue()); byte[] content = IOUtils.toByteArray(response.getEntity().getContent()); try (TarArchiveInputStream tarIn = new TarArchiveInputStream( new GzipCompressorInputStream(new ByteArrayInputStream(content)))) { TarArchiveEntry entry = null; while ((entry = tarIn.getNextTarEntry()) != null) { System.out.printf("Got tar entry: %s\n", entry.getName()); byte[] entryData = new byte[(int) entry.getSize()]; int read = tarIn.read(entryData, 0, entryData.length); } } return false; }); }
From source file:org.thevortex.lighting.jinks.client.WinkClient.java
/** * Basic setup for a client builder, including the connection manager. * * @return the builder/*from w w w. j a v a 2 s . co m*/ */ public synchronized CloseableHttpClient getClient() { if (httpClient == null) { PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(1, TimeUnit.MINUTES); mgr.setDefaultMaxPerRoute(5); mgr.setMaxTotal(15); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setConnectionManager(mgr); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(connectionTimeout * 1000) .setSocketTimeout(socketTimeout * 1000).build(); httpClient = httpClientBuilder.setDefaultRequestConfig(requestConfig).build(); } return httpClient; }
From source file:org.hupo.psi.mi.psicquic.ws.SolrBasedPsicquicRestService.java
protected HttpClient createHttpClient() { PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(SolrBasedPsicquicService.maxTotalConnections); cm.setDefaultMaxPerRoute(SolrBasedPsicquicService.defaultMaxConnectionsPerHost); RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder = requestBuilder.setConnectTimeout(SolrBasedPsicquicService.connectionTimeOut); requestBuilder = requestBuilder.setSocketTimeout(SolrBasedPsicquicService.soTimeOut); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setDefaultRequestConfig(requestBuilder.build()); builder.setConnectionManager(cm);/* w w w.j ava2 s .c o m*/ return builder.build(); }