List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:com.intuit.data.autumn.client.impl.HttpCallImplWithConnectionPooling.java
private Client getClient(final HttpCallConfig<T> config) { // If either use connection pooling if (!config.getUseConnectionPooling() || client != null) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); if (config.getMaxConnectionPerHost().or(-1) > 0) { connectionManager.getParams() .setDefaultMaxConnectionsPerHost(config.getMaxConnectionPerHost().get()); } else {//from w ww.j a v a 2 s .c o m connectionManager.getParams().setDefaultMaxConnectionsPerHost(20); } HttpClient httpClient = new HttpClient(connectionManager); ApacheHttpClientHandler clientHandler = new ApacheHttpClientHandler(httpClient); ClientHandler root = new ApacheHttpClient(clientHandler); ClientConfig config1 = new DefaultApacheHttpClientConfig(); if (config.getProxyURL().isPresent()) { String proxyURLWithPort = "http://" + config.getProxyURL() + ':' + config.getProxyPort(); config1.getProperties().put(PROPERTY_PROXY_URI, proxyURLWithPort); } client = new Client(root, config1); //Setting connection timeouts and read timeouts when present and doing it in the getClient method if (config.getConnectionTimeout().or(-1) > 0) { client.setConnectTimeout(config.getConnectionTimeout().get()); } if (config.getReadTimeOut().or(-1) > 0) { client.setReadTimeout(config.getReadTimeOut().get()); } //Logging the client properties LOGGER.info("Created a new client with the following properties set by the application {}", client.getProperties().toString()); } return client; }
From source file:fr.aliasource.webmail.server.proxy.client.http.ProxyClient.java
private HttpClient createHttpClient() { mtConMan = new MultiThreadedHttpConnectionManager(); HttpClient ret = new HttpClient(mtConMan); HttpConnectionManagerParams mp = ret.getHttpConnectionManager().getParams(); mp.setDefaultMaxConnectionsPerHost(4); mp.setMaxTotalConnections(8);/* w w w .j av a2 s. c o m*/ return ret; }
From source file:com.sun.jersey.client.apache.ApacheHttpClient.java
/** * Create a default Apache HTTP client handler. * * @return a default Apache HTTP client handler. *///from w w w .ja v a2s. com private static ApacheHttpClientHandler createDefaultClientHander(ClientConfig cc) { final HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); return new ApacheHttpClientHandler(client, cc); }
From source file:com.ms.commons.utilities.HttpClientUtils.java
public static synchronized void init() { if (connectionManager != null) { return;/*from w w w . j a v a2 s . c o m*/ } connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setConnectionTimeout(10000); params.setSoTimeout(20000); params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 1000); params.setMaxTotalConnections(10000); connectionManager.setParams(params); client = new HttpClient(connectionManager); client.getParams().setParameter("http.protocol.max-redirects", 3); }
From source file:com.alfaariss.oa.authentication.remote.aselect.logout.LogoutManager.java
/** * Constructor./*from w w w . j a v a2 s . co m*/ * @param configurationManager The configuration manager * @param config The configuration section * @param idpStorage The remote A-Select organization storage. * @param sMethodId The method id. * @throws OAException If config could not be read or is invalid. */ public LogoutManager(IConfigurationManager configurationManager, Element config, IIDPStorage idpStorage, String sMethodId) throws OAException { try { _logger = LogFactory.getLog(LogoutManager.class); _eventLogger = LogFactory.getLog(Engine.EVENT_LOGGER); _idpStorage = idpStorage; _sMethodID = sMethodId; _bEnabled = true; if (config != null) { Element eLogout = configurationManager.getSection(config, "logout"); if (eLogout != null) { String sEnabled = configurationManager.getParam(eLogout, "enabled"); if (sEnabled != null) { if (sEnabled.equalsIgnoreCase("FALSE")) _bEnabled = false; else if (!sEnabled.equalsIgnoreCase("TRUE")) { _logger.error("Unknown value in 'enabled' configuration item: " + sEnabled); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } } } } if (!_bEnabled) { _logger.info("Synchronous logout manager: disabled"); } else { Engine engine = Engine.getInstance(); _cryptoManager = engine.getCryptoManager(); _server = engine.getServer(); _aliasStoreIDPRole = engine.getTGTFactory().getAliasStoreIDP(); if (_aliasStoreIDPRole == null) { _logger.info("No IDP TGT Alias store available, disabling synchronous logout manager"); _bEnabled = false; return; } //Create thread safe HTTP client from parent config MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); _httpClient = new HttpClient(connectionManager); if (config != null) { Element eHTTP = configurationManager.getSection(config, "http"); if (eHTTP != null) readHTTPConfig(configurationManager, eHTTP); else _logger.info( "No optional 'http' section configured, using default http connection settings"); } } _logger.info("Synchronous Logout Manager: started"); } catch (OAException e) { throw e; } catch (Exception e) { _logger.fatal("Could not create synchronous logout manager", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } }
From source file:com.vdenotaris.spring.boot.security.saml.web.config.WebSecurityConfig.java
@PostConstruct public void init() { this.backgroundTaskTimer = new Timer(true); this.multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); }
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 . j a v a 2 s .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:com.cerema.cloud2.lib.common.network.NetworkUtils.java
static public MultiThreadedHttpConnectionManager getMultiThreadedConnManager() { if (mConnManager == null) { mConnManager = new MultiThreadedHttpConnectionManager(); mConnManager.getParams().setDefaultMaxConnectionsPerHost(5); mConnManager.getParams().setMaxTotalConnections(5); }/*from ww w . j a va 2s.c o m*/ return mConnManager; }
From source file:com.taobao.diamond.client.impl.DefaultDiamondSubscriber.java
protected void initHttpClient() { if (MockServer.isTestMode()) { return;/* w w w. ja v a2 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;//w w w . jav a2s .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); }