List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams setDefaultMaxConnectionsPerHost
public void setDefaultMaxConnectionsPerHost(int paramInt)
From source file:com.liferay.portal.util.HttpImpl.java
public HttpImpl() { // Mimic behavior found in // http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html if (Validator.isNotNull(_NON_PROXY_HOSTS)) { String nonProxyHostsRegEx = _NON_PROXY_HOSTS; nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\.", "\\\\."); nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\*", ".*?"); nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\|", ")|("); nonProxyHostsRegEx = "(" + nonProxyHostsRegEx + ")"; _nonProxyHostsPattern = Pattern.compile(nonProxyHostsRegEx); }//from w w w .j a va2s .c o m MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams httpConnectionManagerParams = httpConnectionManager.getParams(); httpConnectionManagerParams.setConnectionTimeout(_TIMEOUT); httpConnectionManagerParams.setDefaultMaxConnectionsPerHost(new Integer(_MAX_CONNECTIONS_PER_HOST)); httpConnectionManagerParams.setMaxTotalConnections(new Integer(_MAX_TOTAL_CONNECTIONS)); httpConnectionManagerParams.setSoTimeout(_TIMEOUT); _httpClient.setHttpConnectionManager(httpConnectionManager); _proxyHttpClient.setHttpConnectionManager(httpConnectionManager); if (hasProxyConfig() && Validator.isNotNull(_PROXY_USERNAME)) { List<String> authPrefs = new ArrayList<String>(); if (_PROXY_AUTH_TYPE.equals("username-password")) { _proxyCredentials = new UsernamePasswordCredentials(_PROXY_USERNAME, _PROXY_PASSWORD); authPrefs.add(AuthPolicy.BASIC); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.NTLM); } else if (_PROXY_AUTH_TYPE.equals("ntlm")) { _proxyCredentials = new NTCredentials(_PROXY_USERNAME, _PROXY_PASSWORD, _PROXY_NTLM_HOST, _PROXY_NTLM_DOMAIN); authPrefs.add(AuthPolicy.NTLM); authPrefs.add(AuthPolicy.BASIC); authPrefs.add(AuthPolicy.DIGEST); } HttpClientParams httpClientParams = _proxyHttpClient.getParams(); httpClientParams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); } }
From source file:com.twelve.capital.external.feed.util.HttpImpl.java
public HttpImpl() { // Override the default protocol socket factory because it uses // reflection for JDK 1.4 compatibility, which we do not need. It also // attemps to create a new socket in a different thread so that we // cannot track which class loader initiated the call. Protocol protocol = new Protocol("http", new FastProtocolSocketFactory(), 80); Protocol.registerProtocol("http", protocol); // Mimic behavior found in // http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html if (Validator.isNotNull(_NON_PROXY_HOSTS)) { String nonProxyHostsRegEx = _NON_PROXY_HOSTS; nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\.", "\\\\."); nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\*", ".*?"); nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\|", ")|("); nonProxyHostsRegEx = "(" + nonProxyHostsRegEx + ")"; _nonProxyHostsPattern = Pattern.compile(nonProxyHostsRegEx); }//www . ja v a 2s . c o m MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams httpConnectionManagerParams = httpConnectionManager.getParams(); httpConnectionManagerParams.setConnectionTimeout(_TIMEOUT); httpConnectionManagerParams.setDefaultMaxConnectionsPerHost(new Integer(_MAX_CONNECTIONS_PER_HOST)); httpConnectionManagerParams.setMaxTotalConnections(new Integer(_MAX_TOTAL_CONNECTIONS)); httpConnectionManagerParams.setSoTimeout(_TIMEOUT); _httpClient.setHttpConnectionManager(httpConnectionManager); _proxyHttpClient.setHttpConnectionManager(httpConnectionManager); if (!hasProxyConfig() || Validator.isNull(_PROXY_USERNAME)) { return; } List<String> authPrefs = new ArrayList<String>(); if (_PROXY_AUTH_TYPE.equals("username-password")) { _proxyCredentials = new UsernamePasswordCredentials(_PROXY_USERNAME, _PROXY_PASSWORD); authPrefs.add(AuthPolicy.BASIC); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.NTLM); } else if (_PROXY_AUTH_TYPE.equals("ntlm")) { _proxyCredentials = new NTCredentials(_PROXY_USERNAME, _PROXY_PASSWORD, _PROXY_NTLM_HOST, _PROXY_NTLM_DOMAIN); authPrefs.add(AuthPolicy.NTLM); authPrefs.add(AuthPolicy.BASIC); authPrefs.add(AuthPolicy.DIGEST); } HttpClientParams httpClientParams = _proxyHttpClient.getParams(); httpClientParams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); }
From source file:oauth.OAuthTokenValidaterStubFactory.java
/** * This created httpclient pool that can be used to connect to external entity. This connection can be configured * via broker.xml by setting up the required http connection parameters. * * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager */// ww w.j av a 2s . c o m private HttpClient createHttpClient() { HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(Integer .parseInt(tokenValidationProperties.getProperty(UIConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST))); params.setMaxTotalConnections( Integer.parseInt(tokenValidationProperties.getProperty(UIConstants.MAXIMUM_TOTAL_HTTP_CONNECTION))); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(params); return new HttpClient(connectionManager); }
From source file:open.hyperion.nimblestorage.connection.NimbleStorageAPIFactory.java
/** * Initialize HTTP client//from ww w.j a v a2s.c om */ public void init() { _log.info("NimbleStorageDriver:NimbleStorageAPIFactory init enter"); _clientMap = new ConcurrentHashMap<String, NimbleStorageAPI>(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(_maxConnPerHost); params.setMaxTotalConnections(_maxConn); params.setTcpNoDelay(true); params.setConnectionTimeout(_connTimeout); params.setSoTimeout(_socketConnTimeout); _connectionManager = new MultiThreadedHttpConnectionManager(); _connectionManager.setParams(params); _connectionManager.closeIdleConnections(0); // close idle connections immediately HttpClient client = new HttpClient(_connectionManager); client.getParams().setConnectionManagerTimeout(_connManagerTimeout); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() { @Override public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) { return false; } }); Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080)); }
From source file:open.hyperion.purestorage.connection.PureStorageAPIFactory.java
/** * Initialize HTTP client//from w w w. ja v a 2s. c o m */ public void init() { _log.info("PureStorageDriver:PureStorageAPIFactory init enter"); _clientMap = new ConcurrentHashMap<String, PureStorageAPI>(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(_maxConnPerHost); params.setMaxTotalConnections(_maxConn); params.setTcpNoDelay(true); params.setConnectionTimeout(_connTimeout); params.setSoTimeout(_socketConnTimeout); _connectionManager = new MultiThreadedHttpConnectionManager(); _connectionManager.setParams(params); _connectionManager.closeIdleConnections(0); // close idle connections immediately HttpClient client = new HttpClient(_connectionManager); client.getParams().setConnectionManagerTimeout(_connManagerTimeout); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() { @Override public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) { return false; } }); Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080)); }
From source file:org.ala.harvester.BiocacheHarvester.java
public BiocacheHarvester() { int timeout = 3000; //msec hashTable = new Hashtable<String, String>(); hashTable.put("accept", "application/json"); mapper = new ObjectMapper(); mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); HttpConnectionManagerParams params; MultiThreadedHttpConnectionManager m_connectionmgr = new MultiThreadedHttpConnectionManager(); params = new HttpConnectionManagerParams(); params.setConnectionTimeout(timeout); params.setSoTimeout(timeout);//from w w w . j a v a 2 s . c om params.setDefaultMaxConnectionsPerHost(100); params.setMaxTotalConnections(3000); m_connectionmgr.setParams(params); httpClient = new HttpClient(m_connectionmgr); // Default is to search all records. The query can be modified using the -query argument to the main method. biocacheSearchQuery = "*:*"; }
From source file:org.alfresco.httpclient.HttpClientFactory.java
protected HttpClient constructHttpClient() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient httpClient = new HttpClient(connectionManager); HttpClientParams params = httpClient.getParams(); params.setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true); params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true); if (socketTimeout != null) { params.setSoTimeout(socketTimeout); }/* w w w.ja va 2s . c o m*/ HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams(); connectionManagerParams.setMaxTotalConnections(maxTotalConnections); connectionManagerParams.setDefaultMaxConnectionsPerHost(maxHostConnections); connectionManagerParams.setConnectionTimeout(connectionTimeout); return httpClient; }
From source file:org.apache.hadoop.hbase.rest.client.Client.java
/** * Constructor//from ww w . j a v a 2 s. c o m * @param cluster the cluster definition */ public Client(Cluster cluster) { this.cluster = cluster; MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams managerParams = manager.getParams(); managerParams.setConnectionTimeout(2000); // 2 s managerParams.setDefaultMaxConnectionsPerHost(10); managerParams.setMaxTotalConnections(100); extraHeaders = new ConcurrentHashMap<String, String>(); this.httpClient = new HttpClient(manager); HttpClientParams clientParams = httpClient.getParams(); clientParams.setVersion(HttpVersion.HTTP_1_1); }
From source file:org.apache.hadoop.hbase.stargate.client.Client.java
/** * Constructor//from w ww . j a v a 2 s .c o m * @param cluster the cluster definition */ public Client(Cluster cluster) { this.cluster = cluster; MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams managerParams = manager.getParams(); managerParams.setConnectionTimeout(2000); // 2 s managerParams.setDefaultMaxConnectionsPerHost(10); managerParams.setMaxTotalConnections(100); this.httpClient = new HttpClient(manager); HttpClientParams clientParams = httpClient.getParams(); clientParams.setVersion(HttpVersion.HTTP_1_1); }
From source file:org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.java
/** * Creates a new instance of this repository service. * * @param uri The server uri.//w w w. j av a 2s. com * @param idFactory The id factory. * @param nameFactory The name factory. * @param pathFactory The path factory. * @param qValueFactory The value factory. * @param itemInfoCacheSize The size of the item info cache. * @param maximumHttpConnections A int >0 defining the maximum number of * connections per host to be configured on * {@link HttpConnectionManagerParams#setDefaultMaxConnectionsPerHost(int)}. * @throws RepositoryException If an error occurs. */ public RepositoryServiceImpl(String uri, IdFactory idFactory, NameFactory nameFactory, PathFactory pathFactory, QValueFactory qValueFactory, int itemInfoCacheSize, int maximumHttpConnections) throws RepositoryException { if (uri == null || "".equals(uri)) { throw new RepositoryException("Invalid repository uri '" + uri + "'."); } if (idFactory == null || qValueFactory == null) { throw new RepositoryException("IdFactory and QValueFactory may not be null."); } this.idFactory = idFactory; this.nameFactory = nameFactory; this.pathFactory = pathFactory; this.qValueFactory = qValueFactory; this.itemInfoCacheSize = itemInfoCacheSize; try { URI repositoryUri = computeRepositoryUri(uri); hostConfig = new HostConfiguration(); hostConfig.setHost(repositoryUri); nsCache = new NamespaceCache(); uriResolver = new URIResolverImpl(repositoryUri, this, DomUtil.createDocument()); NamePathResolver resolver = new NamePathResolverImpl(nsCache); valueFactory = new ValueFactoryQImpl(qValueFactory, resolver); } catch (URIException e) { throw new RepositoryException(e); } catch (ParserConfigurationException e) { throw new RepositoryException(e); } connectionManager = new MultiThreadedHttpConnectionManager(); if (maximumHttpConnections > 0) { HttpConnectionManagerParams connectionParams = connectionManager.getParams(); connectionParams.setDefaultMaxConnectionsPerHost(maximumHttpConnections); connectionParams.setMaxTotalConnections(maximumHttpConnections); } // This configuration of the clients cache assumes that the level of // concurrency on this map will be equal to the default number of maximum // connections allowed on the httpClient level. // TODO: review again int concurrencyLevel = MAX_CONNECTIONS_DEFAULT; int initialCapacity = MAX_CONNECTIONS_DEFAULT; if (maximumHttpConnections > 0) { concurrencyLevel = maximumHttpConnections; initialCapacity = maximumHttpConnections; } clients = new ConcurrentHashMap<Object, HttpClient>(concurrencyLevel, .75f, initialCapacity); }