List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:org.apache.sshd.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 = "localhost"; final int nbThread = 2; final int nbDownloads = 2; final int nbLoops = 2; final int port = getFreePort(); StringBuilder resp = new StringBuilder(); resp.append("<html><body>\n"); for (int i = 0; i < 1000; i++) { resp.append("0123456789\n"); }//from ww w . jav a 2 s . 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())); } }); acceptor.setReuseAddress(true); acceptor.bind(new InetSocketAddress(port)); Session session = createSession(); final int forwardedPort1 = getFreePort(); final int forwardedPort2 = getFreePort(); System.err.println("URL: http://localhost:" + forwardedPort2); session.setPortForwardingL(forwardedPort1, host, port); session.setPortForwardingR(forwardedPort2, "localhost", forwardedPort1); final CountDownLatch latch = new CountDownLatch(nbThread * nbDownloads * nbLoops); final Thread[] threads = new Thread[nbThread]; final List<Throwable> errors = new CopyOnWriteArrayList<Throwable>(); for (int i = 0; i < threads.length; i++) { threads[i] = new Thread() { 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 (int i = 0; i < threads.length; i++) { threads[i].start(); } latch.await(); for (Throwable t : errors) { t.printStackTrace(); } assertEquals(0, errors.size()); }
From source file:org.apache.sshd.PortForwardingTest.java
@Test @Ignore//from w w w . j a v a 2s . c om 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 = "localhost"; final int nbThread = 2; final int nbDownloads = 2; final int nbLoops = 2; final int port = getFreePort(); StringBuilder resp = new StringBuilder(); resp.append("<html><body>\n"); for (int i = 0; i < 1000; i++) { resp.append("0123456789\n"); } 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())); } }); acceptor.setReuseAddress(true); acceptor.bind(new InetSocketAddress(port)); Session session = createSession(); final int forwardedPort1 = getFreePort(); final int forwardedPort2 = getFreePort(); System.err.println("URL: http://localhost:" + forwardedPort2); session.setPortForwardingL(forwardedPort1, host, port); session.setPortForwardingR(forwardedPort2, "localhost", forwardedPort1); final CountDownLatch latch = new CountDownLatch(nbThread * nbDownloads * nbLoops); final Thread[] threads = new Thread[nbThread]; final List<Throwable> errors = new CopyOnWriteArrayList<Throwable>(); for (int i = 0; i < threads.length; i++) { threads[i] = new Thread() { 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 (int i = 0; i < threads.length; i++) { threads[i].start(); } latch.await(); for (Throwable t : errors) { t.printStackTrace(); } assertEquals(0, errors.size()); }
From source file:org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ReferenceBindingProvider.java
public void start() { configContext = Axis2EngineIntegration.getAxisConfigurationContext(extensionPoints.getServiceDiscovery()); // Apply the configuration from any other policies if (isRampartRequired) { Axis2EngineIntegration.loadRampartModule(configContext); }// w ww .ja v a 2 s . c om for (PolicyProvider pp : this.endpointReference.getPolicyProviders()) { pp.configureBinding(this); } try { Definition definition = wsBinding.getGeneratedWSDLDocument(); QName serviceQName = wsBinding.getService().getQName(); Port port = wsBinding.getPort(); if (port == null) { // service has multiple ports, select one port to use // TODO - it feels like there is much more to this than is // here at the moment as need to match with the service side // assuming that it's available Collection<Port> ports = wsBinding.getService().getPorts().values(); for (Port p : ports) { // look for a SOAP 1.1 port first if (p.getExtensibilityElements().get(0) instanceof SOAPAddress) { port = p; break; } } if (port == null) { // no SOAP 1.1 port available, so look for a SOAP 1.2 port for (Port p : ports) { if (p.getExtensibilityElements().get(0) instanceof SOAP12Address) { port = p; break; } } } } axisClientSideService = Axis2EngineIntegration.createClientSideAxisService(definition, serviceQName, port.getName(), new Options()); HttpClient httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); if (httpClient == null) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setDefaultMaxConnectionsPerHost(2); connectionManagerParams.setTcpNoDelay(true); connectionManagerParams.setStaleCheckingEnabled(true); connectionManagerParams.setLinger(0); connectionManager.setParams(connectionManagerParams); httpClient = new HttpClient(connectionManager); configContext.setThreadPool(new ThreadPool(1, 5)); configContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); configContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); } serviceClient = new ServiceClient(configContext, axisClientSideService); } catch (AxisFault e) { throw new RuntimeException(e); // TODO: better exception } }
From source file:org.apache.wicket.threadtest.tester.Tester.java
/** * Runs the test./* ww w. j ava2s . com*/ * * @throws Exception */ public void run() throws Exception { activeThreads = 0; HttpConnectionManagerParams connManagerParams = new HttpConnectionManagerParams(); connManagerParams.setDefaultMaxConnectionsPerHost(numberOfThreads * 2); MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); manager.setParams(connManagerParams); Server server = null; GetMethod getMethod = new GetMethod("http://localhost:" + port + "/"); try { getMethod.setFollowRedirects(true); HttpClient httpClient = new HttpClient(params, manager); int code = httpClient.executeMethod(getMethod); if (code != 200) { server = startServer(port); } } catch (Exception e) { server = startServer(port); } finally { getMethod.releaseConnection(); } try { ThreadGroup g = new ThreadGroup("runners"); Thread[] threads = new Thread[numberOfThreads]; HttpClient client = null; for (int i = 0; i < numberOfThreads; i++) { if (multipleSessions) { client = new HttpClient(params, manager); client.getHostConfiguration().setHost(host, port); } else { if (client == null) { client = new HttpClient(params, manager); client.getHostConfiguration().setHost(host, port); } } threads[i] = new Thread(g, new CommandRunner(commands, client, this)); } long start = System.currentTimeMillis(); for (int i = 0; i < numberOfThreads; i++) { activeThreads++; threads[i].start(); } while (activeThreads > 0) { synchronized (this) { wait(); } } long end = System.currentTimeMillis(); long time = end - start; log.info("\n******** finished in " + Duration.milliseconds(time) + " (" + time + " milis)"); } finally { MultiThreadedHttpConnectionManager.shutdownAll(); if (server != null) { server.stop(); } } }
From source file:org.appverse.web.framework.backend.ws.helpers.StubHelper.java
public static void configureEndpoint(String endpointPropertiesFile, String timeoutPropertyName, ServiceClient _serviceClient) {/* w w w .j a v a 2s . c o m*/ Properties endpointsProperties = new Properties(); InputStream endPointsInputStream = StubHelper.class.getResourceAsStream(endpointPropertiesFile); try { endpointsProperties.load(endPointsInputStream); } catch (IOException e) { e.printStackTrace(); } String accountTimeoutString = (String) endpointsProperties.get(timeoutPropertyName); try { long accountTimeout = new Long(accountTimeoutString) * 1000; _serviceClient.getOptions().setTimeOutInMilliSeconds(accountTimeout); } catch (NumberFormatException e) { logger.equals("Error login axis account service timeout"); } String endpointProxyEnabled = (String) endpointsProperties.get("endpoint.proxy.enabled"); if (endpointProxyEnabled != null && endpointProxyEnabled.equals("true")) { HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties(); String endpointProxyHost = endpointsProperties.getProperty("endpoint.proxy.host"); proxyProperties.setProxyName(endpointProxyHost); int endpointProxyPort = new Integer(endpointsProperties.getProperty("endpoint.proxy.port")); proxyProperties.setProxyPort(endpointProxyPort); _serviceClient.getOptions().setProperty(HTTPConstants.PROXY, proxyProperties); } if (endpointsProperties.getProperty("endpoint.ignore_SSL_errors") != null && endpointsProperties.getProperty("endpoint.ignore_SSL_errors").equals("true")) { // Create a trust manager that does not validate certificate // chains TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }; // Install the all-trusting trust manager try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { } } ConfigurationContext configurationContext = _serviceClient.getServiceContext().getConfigurationContext(); MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(50); multiThreadedHttpConnectionManager.setParams(params); HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager); configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); }
From source file:org.archive.wayback.liveweb.ArcRemoteLiveWebCache.java
/** * //from ww w .ja v a2s . com */ public ArcRemoteLiveWebCache() { connectionManager = new MultiThreadedHttpConnectionManager(); hostConfiguration = new HostConfiguration(); HttpClientParams params = new HttpClientParams(); params.setParameter(HttpClientParams.RETRY_HANDLER, new NoRetryHandler()); http = new HttpClient(params, connectionManager); http.setHostConfiguration(hostConfiguration); }
From source file:org.archive.wayback.liveweb.ARCUnwrappingProxy.java
/** * */ public ARCUnwrappingProxy() { connectionManager = new MultiThreadedHttpConnectionManager(); hostConfiguration = new HostConfiguration(); }
From source file:org.archive.wayback.liveweb.RemoteLiveWebCache.java
/** * /*from w ww. ja v a 2s . c o m*/ */ public RemoteLiveWebCache() { connectionManager = new MultiThreadedHttpConnectionManager(); hostConfiguration = new HostConfiguration(); HttpClientParams params = new HttpClientParams(); params.setParameter(HttpClientParams.RETRY_HANDLER, new NoRetryHandler()); http = new HttpClient(params, connectionManager); http.setHostConfiguration(hostConfiguration); }
From source file:org.archive.wayback.liveweb.StdRemoteLiveWebCache.java
/** * StdRemoteLiveWebCache constructor initializes and configures connection objects. *//*from w w w. j a v a2 s . c o m*/ public StdRemoteLiveWebCache() { connectionManager = new MultiThreadedHttpConnectionManager(); hostConfiguration = new HostConfiguration(); HttpClientParams params = new HttpClientParams(); params.setParameter(HttpClientParams.RETRY_HANDLER, new NoRetryHandler()); httpClient = new HttpClient(params, connectionManager); httpClient.setHostConfiguration(hostConfiguration); }
From source file:org.archive.wayback.resourceindex.ziplines.Http11BlockLoader.java
/** * //from w w w .j a v a 2 s .c o m */ public Http11BlockLoader() { connectionManager = new MultiThreadedHttpConnectionManager(); hostConfiguration = new HostConfiguration(); HttpClientParams params = new HttpClientParams(); // params.setParameter(HttpClientParams.RETRY_HANDLER, new NoRetryHandler()); http = new HttpClient(params, connectionManager); http.setHostConfiguration(hostConfiguration); }