List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams HttpConnectionManagerParams
HttpConnectionManagerParams
From source file:cn.leancloud.diamond.client.impl.DefaultDiamondSubscriber.java
protected void initHttpClient() { if (MockServer.isTestMode()) { return;//from w ww .j a v a2 s . com } HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()), diamondConfigure.getPort()); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.closeIdleConnections(diamondConfigure.getPollingIntervalTime() * 4000); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled()); params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections()); params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections()); params.setConnectionTimeout(diamondConfigure.getConnectionTimeout()); // 1, // boyan@taobao.com params.setSoTimeout(60 * 1000); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); httpClient.setHostConfiguration(hostConfiguration); }
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 w w.j a v a 2s. co 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:ac.elements.io.Signature.java
/** * Configure HttpClient with set of defaults as well as configuration from * AmazonEC2Config instance./*ww w . j a v a2 s . c o 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:com.trendmicro.hdfs.webdav.test.MiniClusterTestUtil.java
public HttpClient getClient() { HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost("localhost"); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setMaxConnectionsPerHost(hostConfig, 100); connectionManager.setParams(params); HttpClient client = new HttpClient(connectionManager); client.setHostConfiguration(hostConfig); return client; }
From source file:com.amazonaws.elasticmapreduce.AmazonElasticMapReduceClient.java
/** * Configure HttpClient with set of defaults as well as configuration * from AmazonElasticMapReduceConfig instance * *//*from ww w . jav a 2 s . c o m*/ 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; }
From source file:com.zimbra.common.util.ZimbraHttpConnectionManager.java
public static void main(String[] args) { // dump httpclient package defaults System.out.println(dumpParams("httpclient package defaults", new HttpConnectionManagerParams(), new HttpClientParams())); System.out.println(dumpParams("Internal ZimbraHttpConnectionManager", ZimbraHttpConnectionManager.getInternalHttpConnMgr().getParams().getConnMgrParams(), ZimbraHttpConnectionManager.getInternalHttpConnMgr().getDefaultHttpClient().getParams())); System.out.println(dumpParams("External ZimbraHttpConnectionManager", ZimbraHttpConnectionManager.getExternalHttpConnMgr().getParams().getConnMgrParams(), ZimbraHttpConnectionManager.getExternalHttpConnMgr().getDefaultHttpClient().getParams())); HttpClient httpClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().getDefaultHttpClient(); String connMgrName = httpClient.getHttpConnectionManager().getClass().getSimpleName(); long connMgrTimeout = httpClient.getParams().getConnectionManagerTimeout(); System.out.println("HttpConnectionManager for the HttpClient instance is: " + connMgrName); System.out.println("connection manager timeout for the HttpClient instance is: " + connMgrTimeout); }
From source file:eionet.cr.harvest.PullHarvest.java
/** * * @return/*from w w w . ja v a 2s . com*/ */ private EndpointHttpClient prepareEndpointHttpClient() { HttpConnectionManagerParams managerParams = new HttpConnectionManagerParams(); managerParams.setDefaultMaxConnectionsPerHost(20); managerParams.setStaleCheckingEnabled(false); int httpTimeout = GeneralConfig.getIntProperty(GeneralConfig.HARVESTER_HTTP_TIMEOUT, getTimeout()); managerParams.setConnectionTimeout(httpTimeout); managerParams.setSoTimeout(httpTimeout); HttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); manager.setParams(managerParams); HttpClientParams clientParams = new HttpClientParams(); clientParams.setParameter("http.useragent", URLUtil.userAgentHeader()); clientParams.setParameter("http.protocol.max-redirects", MAX_REDIRECTIONS); HashMap<String, String> headers = new HashMap<String, String>(); headers.put("Connection", "close"); clientParams.setParameter("additionalHTTPHeaders", headers); return new EndpointHttpClient(clientParams, manager); }
From source file:com.taobao.diamond.client.impl.DefaultDiamondPublisher.java
private void initHttpClient() { if (MockServer.isTestMode()) { return;//from ww w . j av a 2s .c o m } HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(domainNamePos.get()), diamondConfigure.getPort()); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.closeIdleConnections(60 * 1000); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled()); params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections()); params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections()); params.setConnectionTimeout(diamondConfigure.getConnectionTimeout()); params.setSoTimeout(requestTimeout); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); httpClient.setHostConfiguration(hostConfiguration); }
From source file:com.zimbra.common.util.ZimbraHttpConnectionManager.java
private static String dumpParams(String notes, HttpConnectionManagerParams connMgrParams, HttpClientParams clientParams) { // dump httpclient package defaults if params is null if (connMgrParams == null) connMgrParams = new HttpConnectionManagerParams(); if (clientParams == null) clientParams = new HttpClientParams(); StringBuilder sb = new StringBuilder(); sb.append("======== " + notes + "========\n"); sb.append("HttpConnectionManagerParams DefaultMaxConnectionsPerHost : " + connMgrParams.getDefaultMaxConnectionsPerHost() + "\n"); sb.append("HttpConnectionManagerParams MaxTotalConnections : " + connMgrParams.getMaxTotalConnections() + "\n"); sb.append("HttpConnectionParams ConnectionTimeout : " + connMgrParams.getConnectionTimeout() + "\n"); sb.append(/*from w ww .j ava 2s.c o m*/ "HttpConnectionParams Linger : " + connMgrParams.getLinger() + "\n"); sb.append("HttpConnectionParams ReceiveBufferSize : " + connMgrParams.getReceiveBufferSize() + "\n"); sb.append("HttpConnectionParams SendBufferSize : " + connMgrParams.getSendBufferSize() + "\n"); sb.append("HttpConnectionParams SoTimeout : " + connMgrParams.getSoTimeout() + "\n"); sb.append("HttpConnectionParams TcpNoDelay : " + connMgrParams.getTcpNoDelay() + "\n"); sb.append("HttpConnectionParams isStaleCheckingEnabled : " + connMgrParams.isStaleCheckingEnabled() + "\n"); // sb.append("HttpClientParams ALLOW_CIRCULAR_REDIRECTS (no corresponding method?) sb.append("HttpClientParams ConnectionManagerClass : " + clientParams.getConnectionManagerClass().getName() + "\n"); sb.append("HttpClientParams ConnectionManagerTimeout : " + clientParams.getConnectionManagerTimeout() + "\n"); // sb.append("HttpClientParams MAX_REDIRECTS (no corresponding method?) sb.append("HttpClientParams isAuthenticationPreemptive() : " + clientParams.isAuthenticationPreemptive() + "\n"); // sb.append("HttpClientParams REJECT_RELATIVE_REDIRECT (no corresponding method?) return sb.toString(); }
From source file:flex.messaging.services.http.HTTPProxyAdapter.java
private void initHttpConnectionManagerParams(HTTPConnectionManagerSettings settings) { connectionParams = new HttpConnectionManagerParams(); connectionParams.setMaxTotalConnections(settings.getMaxTotalConnections()); connectionParams.setDefaultMaxConnectionsPerHost(settings.getDefaultMaxConnectionsPerHost()); if (!settings.getCookiePolicy().equals(CookiePolicy.DEFAULT)) { HttpClientParams httpClientParams = (HttpClientParams) connectionParams.getDefaults(); httpClientParams.setCookiePolicy(settings.getCookiePolicy()); }/*from w ww . j a v a 2s . com*/ if (settings.getConnectionTimeout() >= 0) connectionParams.setConnectionTimeout(settings.getConnectionTimeout()); if (settings.getSocketTimeout() >= 0) connectionParams.setSoTimeout(settings.getSocketTimeout()); connectionParams.setStaleCheckingEnabled(settings.isStaleCheckingEnabled()); if (settings.getSendBufferSize() > 0) connectionParams.setSendBufferSize(settings.getSendBufferSize()); if (settings.getReceiveBufferSize() > 0) connectionParams.setReceiveBufferSize(settings.getReceiveBufferSize()); connectionParams.setTcpNoDelay(settings.isTcpNoDelay()); connectionParams.setLinger(settings.getLinger()); if (settings.getMaxConnectionsPerHost() != null) { Iterator it = settings.getMaxConnectionsPerHost().iterator(); while (it.hasNext()) { HostConfigurationSettings hcs = (HostConfigurationSettings) it.next(); HostConfiguration hostConfig = new HostConfiguration(); if (hcs.getProtocol() != null) { Protocol protocol = Protocol.getProtocol(hcs.getProtocol()); hostConfig.setHost(hcs.getHost(), hcs.getPort(), protocol); } else if (hcs.getProtocolFactory() != null) { Protocol protocol = hcs.getProtocolFactory().getProtocol(); if (hcs.getPort() > 0) hostConfig.setHost(hcs.getHost(), hcs.getPort(), protocol); else hostConfig.setHost(hcs.getHost(), protocol.getDefaultPort(), protocol); } else { if (hcs.getPort() > 0) hostConfig.setHost(hcs.getHost(), hcs.getPort()); else hostConfig.setHost(hcs.getHost()); } if (hcs.getVirtualHost() != null) { HostParams params = hostConfig.getParams(); if (params != null) params.setVirtualHost(hcs.getVirtualHost()); } if (hcs.getProxyHost() != null) { hostConfig.setProxy(hcs.getProxyHost(), hcs.getProxyPort()); } try { InetAddress addr = InetAddress.getByName(hcs.getLocalAddress()); hostConfig.setLocalAddress(addr); } catch (UnknownHostException ex) { } connectionParams.setMaxConnectionsPerHost(hostConfig, hcs.getMaximumConnections()); } } }