Search in sources :

Example 26 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project openmeetings by apache.

the class AppointmentManager method createHttpClient.

/**
 * Returns a new HttpClient with the inbuilt connection manager in this.
 *
 * @return HttpClient object that was created.
 */
public HttpClient createHttpClient() {
    if (connmanager == null) {
        connmanager = new MultiThreadedHttpConnectionManager();
        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
        params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS);
        params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
        connmanager.setParams(params);
    }
    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setConnectionManagerTimeout(CONNECTION_MANAGER_TIMEOUT);
    return new HttpClient(connmanager);
}
Also used : HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams)

Example 27 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project ecf by eclipse.

the class AbstractBulletinBoard method postConnect.

public void postConnect() {
    try {
        this.url = new URL(getID().toExternalForm());
        final MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
        httpClient = new HttpClient(connectionManager);
    } catch (final MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) URL(java.net.URL)

Example 28 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project cosmic by MissionCriticalCloud.

the class UriUtils method getInputStreamFromUrl.

public static InputStream getInputStreamFromUrl(final String url, final String user, final String password) {
    try {
        final Pair<String, Integer> hostAndPort = validateUrl(url);
        final HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
        if ((user != null) && (password != null)) {
            httpclient.getParams().setAuthenticationPreemptive(true);
            final Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
            httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
            s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
        }
        // Execute the method.
        final GetMethod method = new GetMethod(url);
        final int statusCode = httpclient.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            s_logger.error("Failed to read from URL: " + url);
            return null;
        }
        return method.getResponseBodyAsStream();
    } catch (final Exception ex) {
        s_logger.error("Failed to read from URL: " + url);
        return null;
    }
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) AuthScope(org.apache.commons.httpclient.auth.AuthScope) GetMethod(org.apache.commons.httpclient.methods.GetMethod) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 29 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project cosmic by MissionCriticalCloud.

the class UriUtils method checkUrlExistence.

// use http HEAD method to validate url
public static void checkUrlExistence(final String url) {
    if (url.toLowerCase().startsWith("http") || url.toLowerCase().startsWith("https")) {
        final HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
        final HeadMethod httphead = new HeadMethod(url);
        try {
            if (httpClient.executeMethod(httphead) != HttpStatus.SC_OK) {
                throw new IllegalArgumentException("Invalid URL: " + url);
            }
        } catch (final HttpException hte) {
            throw new IllegalArgumentException("Cannot reach URL: " + url);
        } catch (final IOException ioe) {
            throw new IllegalArgumentException("Cannot reach URL: " + url);
        }
    }
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Example 30 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project cosmic by MissionCriticalCloud.

the class ClusterServiceServletImpl method getHttpClient.

private HttpClient getHttpClient() {
    if (s_client == null) {
        final MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
        mgr.getParams().setDefaultMaxConnectionsPerHost(4);
        // TODO make it configurable
        mgr.getParams().setMaxTotalConnections(1000);
        s_client = new HttpClient(mgr);
        final HttpClientParams clientParams = new HttpClientParams();
        clientParams.setSoTimeout(ClusterServiceAdapter.ClusterMessageTimeOut.value() * 1000);
        s_client.setParams(clientParams);
    }
    return s_client;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams)

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