List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager setParams
public void setParams(HttpConnectionManagerParams paramHttpConnectionManagerParams)
From source file:ac.elements.io.Signature.java
/** * Configure HttpClient with set of defaults as well as configuration from * AmazonEC2Config instance.//from w w w . jav a 2s .co m * * @return the http client */ private static HttpClient configureHttpClient() { /* Set http client parameters */ HttpClientParams httpClientParams = new HttpClientParams(); httpClientParams.setParameter(HttpMethodParams.USER_AGENT, USER_AGENT); httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() { public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) { if (executionCount > MAX_RETRY_ERROR) { log.warn("Maximum Number of Retry attempts " + "reached, will not retry"); return false; } log.warn("Retrying request. Attempt " + executionCount); if (exception instanceof NoHttpResponseException) { log.warn("Retrying on NoHttpResponseException"); return true; } if (exception instanceof InterruptedIOException) { log.warn("Will not retry on InterruptedIOException", exception); return false; } if (exception instanceof UnknownHostException) { log.warn("Will not retry on UnknownHostException", exception); return false; } if (!method.isRequestSent()) { log.warn("Retrying on failed sent request"); return true; } return false; } }); /* Set host configuration */ HostConfiguration hostConfiguration = new HostConfiguration(); /* Set connection manager parameters */ HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setConnectionTimeout(50000); connectionManagerParams.setSoTimeout(50000); connectionManagerParams.setStaleCheckingEnabled(true); connectionManagerParams.setTcpNoDelay(true); connectionManagerParams.setMaxTotalConnections(MAX_CONNECTIONS); connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, MAX_CONNECTIONS); /* Set connection manager */ MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(connectionManagerParams); /* Set http client */ httpClient = new HttpClient(httpClientParams, connectionManager); /* Set proxy if configured */ // if (config.isSetProxyHost() && config.isSetProxyPort()) { // log.info("Configuring Proxy. Proxy Host: " + config.getProxyHost() + // "Proxy Port: " + config.getProxyPort() ); // hostConfiguration.setProxy(config.getProxyHost(), // config.getProxyPort()); // if (config.isSetProxyUsername() && config.isSetProxyPassword()) { // httpClient.getState().setProxyCredentials (new AuthScope( // config.getProxyHost(), // config.getProxyPort()), // new UsernamePasswordCredentials( // config.getProxyUsername(), // config.getProxyPassword())); // // } // } httpClient.setHostConfiguration(hostConfiguration); return httpClient; }
From source file:edu.harvard.med.iccbl.screensaver.soaputils.PugSoapUtil.java
private static void updateStub(org.apache.axis2.client.Stub stub, int maxTotal, int maxPerHost) { MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = httpConnectionManager.getParams(); if (params == null) { params = new HttpConnectionManagerParams(); }/*from w ww. j av a 2 s .c o m*/ params.setMaxTotalConnections(maxTotal); params.setDefaultMaxConnectionsPerHost(maxPerHost); // extra, not prescribed -sde4 params.setConnectionTimeout(600000); params.setSoTimeout(600000); httpConnectionManager.setParams(params); HttpClient httpClient = new HttpClient(httpConnectionManager); ServiceClient serviceClient = stub._getServiceClient(); ConfigurationContext context = serviceClient.getServiceContext().getConfigurationContext(); context.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); }
From source file:fr.dutra.confluence2wordpress.xmlrpc.CommonsXmlRpcTransportFactory.java
public CommonsXmlRpcTransportFactory(URL url, String proxyHost, int proxyPort, int maxConnections) { this.url = url; HostConfiguration hostConf = new HostConfiguration(); hostConf.setHost(url.getHost(), url.getPort()); if (proxyHost != null && proxyPort != -1) { hostConf.setProxy(proxyHost, proxyPort); }//w ww. j a v a 2s . com HttpConnectionManagerParams connParam = new HttpConnectionManagerParams(); connParam.setMaxConnectionsPerHost(hostConf, maxConnections); connParam.setMaxTotalConnections(maxConnections); MultiThreadedHttpConnectionManager conMgr = new MultiThreadedHttpConnectionManager(); conMgr.setParams(connParam); client = new HttpClient(conMgr); client.setHostConfiguration(hostConf); }
From source file:de.fuberlin.wiwiss.marbles.loading.SemanticWebClient.java
/** * Constructs a new <code>SemanticWebClient</code> * // www . j ava2s . co m * @param cacheController * @param spongerProvider * @param dataProviders */ public SemanticWebClient(CacheController cacheController, SpongerProvider spongerProvider, Collection<DataProvider> dataProviders) { this.cacheController = cacheController; this.dataProviders = dataProviders; /* Set connection parameters */ HttpConnectionManagerParams httpManagerParams = new HttpConnectionManagerParams(); httpManagerParams.setConnectionTimeout(CONNECTION_TIMEOUT * 1000); httpManagerParams.setTcpNoDelay(true); httpManagerParams.setStaleCheckingEnabled(true); MultiThreadedHttpConnectionManager httpManager = new MultiThreadedHttpConnectionManager(); httpManager.setParams(httpManagerParams); httpClient = new HttpClient(httpManager); uriQueue = new DereferencingTaskQueue(httpClient, spongerProvider, 10 /* maxThreads */, 500 * 1024 /* maxFileSize */); }
From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java
/** * Create the {@link HttpClient} object// w w w. jav a 2 s . c om */ private void createClient() { HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setConnectionTimeout(TIMEOUT_MS); params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS); params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); configureCredentials(); if (StringUtils.isNotBlank(System.getProperty("http.proxyHost"))) { log.debug("A HTTP Proxy is configured"); System.setProperty("java.net.useSystemProxies", "true"); Proxy proxy = chooseProxy(); if (proxy.type() == Type.HTTP && proxy.address() instanceof InetSocketAddress) { // convert the socket address to an ProxyHost final InetSocketAddress isa = (InetSocketAddress) proxy.address(); // assume default scheme (http) ProxyHost proxyHost = new ProxyHost(getHost(isa), isa.getPort()); httpClient.getHostConfiguration().setProxyHost(proxyHost); if (StringUtils.isNotBlank(System.getProperty("http.proxyUser"))) { String user = System.getProperty("http.proxyUser"); String password = System.getProperty("http.proxyPassword"); httpClient.getState().setProxyCredentials(new AuthScope(getHost(isa), isa.getPort()), new UsernamePasswordCredentials(user, password)); } } } }
From source file:com.duowan.common.rpc.client.CommonsHttpInvokerRequestExecutor.java
/** * Create a new CommonsHttpInvokerRequestExecutor with a default * HttpClient that uses a default MultiThreadedHttpConnectionManager. * Sets the socket read timeout to {@link #DEFAULT_READ_TIMEOUT_MILLISECONDS}. * @see org.apache.commons.httpclient.HttpClient * @see org.apache.commons.httpclient.MultiThreadedHttpConnectionManager *//*from w ww .j a v a 2 s . c o m*/ public CommonsHttpInvokerRequestExecutor() { MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(300); params.setMaxTotalConnections(500); httpConnectionManager.setParams(params); this.httpClient = new HttpClient(httpConnectionManager); this.setReadTimeout(getReadTimeout()); this.setConnectionTimeout(getConnectionTimeout()); }
From source file:com.twinsoft.convertigo.engine.util.HttpUtils.java
public static HttpClient makeHttpClient3(boolean usePool) { HttpClient httpClient;/*from w w w. ja v a 2 s .c o m*/ if (usePool) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); int maxTotalConnections = 100; try { maxTotalConnections = new Integer( EnginePropertiesManager.getProperty(PropertyName.HTTP_CLIENT_MAX_TOTAL_CONNECTIONS)) .intValue(); } catch (NumberFormatException e) { Engine.logEngine.warn("Unable to retrieve the max number of connections; defaults to 100."); } int maxConnectionsPerHost = 50; try { maxConnectionsPerHost = new Integer( EnginePropertiesManager.getProperty(PropertyName.HTTP_CLIENT_MAX_CONNECTIONS_PER_HOST)) .intValue(); } catch (NumberFormatException e) { Engine.logEngine .warn("Unable to retrieve the max number of connections per host; defaults to 100."); } HttpConnectionManagerParams httpConnectionManagerParams = new HttpConnectionManagerParams(); httpConnectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost); httpConnectionManagerParams.setMaxTotalConnections(maxTotalConnections); connectionManager.setParams(httpConnectionManagerParams); httpClient = new HttpClient(connectionManager); } else { httpClient = new HttpClient(); } HttpClientParams httpClientParams = (HttpClientParams) HttpClientParams.getDefaultParams(); httpClientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); /** #741 : belambra wants only one Set-Cookie header */ httpClientParams.setParameter("http.protocol.single-cookie-header", Boolean.TRUE); /** #5066 : httpClient auto retries failed request up to 3 times by default */ httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); httpClient.setParams(httpClientParams); return httpClient; }
From source file:com.gisgraphy.fulltext.FullTextSearchEngine.java
/** * @param multiThreadedHttpConnectionManager * The// ww w . j av a 2 s.com * @link {@link MultiThreadedHttpConnectionManager} that the fulltext search * engine will use * @throws FullTextSearchException * If an error occured */ @Autowired public FullTextSearchEngine( @Qualifier("multiThreadedHttpConnectionManager") MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager) throws FullTextSearchException { Assert.notNull(multiThreadedHttpConnectionManager, "multiThreadedHttpConnectionManager can not be null"); HttpConnectionManagerParams p = new HttpConnectionManagerParams(); p.setSoTimeout(0); p.setConnectionTimeout(0); multiThreadedHttpConnectionManager.setParams(p); this.httpClient = new HttpClient(multiThreadedHttpConnectionManager); if (this.httpClient == null) { throw new FullTextSearchException( "Can not instanciate http client with multiThreadedHttpConnectionManager : " + multiThreadedHttpConnectionManager); } }
From source file:com.xerox.amazonws.common.AWSQueryConnection.java
private void configureHttpClient() { MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connParams = connMgr.getParams(); connParams.setMaxTotalConnections(maxConnections); connParams.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxConnections); connMgr.setParams(connParams); hc = new HttpClient(connMgr); // NOTE: These didn't seem to help in my initial testing // hc.getParams().setParameter("http.tcp.nodelay", true); // hc.getParams().setParameter("http.connection.stalecheck", false); if (proxyHost != null) { HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setProxy(proxyHost, proxyPort); hc.setHostConfiguration(hostConfig); log.info("Proxy Host set to " + proxyHost + ":" + proxyPort); if (proxyUser != null && !proxyUser.trim().equals("")) { if (proxyDomain != null) { hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUser, proxyPassword, proxyHost, proxyDomain)); } else { hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword)); }// w ww. ja v a 2s . c o m } } }
From source file:com.amazonaws.elasticmapreduce.AmazonElasticMapReduceClient.java
/** * Configure HttpClient with set of defaults as well as configuration * from AmazonElasticMapReduceConfig instance * *//* w ww.j a v a 2s . c om*/ private HttpClient configureHttpClient() { /* Set http client parameters */ HttpClientParams httpClientParams = new HttpClientParams(); httpClientParams.setParameter(HttpMethodParams.USER_AGENT, config.getUserAgent()); httpClientParams.setParameter(HttpClientParams.RETRY_HANDLER, new HttpMethodRetryHandler() { public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) { if (executionCount > 3) { log.debug("Maximum Number of Retry attempts reached, will not retry"); return false; } log.debug("Retrying request. Attempt " + executionCount); if (exception instanceof NoHttpResponseException) { log.debug("Retrying on NoHttpResponseException"); return true; } if (exception instanceof InterruptedIOException) { log.debug("Will not retry on InterruptedIOException", exception); return false; } if (exception instanceof UnknownHostException) { log.debug("Will not retry on UnknownHostException", exception); return false; } if (!method.isRequestSent()) { log.debug("Retrying on failed sent request"); return true; } return false; } }); /* Set host configuration */ HostConfiguration hostConfiguration = new HostConfiguration(); /* Set connection manager parameters */ HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setConnectionTimeout(50000); connectionManagerParams.setSoTimeout(50000); connectionManagerParams.setStaleCheckingEnabled(true); connectionManagerParams.setTcpNoDelay(true); connectionManagerParams.setMaxTotalConnections(config.getMaxConnections()); connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, config.getMaxConnections()); /* Set connection manager */ MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(connectionManagerParams); /* Set http client */ httpClient = new HttpClient(httpClientParams, connectionManager); /* Set proxy if configured */ if (config.isSetProxyHost() && config.isSetProxyPort()) { log.info("Configuring Proxy. Proxy Host: " + config.getProxyHost() + "Proxy Port: " + config.getProxyPort()); hostConfiguration.setProxy(config.getProxyHost(), config.getProxyPort()); if (config.isSetProxyUsername() && config.isSetProxyPassword()) { httpClient.getState().setProxyCredentials( new AuthScope(config.getProxyHost(), config.getProxyPort()), new UsernamePasswordCredentials(config.getProxyUsername(), config.getProxyPassword())); } } httpClient.setHostConfiguration(hostConfiguration); return httpClient; }