List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager
public PoolingClientConnectionManager()
From source file:org.fcrepo.indexer.IndexerGroup.java
@VisibleForTesting protected DefaultHttpClient httpClient(final String repositoryURL) { // try to find existing client if (clients.size() > 0) { for (final Iterator<String> it = clients.keySet().iterator(); it.hasNext();) { final String base = it.next(); if (repositoryURL.startsWith(base)) { return clients.get(base); }//www . j a v a 2s . co m } } if (defaultClient != null) { return defaultClient; } // if no existing client matched, create a new one final String baseURL; if (repositoryURL.indexOf(REST_PREFIX) > 0) { baseURL = repositoryURL.substring(0, repositoryURL.indexOf(REST_PREFIX) + REST_PREFIX.length()); } else if (repositoryURL.indexOf("/", FCREPO_PREFIX.length()) > 0) { baseURL = repositoryURL.substring(0, repositoryURL.indexOf("/", FCREPO_PREFIX.length()) + 1); } else { baseURL = repositoryURL; } final PoolingClientConnectionManager connMann = new PoolingClientConnectionManager(); connMann.setMaxTotal(MAX_VALUE); connMann.setDefaultMaxPerRoute(MAX_VALUE); final DefaultHttpClient httpClient = new DefaultHttpClient(connMann); httpClient.setRedirectStrategy(new DefaultRedirectStrategy()); httpClient.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler(0, false)); // If the Fedora instance requires authentication, set it up here if (!isBlank(fedoraUsername) && !isBlank(fedoraPassword)) { LOGGER.debug("Adding BASIC credentials to client for repo requests."); final URI fedoraUri = URI.create(baseURL); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(fedoraUri.getHost(), fedoraUri.getPort()), new UsernamePasswordCredentials(fedoraUsername, fedoraPassword)); httpClient.setCredentialsProvider(credsProvider); } clients.put(baseURL, httpClient); return httpClient; }