List of usage examples for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager()
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.HopsworksRMAppSecurityActions.java
protected PoolingHttpClientConnectionManager createConnectionManager() throws GeneralSecurityException { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE); return connectionManager; }
From source file:org.apache.http.examples.me.ClientMultiThreadedExecution.java
public static void main(String[] args) throws Exception { // Create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(10);/*from w w w . j av a2 s . c o m*/ CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build(); try { // create an array of URIs to perform GETs on /* String[] urisToGet = { "http://hc.apache.org/", "http://hc.apache.org/httpcomponents-core-ga/", "http://hc.apache.org/httpcomponents-client-ga/", };*/ int times = 100; String[] urisToGet = new String[times]; long ss = System.currentTimeMillis(); for (int i = 0; i < times; i++) { ss++; urisToGet[i] = URL + "&_=" + ss + System.currentTimeMillis(); } // create a thread for each URI GetThread[] threads = new GetThread[urisToGet.length]; for (int i = 0; i < threads.length; i++) { HttpGet httpget = new HttpGet(urisToGet[i]); httpget.setHeader("cookie", cookie); //httpget.setHeader("User-Agent","Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"); threads[i] = new GetThread(httpclient, httpget, i + 1); } // start the threads for (int j = 0; j < threads.length; j++) { threads[j].start(); } // join the threads for (int j = 0; j < threads.length; j++) { threads[j].join(); } } finally { httpclient.close(); } }
From source file:org.apache.ignite.console.agent.handlers.RestListener.java
/** * @param cfg Config./*from w w w. j a va 2 s . co m*/ */ public RestListener(AgentConfiguration cfg) { super(); this.cfg = cfg; // Create a connection manager with custom configuration. PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(); connMgr.setDefaultMaxPerRoute(Integer.MAX_VALUE); connMgr.setMaxTotal(Integer.MAX_VALUE); httpClient = HttpClientBuilder.create().setConnectionManager(connMgr).build(); }
From source file:org.apache.manifoldcf.agents.output.elasticsearch.ElasticSearchConnector.java
protected HttpClient getSession() throws ManifoldCFException { if (client == null) { connectionManager = new PoolingHttpClientConnectionManager(); int socketTimeout = 900000; int connectionTimeout = 60000; // Set up connection manager connectionManager = new PoolingHttpClientConnectionManager(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true) .setSocketTimeout(socketTimeout).setStaleConnectionCheckEnabled(true) .setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout) .setConnectionRequestTimeout(socketTimeout); client = HttpClients.custom().setConnectionManager(connectionManager).setMaxConnTotal(1) .disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build()) .setDefaultSocketConfig(SocketConfig.custom() //.setTcpNoDelay(true) .setSoTimeout(socketTimeout).build()) .setDefaultCredentialsProvider(credentialsProvider) .setRequestExecutor(new HttpRequestExecutor(socketTimeout)).build(); }// w ww . j av a 2 s . c o m expirationTime = System.currentTimeMillis() + EXPIRATION_INTERVAL; return client; }
From source file:org.apache.nifi.processors.standard.PostHTTP.java
private Config getConfig(final String url, final ProcessContext context) { final String baseUrl = getBaseUrl(url); Config config = configMap.get(baseUrl); if (config != null) { return config; }/*from w w w . ja va 2 s . c o m*/ final PoolingHttpClientConnectionManager conMan; final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE) .asControllerService(SSLContextService.class); if (sslContextService == null) { conMan = new PoolingHttpClientConnectionManager(); } else { final SSLContext sslContext; try { sslContext = createSSLContext(sslContextService); getLogger().info("PostHTTP supports protocol: " + sslContext.getProtocol()); } catch (final Exception e) { throw new ProcessException(e); } final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext); // Also use a plain socket factory for regular http connections (especially proxies) final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create().register("https", sslsf) .register("http", PlainConnectionSocketFactory.getSocketFactory()).build(); conMan = new PoolingHttpClientConnectionManager(socketFactoryRegistry); } conMan.setDefaultMaxPerRoute(context.getMaxConcurrentTasks()); conMan.setMaxTotal(context.getMaxConcurrentTasks()); config = new Config(conMan); final Config existingConfig = configMap.putIfAbsent(baseUrl, config); return existingConfig == null ? config : existingConfig; }
From source file:org.datacleaner.cluster.http.HttpClusterManager.java
/** * Creates a new HTTP cluster manager// www.ja v a 2 s . c om * * @param slaveEndpoints * the endpoint URLs of the slaves */ public HttpClusterManager(List<String> slaveEndpoints) { this(HttpClients.custom().useSystemProperties() .setConnectionManager(new PoolingHttpClientConnectionManager()).build(), HttpClientContext.create(), slaveEndpoints); }
From source file:org.datacleaner.user.UserPreferencesImpl.java
@Override public CloseableHttpClient createHttpClient() { final HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); if (isProxyEnabled()) { // set up HTTP proxy final String proxyHostname = getProxyHostname(); final int proxyPort = getProxyPort(); try {/*from ww w . j av a 2 s . com*/ final HttpHost proxy = new HttpHost(proxyHostname, proxyPort); requestConfigBuilder.setProxy(proxy); if (isProxyAuthenticationEnabled()) { final AuthScope authScope = new AuthScope(proxyHostname, proxyPort); final String proxyUsername = getProxyUsername(); final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(proxyUsername, getProxyPassword()); credentialsProvider.setCredentials(authScope, credentials); final int backslashIndex = proxyUsername.lastIndexOf('\\'); final String ntUsername; final String ntDomain; if (backslashIndex != -1) { ntUsername = proxyUsername.substring(backslashIndex + 1); ntDomain = proxyUsername.substring(0, backslashIndex); } else { ntUsername = proxyUsername; ntDomain = System.getProperty("datacleaner.proxy.domain"); } String workstation = System.getProperty("datacleaner.proxy.workstation"); if (Strings.isNullOrEmpty(workstation)) { String computername = InetAddress.getLocalHost().getHostName(); workstation = computername; } NTCredentials ntCredentials = new NTCredentials(ntUsername, getProxyPassword(), workstation, ntDomain); AuthScope ntAuthScope = new AuthScope(proxyHostname, proxyPort, AuthScope.ANY_REALM, "ntlm"); credentialsProvider.setCredentials(ntAuthScope, ntCredentials); } } catch (Exception e) { // ignore proxy creation and return http client without it logger.error("Unexpected error occurred while initializing HTTP proxy", e); } } final RequestConfig requestConfig = requestConfigBuilder.build(); final CloseableHttpClient httpClient = HttpClients.custom().useSystemProperties() .setConnectionManager(connectionManager).setDefaultCredentialsProvider(credentialsProvider) .setDefaultRequestConfig(requestConfig).build(); return httpClient; }
From source file:org.fcrepo.importexport.integration.AbstractResourceIT.java
AbstractResourceIT() { clientBuilder = FcrepoClient.client().credentials(USERNAME, PASSWORD).authScope("localhost"); setDefaultHttpClient(new FcrepoHttpClientBuilder(USERNAME, PASSWORD, "localhost").build()); final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(Integer.MAX_VALUE); connectionManager.setDefaultMaxPerRoute(20); connectionManager.closeIdleConnections(3, TimeUnit.SECONDS); }
From source file:org.openecomp.sdc.be.dao.rest.HttpRestClient.java
private void createHttpClient(RestConfigurationInfo restConfigurationInfo) { // throws KeyManagementException, NoSuchAlgorithmException { PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); int connPoolSize = getConnectionPoolSize(restConfigurationInfo); connManager.setMaxTotal(connPoolSize); connManager.setDefaultMaxPerRoute(10); connManager.setValidateAfterInactivity(15000); // Create common default configuration int socketTimeout = getTimeout(restConfigurationInfo.getSocketTimeoutInSec(), DEFAULT_SOCKET_TIMEOUT); int connectTimeoutInSec = getTimeout(restConfigurationInfo.getConnectTimeoutInSec(), DEFAULT_CONNECT_TIMEOUT); int readTimeOut = getTimeout(restConfigurationInfo.getReadTimeoutInSec(), DEFAULT_READ_TIMEOUT_IN_SEC); RequestConfig clientConfig = RequestConfig.custom().setConnectTimeout(connectTimeoutInSec) .setSocketTimeout(socketTimeout).setConnectionRequestTimeout(readTimeOut).build(); this.cm = connManager; this.httpClient = HttpClients.custom().setDefaultRequestConfig(clientConfig) .setConnectionManager(connManager).build(); }
From source file:org.tanaguru.util.http.HttpRequestHandler.java
private CloseableHttpClient getHttpClient(String url) { RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout) .setConnectTimeout(connectionTimeout).build(); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); httpClientBuilder.setDefaultRequestConfig(requestConfig); httpClientBuilder.setConnectionManager(new PoolingHttpClientConnectionManager()); httpClientBuilder.setUserAgent(TANAGURU_USER_AGENT); if (isProxySet(url)) { LOGGER.debug(("Set proxy with " + proxyHost + " and " + proxyPort)); httpClientBuilder.setProxy(new HttpHost(proxyHost, Integer.valueOf(proxyPort))); if (isProxyCredentialSet()) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyHost, Integer.valueOf(proxyPort)), new UsernamePasswordCredentials(proxyUser, proxyPassword)); httpClientBuilder.setDefaultCredentialsProvider(credsProvider); LOGGER.debug(("Set proxy credentials " + proxyHost + " and " + proxyPort + " and " + proxyUser + " and " + proxyPassword)); }//from ww w . ja va2 s .co m } return httpClientBuilder.build(); }