Search in sources :

Example 16 with HttpConnectionManagerParams

use of org.apache.commons.httpclient.params.HttpConnectionManagerParams in project coprhd-controller by CoprHD.

the class VPlexApiFactory method init.

/**
 * Initialize HTTP client
 */
private void init() {
    // Create the VPlex API client map.
    _clientMap = new ConcurrentHashMap<String, VPlexApiClient>();
    // Setup the connection parameters.
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxTotalConnections(_maxConn);
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setConnectionTimeout(_connTimeoutMs);
    params.setSoTimeout(_socketTimeoutMs);
    params.setTcpNoDelay(true);
    // Create the HTTP connection manager for managing the set of HTTP
    // connections and set the configuration parameters. Also, make sure
    // idle connections are closed immediately to prevent a buildup of
    // connections in the CLOSE_WAIT state.
    MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
    mgr.setParams(params);
    mgr.closeIdleConnections(0);
    // Create the HTTP client and set the handler for determining if an
    // HttpMethod should be retried after a recoverable exception during
    // execution.
    HttpClient client = new HttpClient(mgr);
    client.getParams().setConnectionManagerTimeout(connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });
    // Create the client handler.
    _clientHandler = new ApacheHttpClientHandler(client);
    // Register the specific for the HTTPS protocol.
    Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 443));
}
Also used : IOException(java.io.IOException) HttpMethodRetryHandler(org.apache.commons.httpclient.HttpMethodRetryHandler) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) ApacheHttpClientHandler(com.sun.jersey.client.apache.ApacheHttpClientHandler) Protocol(org.apache.commons.httpclient.protocol.Protocol) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 17 with HttpConnectionManagerParams

use of org.apache.commons.httpclient.params.HttpConnectionManagerParams in project application by collectionspace.

the class ServicesConnection method initClient.

private void initClient() {
    if (manager != null)
        return;
    synchronized (getClass()) {
        if (manager != null)
            return;
        // We're only connecting to one host, so set the max connections per host to be
        // the same as the max total connections.
        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
        params.setMaxTotalConnections(MAX_SERVICES_CONNECTIONS);
        params.setDefaultMaxConnectionsPerHost(MAX_SERVICES_CONNECTIONS);
        manager = new MultiThreadedHttpConnectionManager();
        manager.setParams(params);
    }
}
Also used : HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)

Example 18 with HttpConnectionManagerParams

use of org.apache.commons.httpclient.params.HttpConnectionManagerParams 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 19 with HttpConnectionManagerParams

use of org.apache.commons.httpclient.params.HttpConnectionManagerParams in project intellij by bazelbuild.

the class ProjectViewDocumentationProvider method pageExists.

private static boolean pageExists(String url) {
    final HttpClient client = new HttpClient();
    final HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
    params.setSoTimeout(5 * 1000);
    params.setConnectionTimeout(5 * 1000);
    try {
        final HeadMethod method = new HeadMethod(url);
        final int rc = client.executeMethod(method);
        if (rc == 404) {
            return false;
        }
    } catch (IllegalArgumentException e) {
        return false;
    } catch (IOException e) {
    // ignore
    }
    return true;
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClient(org.apache.commons.httpclient.HttpClient) IOException(java.io.IOException)

Aggregations

HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)19 HttpClient (org.apache.commons.httpclient.HttpClient)15 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)13 IOException (java.io.IOException)8 HttpMethodRetryHandler (org.apache.commons.httpclient.HttpMethodRetryHandler)7 Protocol (org.apache.commons.httpclient.protocol.Protocol)7 ApacheHttpClient (com.sun.jersey.client.apache.ApacheHttpClient)6 HttpMethod (org.apache.commons.httpclient.HttpMethod)6 ApacheHttpClientHandler (com.sun.jersey.client.apache.ApacheHttpClientHandler)5 HttpClientParams (org.apache.commons.httpclient.params.HttpClientParams)5 HttpConnectionManager (org.apache.commons.httpclient.HttpConnectionManager)3 HeadMethod (org.apache.commons.httpclient.methods.HeadMethod)2 HP3PARApi (com.emc.storageos.hp3par.impl.HP3PARApi)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)1 HTTPSProperties (com.sun.jersey.client.urlconnection.HTTPSProperties)1 File (java.io.File)1 URI (java.net.URI)1 GeneralSecurityException (java.security.GeneralSecurityException)1 X509Certificate (java.security.cert.X509Certificate)1