List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager setParams
public void setParams(HttpConnectionManagerParams paramHttpConnectionManagerParams)
From source file:com.amazonaws.a2s.AmazonA2SClient.java
/** * Configure HttpClient with set of defaults as well as configuration * from AmazonA2SConfig instance/* www .j ava 2s .com*/ * */ 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 (!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(3); connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, 3); /* 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()); } httpClient.setHostConfiguration(hostConfiguration); return httpClient; }
From source file:com.taobao.diamond.client.impl.DefaultDiamondPublisher.java
private void initHttpClient() { if (MockServer.isTestMode()) { return;/*from w w w . j ava 2 s .c om*/ } 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.taobao.diamond.client.impl.DefaultDiamondSubscriber.java
protected void initHttpClient() { if (MockServer.isTestMode()) { return;/*from w ww . j a v a 2 s . c o m*/ } 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:cn.leancloud.diamond.client.impl.DefaultDiamondSubscriber.java
protected void initHttpClient() { if (MockServer.isTestMode()) { return;/*from w w w. jav a 2 s . co m*/ } 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: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;/*from w w w .j a v a 2 s . co m*/ MultiThreadedHttpConnectionManager m_connectionmgr = new MultiThreadedHttpConnectionManager(); params = new HttpConnectionManagerParams(); params.setConnectionTimeout(timeout); params.setSoTimeout(timeout); 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.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ReferenceBindingProvider.java
public void start() { configContext = Axis2EngineIntegration.getAxisConfigurationContext(extensionPoints.getServiceDiscovery()); // Apply the configuration from any other policies if (isRampartRequired) { Axis2EngineIntegration.loadRampartModule(configContext); }//from ww w. j a v a 2 s. c o m for (PolicyProvider pp : this.endpointReference.getPolicyProviders()) { pp.configureBinding(this); } try { Definition definition = wsBinding.getGeneratedWSDLDocument(); QName serviceQName = wsBinding.getService().getQName(); Port port = wsBinding.getPort(); if (port == null) { // service has multiple ports, select one port to use // TODO - it feels like there is much more to this than is // here at the moment as need to match with the service side // assuming that it's available Collection<Port> ports = wsBinding.getService().getPorts().values(); for (Port p : ports) { // look for a SOAP 1.1 port first if (p.getExtensibilityElements().get(0) instanceof SOAPAddress) { port = p; break; } } if (port == null) { // no SOAP 1.1 port available, so look for a SOAP 1.2 port for (Port p : ports) { if (p.getExtensibilityElements().get(0) instanceof SOAP12Address) { port = p; break; } } } } axisClientSideService = Axis2EngineIntegration.createClientSideAxisService(definition, serviceQName, port.getName(), new Options()); HttpClient httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); if (httpClient == null) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setDefaultMaxConnectionsPerHost(2); connectionManagerParams.setTcpNoDelay(true); connectionManagerParams.setStaleCheckingEnabled(true); connectionManagerParams.setLinger(0); connectionManager.setParams(connectionManagerParams); httpClient = new HttpClient(connectionManager); configContext.setThreadPool(new ThreadPool(1, 5)); configContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); configContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); } serviceClient = new ServiceClient(configContext, axisClientSideService); } catch (AxisFault e) { throw new RuntimeException(e); // TODO: better exception } }
From source file:org.apache.wicket.threadtest.tester.Tester.java
/** * Runs the test./*from ww w .j ava 2 s .co m*/ * * @throws Exception */ public void run() throws Exception { activeThreads = 0; HttpConnectionManagerParams connManagerParams = new HttpConnectionManagerParams(); connManagerParams.setDefaultMaxConnectionsPerHost(numberOfThreads * 2); MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); manager.setParams(connManagerParams); Server server = null; GetMethod getMethod = new GetMethod("http://localhost:" + port + "/"); try { getMethod.setFollowRedirects(true); HttpClient httpClient = new HttpClient(params, manager); int code = httpClient.executeMethod(getMethod); if (code != 200) { server = startServer(port); } } catch (Exception e) { server = startServer(port); } finally { getMethod.releaseConnection(); } try { ThreadGroup g = new ThreadGroup("runners"); Thread[] threads = new Thread[numberOfThreads]; HttpClient client = null; for (int i = 0; i < numberOfThreads; i++) { if (multipleSessions) { client = new HttpClient(params, manager); client.getHostConfiguration().setHost(host, port); } else { if (client == null) { client = new HttpClient(params, manager); client.getHostConfiguration().setHost(host, port); } } threads[i] = new Thread(g, new CommandRunner(commands, client, this)); } long start = System.currentTimeMillis(); for (int i = 0; i < numberOfThreads; i++) { activeThreads++; threads[i].start(); } while (activeThreads > 0) { synchronized (this) { wait(); } } long end = System.currentTimeMillis(); long time = end - start; log.info("\n******** finished in " + Duration.milliseconds(time) + " (" + time + " milis)"); } finally { MultiThreadedHttpConnectionManager.shutdownAll(); if (server != null) { server.stop(); } } }
From source file:org.appverse.web.framework.backend.ws.helpers.StubHelper.java
public static void configureEndpoint(String endpointPropertiesFile, String timeoutPropertyName, ServiceClient _serviceClient) {/*from w ww .j a va2s . c om*/ Properties endpointsProperties = new Properties(); InputStream endPointsInputStream = StubHelper.class.getResourceAsStream(endpointPropertiesFile); try { endpointsProperties.load(endPointsInputStream); } catch (IOException e) { e.printStackTrace(); } String accountTimeoutString = (String) endpointsProperties.get(timeoutPropertyName); try { long accountTimeout = new Long(accountTimeoutString) * 1000; _serviceClient.getOptions().setTimeOutInMilliSeconds(accountTimeout); } catch (NumberFormatException e) { logger.equals("Error login axis account service timeout"); } String endpointProxyEnabled = (String) endpointsProperties.get("endpoint.proxy.enabled"); if (endpointProxyEnabled != null && endpointProxyEnabled.equals("true")) { HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties(); String endpointProxyHost = endpointsProperties.getProperty("endpoint.proxy.host"); proxyProperties.setProxyName(endpointProxyHost); int endpointProxyPort = new Integer(endpointsProperties.getProperty("endpoint.proxy.port")); proxyProperties.setProxyPort(endpointProxyPort); _serviceClient.getOptions().setProperty(HTTPConstants.PROXY, proxyProperties); } if (endpointsProperties.getProperty("endpoint.ignore_SSL_errors") != null && endpointsProperties.getProperty("endpoint.ignore_SSL_errors").equals("true")) { // Create a trust manager that does not validate certificate // chains TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }; // Install the all-trusting trust manager try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { } } ConfigurationContext configurationContext = _serviceClient.getServiceContext().getConfigurationContext(); MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(50); multiThreadedHttpConnectionManager.setParams(params); HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager); configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); }
From source file:org.eclipse.orion.server.cf.CFActivator.java
/** * Returns an HTTPClient instance that is configured to support multiple connections * in different threads. Callers must explicitly release any connections made using this * client.//from w w w .j a va 2s . c o m */ public synchronized HttpClient getHttpClient() { //see http://hc.apache.org/httpclient-3.x/threading.html MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connectionManagerParams = connectionManager.getParams(); connectionManagerParams.setConnectionTimeout(30000); connectionManager.setParams(connectionManagerParams); HttpClientParams clientParams = new HttpClientParams(); clientParams.setConnectionManagerTimeout(300000); // 5 minutes return new HttpClient(clientParams, connectionManager); }
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);//w ww . j a v a 2 s .co m para.setStaleCheckingEnabled(true); 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); }