use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project camel by apache.
the class MultiThreadedHttpGetTest method testHttpGetWithoutConversion.
@Test
public void testHttpGetWithoutConversion() throws Exception {
// This is needed as by default there are 2 parallel
// connections to some host and there is nothing that
// closes the http connection here.
// Need to set the httpConnectionManager
HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(5);
context.getComponent("http", HttpComponent.class).setHttpConnectionManager(httpConnectionManager);
String endpointName = "seda:withoutConversion?concurrentConsumers=5";
sendMessagesTo(endpointName, 5);
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project core-util by WSO2Telco.
the class OAuthApplicationDataStubFactory method createHttpClient.
/**
* This created httpclient pool that can be used to connect to external entity. This connection can be configured
* via broker.xml by setting up the required http connection parameters.
*
* @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager
*/
private HttpClient createHttpClient() {
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setDefaultMaxConnectionsPerHost(config.getMaximumHttpConnectionPerHost());
params.setMaxTotalConnections(config.getMaximumTotalHttpConnection());
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.setParams(params);
return new HttpClient(connectionManager);
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project carbon-business-process by wso2.
the class BPELServerImpl method initHttpConnectionManager.
private void initHttpConnectionManager() throws Exception {
httpConnectionManager = new MultiThreadedHttpConnectionManager();
int maxConnectionsPerHost = bpelServerConfiguration.getMaxConnectionsPerHost();
int maxTotalConnections = bpelServerConfiguration.getMaxTotalConnections();
if (log.isDebugEnabled()) {
log.debug(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + "=" + maxConnectionsPerHost);
log.debug(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + "=" + maxTotalConnections);
}
if (maxConnectionsPerHost < 1 || maxTotalConnections < 1) {
String errmsg = HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + " and " + HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + " must be positive integers!";
log.error(errmsg);
throw new Exception(errmsg);
}
httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
httpConnectionManager.getParams().setMaxTotalConnections(maxTotalConnections);
// TODO: Modify this and move configuration to bps.xml
// Register the connection manager to a idle check thread
idleConnectionTimeoutThread = new IdleConnectionTimeoutThread();
idleConnectionTimeoutThread.setName("Http_Idle_Connection_Timeout_Thread");
long idleConnectionTimeout = Long.parseLong(odeConfigurationProperties.getProperty("http.idle.connection.timeout", "30000"));
long idleConnectionCheckInterval = Long.parseLong(odeConfigurationProperties.getProperty("http.idle.connection.check.interval", "30000"));
if (log.isDebugEnabled()) {
log.debug("http.idle.connection.timeout=" + idleConnectionTimeout);
log.debug("http.idle.connection.check.interval=" + idleConnectionCheckInterval);
}
idleConnectionTimeoutThread.setConnectionTimeout(idleConnectionTimeout);
idleConnectionTimeoutThread.setTimeoutInterval(idleConnectionCheckInterval);
idleConnectionTimeoutThread.addConnectionManager(httpConnectionManager);
idleConnectionTimeoutThread.start();
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project ovirt-engine by oVirt.
the class HttpUtils method getConnection.
/**
* There are places in the code where use http to communicate with vdsm or external providers
*
* @param connectionTimeOut
* - the instance type of the interface for this connection
* @param clientRetries
* - Number of retries if timeout occurd
* @param maxConnectionsPerHost
* - maximum number of connections allowed for a given host
* @param maxTotalConnections
* - The maximum number of connections allowed
* @return {@link HttpClient}.
*/
public static HttpClient getConnection(int connectionTimeOut, int clientRetries, int maxConnectionsPerHost, int maxTotalConnections) {
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setConnectionTimeout(connectionTimeOut);
params.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
params.setMaxTotalConnections(maxTotalConnections);
MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
httpConnectionManager.setParams(params);
// Create the client:
HttpClient client = new HttpClient(httpConnectionManager);
// Configure the HTTP client so it will retry the execution of
// methods when there are IO errors:
int retries = Config.getValue(ConfigValues.vdsRetries);
HttpMethodRetryHandler handler = new DefaultHttpMethodRetryHandler(retries, false);
HttpClientParams parameters = client.getParams();
parameters.setParameter(HttpMethodParams.RETRY_HANDLER, handler);
// Done:
return client;
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project wicket by apache.
the class Tester method run.
/**
* Runs the test.
*
* @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();
}
}
}
Aggregations