List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:org.apache.servicemix.http.HttpComponent.java
protected void doInit() throws Exception { // Load configuration configuration.setRootDir(context.getWorkspaceRoot()); configuration.setComponentName(context.getComponentName()); configuration.load();//from w ww . j av a2 s . co m // Lookup keystoreManager and authenticationService if (configuration.getKeystoreManager() == null) { try { String name = configuration.getKeystoreManagerName(); Object km = context.getNamingContext().lookup(name); configuration.setKeystoreManager(km); } catch (Throwable e) { // ignore } } if (configuration.getAuthenticationService() == null) { try { String name = configuration.getAuthenticationServiceName(); Object as = context.getNamingContext().lookup(name); configuration.setAuthenticationService(as); } catch (Throwable e) { try { Class cl = Class .forName("org.apache.servicemix.jbi.security.auth.impl.JAASAuthenticationService"); configuration.setAuthenticationService(cl.newInstance()); } catch (Throwable t) { logger.warn("Unable to retrieve or create the authentication service"); } } } // Create client if (client == null) { connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(configuration.getMaxConnectionsPerHost()); params.setMaxTotalConnections(configuration.getMaxTotalConnections()); connectionManager.setParams(params); client = new HttpClient(connectionManager); } // Create connectionPool if (connectionPool == null) { connectionPool = createNewJettyClient(); } // Create serverManager if (configuration.isManaged()) { server = new ManagedContextManager(); } else { JettyContextManager jcm = new JettyContextManager(); jcm.setMBeanServer(context.getMBeanServer()); this.server = jcm; } server.setConfiguration(configuration); server.init(); server.start(); if (listener != null) { listener.setMBeanServer(context.getMBeanServer()); listener.setDomainAndContainer(context.getMBeanNames().getJmxDomainName(), containerNameFromObjectName()); } // Default initalization super.doInit(); }
From source file:org.apache.sling.pipes.JsonPipe.java
/** * Configure http client/*ww w . j av a 2 s. c o m*/ */ private void configureHttpClient() { HttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); manager.setParams(params); client = new HttpClient(manager); client.getParams().setAuthenticationPreemptive(false); }
From source file:org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.java
/** * @see #useMultiPartPost/*from w w w .ja va 2 s . c o m*/ * @see #_parser */ public CommonsHttpSolrServer(URL baseURL, HttpClient client, ResponseParser parser, boolean useMultiPartPost) { _baseURL = baseURL.toExternalForm(); if (_baseURL.endsWith("/")) { _baseURL = _baseURL.substring(0, _baseURL.length() - 1); } if (_baseURL.indexOf('?') >= 0) { throw new RuntimeException( "Invalid base url for solrj. The base URL must not contain parameters: " + _baseURL); } if (client == null) { _httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); // prevent retries (note: this didn't work when set on mgr.. needed to be set on client) DefaultHttpMethodRetryHandler retryhandler = new DefaultHttpMethodRetryHandler(0, false); _httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler); // set some better defaults if we created a new connection manager and client // increase the default connections this.setDefaultMaxConnectionsPerHost(32); // 2 this.setMaxTotalConnections(128); // 20 } else { _httpClient = client; } _parser = parser; this.useMultiPartPost = useMultiPartPost; }
From source file:org.apache.solr.client.solrj.impl.LBHttpSolrServer.java
public LBHttpSolrServer(String... solrServerUrls) throws MalformedURLException { this(new HttpClient(new MultiThreadedHttpConnectionManager()), solrServerUrls); }
From source file:org.apache.solr.client.solrj.SolrExceptionTest.java
public void testSolrException() throws Throwable { // test a connection to a solr server that probably doesn't exist // this is a very simple test and most of the test should be considered verified // if the compiler won't let you by without the try/catch boolean gotExpectedError = false; try {/* w w w .ja v a 2 s . c o m*/ // switched to a local address to avoid going out on the net, ns lookup issues, etc. // set a 1ms timeout to let the connection fail faster. HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); httpClient.getParams().setParameter("http.connection.timeout", new Integer(1)); SolrServer client = new CommonsHttpSolrServer("http://localhost:11235/solr/", httpClient); SolrQuery query = new SolrQuery("test123"); client.query(query); } catch (SolrServerException sse) { gotExpectedError = true; /*** assertTrue(UnknownHostException.class == sse.getRootCause().getClass() //If one is using OpenDNS, then you don't get UnknownHostException, instead you get back that the query couldn't execute || (sse.getRootCause().getClass() == SolrException.class && ((SolrException) sse.getRootCause()).code() == 302 && sse.getMessage().equals("Error executing query"))); ***/ } assertTrue(gotExpectedError); }
From source file:org.apache.solr.client.solrj.TestLBHttpSolrServer.java
public void setUp() throws Exception { super.setUp(); httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); httpClient.getParams().setParameter("http.connection.timeout", new Integer(1000)); for (int i = 0; i < solr.length; i++) { solr[i] = new SolrInstance("solr" + i, 0); solr[i].setUp();//w ww. j a va2 s . c om solr[i].startJetty(); addDocs(solr[i]); } }
From source file:org.apache.solr.client.solrj.TestLBHttpSolrServer.java
public void testReliability() throws Exception { String[] s = new String[solr.length]; for (int i = 0; i < solr.length; i++) { s[i] = solr[i].getUrl();//from w ww .j a va 2 s . co m } HttpClient myHttpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); myHttpClient.getParams().setParameter("http.connection.timeout", new Integer(100)); myHttpClient.getParams().setParameter("http.socket.timeout", new Integer(100)); LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(myHttpClient, s); lbHttpSolrServer.setAliveCheckInterval(500); // Kill a server and test again solr[1].jetty.stop(); solr[1].jetty = null; // query the servers for (String value : s) lbHttpSolrServer.query(new SolrQuery("*:*")); // Start the killed server once again solr[1].startJetty(); // Wait for the alive check to complete waitForServer(30000, lbHttpSolrServer, 3, "solr1"); }
From source file:org.apache.solr.explorer.server.SolrProxyServlet.java
public SolrProxyServlet() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); client = new HttpClient(connectionManager); }
From source file:org.apache.solr.handler.dataimport.SolrEntityProcessor.java
/** * Factory method that returns a {@link HttpClient} instance used for interfacing with a source Solr service. * One can override this method to return a differently configured {@link HttpClient} instance. * For example configure https and http authentication. * * @return a {@link HttpClient} instance used for interfacing with a source Solr service *///from ww w. j av a 2 s. co m protected HttpClient getHttpClient() { return new HttpClient(new MultiThreadedHttpConnectionManager()); }
From source file:org.apache.sshd.common.forward.PortForwardingLoadTest.java
@Test public void testForwardingOnLoad() throws Exception { // final String path = "/history/recent/troubles/"; // final String host = "www.bbc.co.uk"; // final String path = ""; // final String host = "www.bahn.de"; final String path = ""; final String host = TEST_LOCALHOST; final int nbThread = 2; final int nbDownloads = 2; final int nbLoops = 2; StringBuilder resp = new StringBuilder(); resp.append("<html><body>\n"); for (int i = 0; i < 1000; i++) { resp.append("0123456789\n"); }//from ww w . j a va 2s . com resp.append("</body></html>\n"); final StringBuilder sb = new StringBuilder(); sb.append("HTTP/1.1 200 OK").append('\n'); sb.append("Content-Type: text/HTML").append('\n'); sb.append("Content-Length: ").append(resp.length()).append('\n'); sb.append('\n'); sb.append(resp); NioSocketAcceptor acceptor = new NioSocketAcceptor(); acceptor.setHandler(new IoHandlerAdapter() { @Override public void messageReceived(IoSession session, Object message) throws Exception { session.write(IoBuffer.wrap(sb.toString().getBytes(StandardCharsets.UTF_8))); } }); acceptor.setReuseAddress(true); acceptor.bind(new InetSocketAddress(0)); final int port = acceptor.getLocalAddress().getPort(); Session session = createSession(); try { final int forwardedPort1 = session.setPortForwardingL(0, host, port); final int forwardedPort2 = Utils.getFreePort(); session.setPortForwardingR(forwardedPort2, TEST_LOCALHOST, forwardedPort1); outputDebugMessage("URL: http://localhost %s", forwardedPort2); final CountDownLatch latch = new CountDownLatch(nbThread * nbDownloads * nbLoops); final Thread[] threads = new Thread[nbThread]; final List<Throwable> errors = new CopyOnWriteArrayList<>(); for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(getCurrentTestName() + "[" + i + "]") { @Override public void run() { for (int j = 0; j < nbLoops; j++) { final MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager(); final HttpClient client = new HttpClient(mgr); client.getHttpConnectionManager().getParams().setDefaultMaxConnectionsPerHost(100); client.getHttpConnectionManager().getParams().setMaxTotalConnections(1000); for (int i = 0; i < nbDownloads; i++) { try { checkHtmlPage(client, new URL("http://localhost:" + forwardedPort2 + path)); } catch (Throwable e) { errors.add(e); } finally { latch.countDown(); System.err.println("Remaining: " + latch.getCount()); } } mgr.shutdown(); } } }; } for (Thread thread : threads) { thread.start(); } latch.await(); for (Throwable t : errors) { t.printStackTrace(); } assertEquals(0, errors.size()); } finally { session.disconnect(); } }