List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams setMaxTotalConnections
public void setMaxTotalConnections(int paramInt)
From source file:org.exoplatform.services.common.HttpClientImpl.java
private void setHost(String protocol, String host, int port) throws Exception { MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams para = new HttpConnectionManagerParams(); para.setConnectionTimeout(HTTP_TIMEOUT); para.setDefaultMaxConnectionsPerHost(10); para.setMaxTotalConnections(20); para.setStaleCheckingEnabled(true);//ww w. jav a 2 s . c o m manager.setParams(para); http = new HttpClient(manager); http.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); http.getParams().setParameter("http.socket.timeout", new Integer(HTTP_TIMEOUT)); http.getParams().setParameter("http.protocol.content-charset", "UTF-8"); http.getParams().setCookiePolicy(CookiePolicy.RFC_2109); http.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); if (port < 0) port = 80; HostConfiguration hostConfig = http.getHostConfiguration(); hostConfig.setHost(host, port, protocol); String proxyHost = System.getProperty("httpclient.proxy.host"); if (proxyHost == null || proxyHost.trim().length() < 1) return; String proxyPort = System.getProperty("httpclient.proxy.port"); hostConfig.setProxy(proxyHost, Integer.parseInt(proxyPort)); String username = System.getProperty("httpclient.proxy.username"); String password = System.getProperty("httpclient.proxy.password"); String ntlmHost = System.getProperty("httpclient.proxy.ntlm.host"); String ntlmDomain = System.getProperty("httpclient.proxy.ntlm.domain"); Credentials ntCredentials; if (ntlmHost == null || ntlmDomain == null) { ntCredentials = new UsernamePasswordCredentials(username, password); } else { ntCredentials = new NTCredentials(username, password, ntlmHost, ntlmDomain); } http.getState().setProxyCredentials(AuthScope.ANY, ntCredentials); }
From source file:org.geosdi.geoplatform.services.httpclient.GeoSDIHttpClient.java
public GeoSDIHttpClient() { System.setProperty("jsse.enableSNIExtension", "false"); System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true"); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setSoTimeout(30000);// w w w . ja va2s . c o m params.setConnectionTimeout(30000); params.setMaxTotalConnections(6); params.setDefaultMaxConnectionsPerHost(6); this.connectionManager.setParams(params); this.client = this.createHttpClient(); //this.applySystemProxySettings(); }
From source file:org.geotools.data.ows.MultithreadedHttpClient.java
public MultithreadedHttpClient() { connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setSoTimeout(30000);// w w w .ja v a 2 s .c o m params.setConnectionTimeout(30000); params.setMaxTotalConnections(6); params.setDefaultMaxConnectionsPerHost(6); connectionManager.setParams(params); client = new HttpClient(connectionManager); applySystemProxySettings(); }
From source file:org.geowebcache.util.HttpClientBuilder.java
/** * uses the configuration of this builder to generate a HttpClient * //from w w w . j a v a 2s . c om * @return the generated HttpClient */ public HttpClient buildClient() { HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setSoTimeout(backendTimeoutMillis); params.setConnectionTimeout(backendTimeoutMillis); if (concurrency > 0) { params.setMaxTotalConnections(concurrency); params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, concurrency); } connectionManager.setParams(params); HttpClient httpClient = new HttpClient(connectionManager); if (authscope != null && httpcredentials != null) { httpClient.getState().setCredentials(authscope, httpcredentials); httpClient.getParams().setAuthenticationPreemptive(true); } if (proxyUrl != null) { httpClient.getHostConfiguration().setProxy(proxyUrl.getHost(), proxyUrl.getPort()); if (proxycredentials != null) { httpClient.getState().setProxyCredentials(new AuthScope(proxyUrl.getHost(), proxyUrl.getPort()), proxycredentials); } } return httpClient; }
From source file:org.hydracache.client.transport.HttpTransport.java
public HttpTransport() { // FIXME Make this more IoC and configurable. MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setDefaultMaxConnectionsPerHost(10); connectionManagerParams.setMaxTotalConnections(100); connectionManager.setParams(connectionManagerParams); this.httpClient = new HttpClient(connectionManager); }
From source file:org.j2free.http.QueuedHttpCallService.java
/** * Enables this service./*from www .j av a 2 s .c o m*/ * * @param corePoolSize * @param maxPoolSize The max number of threads * @param threadIdle How long a thread can be idle before terminating it * @param connectTimeout How long to wait for a connection * @param socketTimeout How long to wait for an operation * @throws IllegalStateException if called when the service is already running */ public QueuedHttpCallService(int corePoolSize, int maxPoolSize, long threadIdle, int connectTimeout, int socketTimeout) { if (maxPoolSize < 0) maxPoolSize = Integer.MAX_VALUE; executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, threadIdle, TimeUnit.SECONDS, new PriorityBlockingQueue<Runnable>(100)); executor.allowCoreThreadTimeOut(true); // allow the threads to timeout if unused executor.prestartCoreThread(); // start up just one thread connectionManager = new MultiThreadedHttpConnectionManager(); // Configure the ConnectionManager HttpConnectionManagerParams cmParams = connectionManager.getParams(); cmParams.setConnectionTimeout(connectTimeout * 1000); cmParams.setSoTimeout(socketTimeout * 1000); cmParams.setMaxTotalConnections(maxPoolSize); httpClient = new HttpClient(connectionManager); }
From source file:org.jasig.portal.security.provider.SamlAssertionFilter.java
@Override protected void initFilterBean() throws ServletException { this.connectionManager = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams params = this.connectionManager.getParams(); params.setMaxTotalConnections(this.maxTotalConnections); params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, this.maxTotalConnections); params.setConnectionTimeout(this.connectionTimeout); params.setSoTimeout(this.readTimeout); this.httpClient = new HttpClient(this.connectionManager); }
From source file:org.jasig.portal.services.MultiThreadedHttpConnectionManagerFactoryBean.java
@Override protected MultiThreadedHttpConnectionManager createInstance() throws Exception { final MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams pars = multiThreadedHttpConnectionManager.getParams(); pars.setConnectionTimeout(this.connectionTimeout); pars.setSoTimeout(this.soTimeout); pars.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); pars.setMaxTotalConnections(this.maxTotalConnections); pars.setDefaultMaxConnectionsPerHost(this.defaultMaxConnectionsPerHost); return multiThreadedHttpConnectionManager; }
From source file:org.jboss.test.cluster.defaultcfg.web.test.CleanShutdownTestCase.java
/** * @see org.jboss.test.JBossClusteredTestCase#setUp() *//*from w w w .jav a 2 s .c o m*/ @Override protected void setUp() throws Exception { super.setUp(); this.name = ObjectName.getInstance(SERVER_NAME); this.server = this.getAdaptors()[0]; this.baseURL = this.getHttpURLs()[0]; this.manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(MAX_THREADS); params.setMaxTotalConnections(MAX_THREADS); this.manager.setParams(params); this.client = new HttpClient(); }
From source file:org.jivesoftware.openfire.crowd.CrowdManager.java
private CrowdManager() { try {//from w w w .j a v a 2s. c o m // loading crowd.properties file CrowdProperties crowdProps = new CrowdProperties(); MultiThreadedHttpConnectionManager threadedConnectionManager = new MultiThreadedHttpConnectionManager(); HttpClient hc = new HttpClient(threadedConnectionManager); HttpClientParams hcParams = hc.getParams(); hcParams.setAuthenticationPreemptive(true); HttpConnectionManagerParams hcConnectionParams = hc.getHttpConnectionManager().getParams(); hcConnectionParams.setDefaultMaxConnectionsPerHost(crowdProps.getHttpMaxConnections()); hcConnectionParams.setMaxTotalConnections(crowdProps.getHttpMaxConnections()); hcConnectionParams.setConnectionTimeout(crowdProps.getHttpConnectionTimeout()); hcConnectionParams.setSoTimeout(crowdProps.getHttpSocketTimeout()); crowdServer = new URI(crowdProps.getCrowdServerUrl()).resolve("rest/usermanagement/latest/"); // setting BASIC authentication in place for connection with Crowd HttpState httpState = hc.getState(); Credentials crowdCreds = new UsernamePasswordCredentials(crowdProps.getApplicationName(), crowdProps.getApplicationPassword()); httpState.setCredentials(new AuthScope(crowdServer.getHost(), crowdServer.getPort()), crowdCreds); // setting Proxy config in place if needed if (StringUtils.isNotBlank(crowdProps.getHttpProxyHost()) && crowdProps.getHttpProxyPort() > 0) { hc.getHostConfiguration().setProxy(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort()); if (StringUtils.isNotBlank(crowdProps.getHttpProxyUsername()) || StringUtils.isNotBlank(crowdProps.getHttpProxyPassword())) { Credentials proxyCreds = new UsernamePasswordCredentials(crowdProps.getHttpProxyUsername(), crowdProps.getHttpProxyPassword()); httpState.setProxyCredentials( new AuthScope(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort()), proxyCreds); } } if (LOG.isDebugEnabled()) { LOG.debug("HTTP Client config"); LOG.debug(crowdServer.toString()); LOG.debug("Max connections:" + hcConnectionParams.getMaxTotalConnections()); LOG.debug("Socket timeout:" + hcConnectionParams.getSoTimeout()); LOG.debug("Connect timeout:" + hcConnectionParams.getConnectionTimeout()); LOG.debug("Proxy host:" + crowdProps.getHttpProxyHost() + ":" + crowdProps.getHttpProxyPort()); LOG.debug("Crowd application name:" + crowdProps.getApplicationName()); } client = hc; } catch (Exception e) { LOG.error("Failure to load the Crowd manager", e); } }