List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:org.abstracthorizon.proximity.storage.remote.CommonsHttpClientRemotePeer.java
/** * Gets the http client./* w ww .j a v a2 s .co m*/ * * @return the http client */ public HttpClient getHttpClient() { if (httpClient == null) { logger.info("Creating CommonsHttpClient instance"); httpRetryHandler = new DefaultHttpMethodRetryHandler(retrievalRetryCount, true); httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); httpClient.getParams().setConnectionManagerTimeout(getConnectionTimeout()); httpConfiguration = httpClient.getHostConfiguration(); // BASIC and DIGEST auth only if (getUsername() != null) { List authPrefs = new ArrayList(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); if (getNtlmDomain() != null) { // Using NTLM auth, adding it as first in policies authPrefs.add(0, AuthPolicy.NTLM); logger.info("... authentication setup for NTLM domain {}, username {}", getNtlmDomain(), getUsername()); httpConfiguration.setHost(getNtlmHost()); httpClient.getState().setCredentials(AuthScope.ANY, new NTCredentials(getUsername(), getPassword(), getNtlmHost(), getNtlmDomain())); } else { // Using Username/Pwd auth, will not add NTLM logger.info("... setting authentication setup for remote peer {}, with username {}", getRemoteUrl(), getUsername()); httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getUsername(), getPassword())); } httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); } if (getProxyHost() != null) { logger.info("... proxy setup with host {}", getProxyHost()); httpConfiguration.setProxy(getProxyHost(), getProxyPort()); if (getProxyUsername() != null) { List authPrefs = new ArrayList(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); if (getProxyNtlmDomain() != null) { // Using NTLM auth, adding it as first in policies authPrefs.add(0, AuthPolicy.NTLM); if (getNtlmHost() != null) { logger.warn("... CommonsHttpClient is unable to use NTLM auth scheme\n" + " for BOTH server side and proxy side authentication!\n" + " You MUST reconfigure server side auth and use BASIC/DIGEST scheme\n" + " if you have to use NTLM proxy, since otherwise it will not work!\n" + " *** SERVER SIDE AUTH OVERRIDDEN"); } logger.info("... proxy authentication setup for NTLM domain {}, username {}", getProxyNtlmDomain(), getProxyUsername()); httpConfiguration.setHost(getProxyNtlmHost()); httpClient.getState().setProxyCredentials(AuthScope.ANY, new NTCredentials( getProxyUsername(), getProxyPassword(), getProxyNtlmHost(), getProxyNtlmDomain())); } else { // Using Username/Pwd auth, will not add NTLM logger.info("... proxy authentication setup for http proxy {}, username {}", getProxyHost(), getProxyUsername()); httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getProxyUsername(), getProxyPassword())); } httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); } } } return httpClient; }
From source file:org.activebpel.rt.axis.bpel.handlers.AeHTTPSender.java
/** @deprecated */ protected void initialize() { if (sConnectionManager == null) { synchronized (AeHTTPSender.class) { if (sConnectionManager == null) { // initialize the connection manager w/ its properties MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager(); sClientProperties = CommonsHTTPClientPropertiesFactory.create(); // max connections per host, defaults to constant above int maxConnectionsPerHost = getIntegerOption( DefaultCommonsHTTPClientProperties.MAXIMUM_CONNECTIONS_PER_HOST_PROPERTY_KEY, DEFAULT_MAX_CONNECTIONS_PER_HOST); cm.setMaxConnectionsPerHost(maxConnectionsPerHost); // max connections, defaults to constant above int maxConnections = getIntegerOption( DefaultCommonsHTTPClientProperties.MAXIMUM_TOTAL_CONNECTIONS_PROPERTY_KEY, DEFAULT_MAX_CONNECTIONS); // as per apache-commons problem report #36882 (max connections per host setting does not work) // cm.setMaxTotalConnections(maxConnections); cm.getParams().setMaxTotalConnections(maxConnections); // save the connection manager for future calls sConnectionManager = cm; sConnectionTimeoutThread = new IdleConnectionTimeoutThread(); sConnectionTimeoutThread.addConnectionManager(sConnectionManager); int sweepInterval = getIntegerOption(KEY_IDLE_SWEEP_INTERVAL, DEFAULT_IDLE_CONNECTION_SWEEP_INTERVAL); sConnectionTimeoutThread.setTimeoutInterval(sweepInterval); int idleTimeout = getIntegerOption(KEY_IDLE_TIMEOUT, DEFAULT_IDLE_CONNECTION_TIMEOUT); sConnectionTimeoutThread.setConnectionTimeout(idleTimeout); sConnectionTimeoutThread.start(); }/* w ww . j av a 2 s . c o m*/ } } connectionManager = sConnectionManager; clientProperties = sClientProperties; }
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;/*w w w.java 2 s . c o 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.alfresco.httpclient.HttpClientFactory.java
protected HttpClient constructHttpClient() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient httpClient = new HttpClient(connectionManager); HttpClientParams params = httpClient.getParams(); params.setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true); params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true); if (socketTimeout != null) { params.setSoTimeout(socketTimeout); }/*from w w w. j a v a2s .co m*/ HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams(); connectionManagerParams.setMaxTotalConnections(maxTotalConnections); connectionManagerParams.setDefaultMaxConnectionsPerHost(maxHostConnections); connectionManagerParams.setConnectionTimeout(connectionTimeout); return httpClient; }
From source file:org.alfresco.jive.impl.JiveOpenClientImpl.java
public void init() { if (jiveUrl == null) { throw new IllegalStateException("jiveUrl has not been set."); }// ww w . j ava 2 s .co m int port = jiveUrl.getPort() == -1 ? jiveUrl.getDefaultPort() : jiveUrl.getPort(); httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); httpClient.getParams().setAuthenticationPreemptive(true); httpClient.getParams().setSoTimeout(timeoutInMs); httpClient.getParams().setConnectionManagerTimeout(timeoutInMs); httpClient.getState().setCredentials(new AuthScope(jiveUrl.getHost(), port), new UsernamePasswordCredentials(userName, String.valueOf(password)) // Security risk due to String interning... ); // Set the proxy host and port, if specified. // Note: unclear why HTTPClient doesn't do this automatically... String proxyHost = System.getProperty(JVM_PROPERTY_PROXY_HOST); if (proxyHost != null && proxyHost.trim().length() > 0) { String proxyPortStr = System.getProperty(JVM_PROPERTY_PROXY_PORT); if (proxyPortStr != null && proxyPortStr.trim().length() > 0) { int proxyPort = -1; try { proxyPort = Integer.valueOf(proxyPortStr.trim()); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); } catch (final NumberFormatException nfe) { log.warn("Proxy configuration (" + proxyHost + ":" + proxyPortStr + ") is invalid. Skipping configuration of proxy server."); } } else { log.warn("Proxy configuration is missing the port number. Skipping configuration of proxy server."); } } }
From source file:org.alfresco.repo.publishing.slideshare.SlideShareConnectorImpl.java
public SlideShareConnectorImpl() { httpClient = new HttpClient(); httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager()); }
From source file:org.alfresco.repo.transfer.HttpClientTransmitterImpl.java
public HttpClientTransmitterImpl() { protocolMap = new TreeMap<String, Protocol>(); protocolMap.put(HTTP_SCHEME_NAME, httpProtocol); protocolMap.put(HTTPS_SCHEME_NAME, httpsProtocol); httpClient = new HttpClient(); httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager()); httpMethodFactory = new StandardHttpMethodFactoryImpl(); jsonErrorSerializer = new ExceptionJsonSerializer(); }
From source file:org.alfresco.repo.urlshortening.BitlyUrlShortenerImpl.java
public BitlyUrlShortenerImpl() { httpClient = new HttpClient(); httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager()); HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost("api-ssl.bitly.com", 443, Protocol.getProtocol("https")); httpClient.setHostConfiguration(hostConfiguration); }
From source file:org.alfresco.rest.api.tests.client.SharedHttpClientProvider.java
public SharedHttpClientProvider(String alfrescoUrl, int maxNumberOfConnections) { setAlfrescoUrl(alfrescoUrl);/*from w w w .j a v a2s . c o m*/ // Initialize manager MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setMaxTotalConnections(maxNumberOfConnections); params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxNumberOfConnections); // Create the client client = new HttpClient(manager); client.getParams().setAuthenticationPreemptive(true); }
From source file:org.alfresco.wcm.client.impl.WebScriptCallerImpl.java
public WebScriptCallerImpl() { httpClient = new HttpClient(); httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager()); }