List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:experiments.NewClass.java
/** * DOCUMENT ME!//from ww w. j av a2 s . c om * * @param args DOCUMENT ME! */ public static void main(final String[] args) { final HttpClient h = new HttpClient(new MultiThreadedHttpConnectionManager()); System.out.println("h was created: " + h); }
From source file:MultiThreadedExample.java
public static void main(String[] args) { // Create an HttpClient with the MultiThreadedHttpConnectionManager. // This connection manager must be used if more than one thread will // be using the HttpClient. HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); // Set the default host/protocol for the methods to connect to. // This value will only be used if the methods are not given an absolute URI httpClient.getHostConfiguration().setHost("jakarta.apache.org", 80, "http"); // create an array of URIs to perform GETs on String[] urisToGet = { "/", "/commons/", "/commons/httpclient/", "http://svn.apache.org/viewvc/jakarta/httpcomponents/oac.hc3x/" }; // create a thread for each URI GetThread[] threads = new GetThread[urisToGet.length]; for (int i = 0; i < threads.length; i++) { GetMethod get = new GetMethod(urisToGet[i]); get.setFollowRedirects(true);/*from w w w . ja va2 s . co m*/ threads[i] = new GetThread(httpClient, get, i + 1); } // start the threads for (int j = 0; j < threads.length; j++) { threads[j].start(); } }
From source file:fr.cls.atoll.motu.library.misc.cas.HttpClientTutorial.java
public static void main(String[] args) { // test();//from w w w .j av a 2s . c o m // System.setProperty("proxyHost", "proxy.cls.fr"); // adresse IP // System.setProperty("proxyPort", "8080"); // System.setProperty("socksProxyPort", "1080"); // // Authenticator.setDefault(new MyAuthenticator()); // Create an instance of HttpClient. // HttpClient client = new HttpClient(); HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); // Create a method instance. GetMethod method = new GetMethod(url); HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setProxy("proxy.cls.fr", 8080); client.setHostConfiguration(hostConfiguration); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); // String username = "xxx"; // String password = "xxx"; // Credentials credentials = new UsernamePasswordCredentials(username, password); // AuthScope authScope = new AuthScope("proxy.cls.fr", 8080); // // client.getState().setProxyCredentials(authScope, credentials); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data System.out.println(new String(responseBody)); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } }
From source file:integration.HeavyLoad.java
public static void main(String[] args) throws IOException { url = args[0] + "/create.json"; final String specFile = args[1]; for (int i = 2; i < args.length; i++) { String server = args[i];/* w ww . j av a 2 s . c o m*/ servers.add(new ServerStats(server)); } if (servers.isEmpty()) { servers.add(new ServerStats(DEFAULT)); } MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams params = connectionManager.getParams(); params.setSoTimeout(TIMEOUT); params.setConnectionTimeout(TIMEOUT); params.setDefaultMaxConnectionsPerHost(NB_THREADS); params.setMaxTotalConnections(NB_THREADS); httpClient = new HttpClient(connectionManager); spec = FileUtilities.readWholeTextFile(new File(specFile)); Thread[] threads = new Thread[NB_THREADS]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(new Reader(), "reader-" + i); threads[i].start(); } for (int i = 0; i < threads.length; i++) { try { threads[i].join(); } catch (InterruptedException e) { } } }
From source file:com.jivesoftware.os.jive.utils.shell.utils.Curl.java
public static Curl create() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient client = new HttpClient(connectionManager); return new Curl(client); }
From source file:fr.cls.atoll.motu.library.cas.util.HttpUtil.java
public static MultiThreadedHttpConnectionManager createConnectionManager() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.getParams().setDefaultMaxConnectionsPerHost(25); connectionManager.getParams().setMaxTotalConnections(250); return connectionManager; }
From source file:de.loercher.localpress.connector.HttpClientJob.java
@Override public void run() { try {/* ww w .java 2s .c om*/ MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient client = new HttpClient(connectionManager); HttpMethod method = new GetMethod(url); client.executeMethod(method); System.out.println(new String(method.getResponseBody())); } catch (IOException ex) { Logger.getLogger(HttpClientJob.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.smartitengineering.util.rest.client.jersey.cache.CacheableClient.java
private static CacheableClientHandler createDefaultClientHander(ClientConfig clientConfig) { final HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); return new CacheableClientHandler(client, clientConfig); }
From source file:cn.vlabs.duckling.common.http.WebSite.java
public WebSite(String baseurl) { client = new HttpClient(new MultiThreadedHttpConnectionManager()); baseURL = baseurl; }
From source file:com.gisgraphy.domain.geoloc.service.fulltextsearch.SolrClientTest.java
@Test public void testConstructorShouldNotAcceptNullParameters() { try {/*w w w .j a v a2 s . c o m*/ new SolrClient(null, new MultiThreadedHttpConnectionManager()); fail("solrClient constructor does not accept null URL"); } catch (IllegalArgumentException e) { } try { new SolrClient("", null); fail("solrClient constructor does not accept null multiThreadedHttpConnectionManager"); } catch (IllegalArgumentException e) { } }