Search in sources :

Example 16 with MultiThreadedHttpConnectionManager

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);
}
Also used : MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HttpComponent(org.apache.camel.component.http.HttpComponent) HttpConnectionManager(org.apache.commons.httpclient.HttpConnectionManager) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) Test(org.junit.Test)

Example 17 with MultiThreadedHttpConnectionManager

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);
}
Also used : HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HttpConnectionManager(org.apache.commons.httpclient.HttpConnectionManager) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)

Example 18 with MultiThreadedHttpConnectionManager

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();
}
Also used : IdleConnectionTimeoutThread(org.apache.commons.httpclient.util.IdleConnectionTimeoutThread) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) BpelEngineException(org.apache.ode.bpel.iapi.BpelEngineException)

Example 19 with MultiThreadedHttpConnectionManager

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;
}
Also used : HttpMethodRetryHandler(org.apache.commons.httpclient.HttpMethodRetryHandler) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams)

Example 20 with MultiThreadedHttpConnectionManager

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();
        }
    }
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) GetMethod(org.apache.commons.httpclient.methods.GetMethod)

Aggregations

MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)34 HttpClient (org.apache.commons.httpclient.HttpClient)26 HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)13 IOException (java.io.IOException)11 HttpConnectionManager (org.apache.commons.httpclient.HttpConnectionManager)7 HttpMethodRetryHandler (org.apache.commons.httpclient.HttpMethodRetryHandler)7 ApacheHttpClient (com.sun.jersey.client.apache.ApacheHttpClient)6 HttpMethod (org.apache.commons.httpclient.HttpMethod)6 GetMethod (org.apache.commons.httpclient.methods.GetMethod)6 Protocol (org.apache.commons.httpclient.protocol.Protocol)6 ApacheHttpClientHandler (com.sun.jersey.client.apache.ApacheHttpClientHandler)5 HttpClientParams (org.apache.commons.httpclient.params.HttpClientParams)5 Credentials (org.apache.commons.httpclient.Credentials)3 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 AdvancedGeoCoder (com.google.code.geocoder.AdvancedGeoCoder)2 SocketTimeoutException (java.net.SocketTimeoutException)2 URISyntaxException (java.net.URISyntaxException)2 UnknownHostException (java.net.UnknownHostException)2 HttpException (org.apache.commons.httpclient.HttpException)2