List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:net.sourceforge.jwbf.bots.HttpBot.java
/** * protected because abstract.//w w w . j a v a 2s.c o m * */ protected HttpBot() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); client = new HttpClient(connectionManager); }
From source file:com.discursive.jccook.httpclient.MultithreadedExample.java
public void start() throws InterruptedException { HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = connectionManager.getParams(); params.setIntParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 2); params.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 4); List retrievers = new ArrayList(); for (int i = 0; i < 20; i++) { HttpClient client = new HttpClient(connectionManager); Thread thread = new Thread(new PageRetriever(client)); retrievers.add(thread);//from w w w .ja v a 2s . c o m } Iterator threadIter = retrievers.iterator(); while (threadIter.hasNext()) { Thread thread = (Thread) threadIter.next(); thread.start(); } }
From source file:arena.httpclient.commons.JakartaCommonsHttpClientSource.java
public JakartaCommonsHttpClientSource() { this.manager = new MultiThreadedHttpConnectionManager(); }
From source file:com.ironiacorp.http.impl.httpclient3.HttpJobRunnerHttpClient3.java
private void setupClient() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); // connectionManager.// maxConnectionsPerHost // maxTotalConnections httpClient = new HttpClient(connectionManager); // http://jakarta.apache.org/httpcomponents/httpclient-3.x/preference-api.html HttpClientParams params = httpClient.getParams(); params.setParameter("http.protocol.version", HttpVersion.HTTP_1_1); params.setParameter("http.socket.timeout", new Integer(60000)); params.setParameter("http.protocol.content-charset", "UTF-8"); params.setCookiePolicy(CookiePolicy.RFC_2109); }
From source file:com.mindquarry.common.index.SolrIndexClient.java
/** * Used to initialize the HTTP client./*w w w . j av a2 s .c o m*/ */ public void initialize() throws Exception { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); httpClient = new HttpClient(connectionManager); // enable Preemptive authentication to save one round trip httpClient.getParams().setAuthenticationPreemptive(true); Credentials solrCreds = new UsernamePasswordCredentials(solrLogin, solrPassword); AuthScope anyAuthScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); httpClient.getState().setCredentials(anyAuthScope, solrCreds); // register events by calling base class initialization super.initialize(); }
From source file:com.taobao.metamorphosis.client.http.SimpleHttpClient.java
protected void initHttpClient(HttpClientConfig config) { HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(config.getHost(), config.getPort()); connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.closeIdleConnections(config.getPollingIntervalTime() * 4000); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setStaleCheckingEnabled(config.isConnectionStaleCheckingEnabled()); params.setMaxConnectionsPerHost(hostConfiguration, config.getMaxHostConnections()); params.setMaxTotalConnections(config.getMaxTotalConnections()); params.setConnectionTimeout(config.getTimeout()); params.setSoTimeout(60 * 1000);/*w w w .ja v a 2s . co m*/ connectionManager.setParams(params); httpclient = new HttpClient(connectionManager); httpclient.setHostConfiguration(hostConfiguration); }
From source file:edu.harvard.i2b2.common.util.axis2.ServiceClient.java
public static String sendREST(String restEPR, OMElement request) throws Exception { String response = null;/* w w w. j a v a 2 s. c o m*/ org.apache.axis2.client.ServiceClient serviceClient = null; try { serviceClient = new org.apache.axis2.client.ServiceClient(); ServiceContext context = serviceClient.getServiceContext(); MultiThreadedHttpConnectionManager connManager = (MultiThreadedHttpConnectionManager) context .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER); if (connManager == null) { connManager = new MultiThreadedHttpConnectionManager(); context.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connManager); connManager.getParams().setMaxTotalConnections(100); connManager.getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 100); } HttpClient httpClient = new HttpClient(connManager); Options options = new Options(); options.setTo(new EndpointReference(restEPR)); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); options.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE); serviceClient.setOptions(options); OMElement result = serviceClient.sendReceive(request); if (result != null) { response = result.toString(); log.debug(response); } } catch (Exception e) { log.debug("Cleanup Error .", e); e.printStackTrace(); throw new I2B2Exception("" + StackTraceUtil.getStackTrace(e)); } finally { if (serviceClient != null) { try { serviceClient.cleanupTransport(); serviceClient.cleanup(); } catch (AxisFault e) { log.debug("Error .", e); } } } return response; }
From source file:com.liferay.portal.search.solr.server.BasicAuthSolrServer.java
public BasicAuthSolrServer(AuthScope authScope, String username, String password, String url) throws MalformedURLException { _username = username;//from ww w . jav a 2s .c o m _password = password; _multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpClient httpClient = new HttpClient(_multiThreadedHttpConnectionManager); if ((_username != null) && (_password != null)) { if (authScope == null) { authScope = AuthScope.ANY; } HttpState httpState = httpClient.getState(); httpState.setCredentials(authScope, new UsernamePasswordCredentials(_username, _password)); HttpClientParams httpClientParams = httpClient.getParams(); httpClientParams.setAuthenticationPreemptive(true); } _server = new CommonsHttpSolrServer(url, httpClient); }
From source file:edu.unc.lib.dl.ui.util.AnalyticsTrackerUtil.java
public AnalyticsTrackerUtil() { // Use a threaded manager with timeouts httpManager = new MultiThreadedHttpConnectionManager(); httpManager.getParams().setConnectionTimeout(2000); httpClient = new HttpClient(httpManager); }
From source file:com.gisgraphy.domain.geoloc.service.fulltextsearch.SolrClientTest.java
@Test public void testConstructorShouldAddEndingSlashIfNotPresent() { IsolrClient client = new SolrClient("http://127.0.0.1/solr", new MultiThreadedHttpConnectionManager()); Assert.assertTrue("SolrClient should add a '/' if not present ", client.getURL().equals("http://127.0.0.1/solr/")); }