Search in sources :

Example 1 with ApacheHttpClientHandler

use of com.sun.jersey.client.apache.ApacheHttpClientHandler in project coprhd-controller by CoprHD.

the class RestClientFactory method init.

/**
 * Initialize HTTP client
 */
public void init() {
    _clientMap = new ConcurrentHashMap<String, RestClientItf>();
    _log.info("Init");
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setMaxTotalConnections(_maxConn);
    params.setTcpNoDelay(true);
    params.setConnectionTimeout(_connTimeout);
    params.setSoTimeout(_socketConnTimeout);
    _connectionManager = new MultiThreadedHttpConnectionManager();
    _connectionManager.setParams(params);
    // close idle connections immediately
    _connectionManager.closeIdleConnections(0);
    HttpClient client = new HttpClient(_connectionManager);
    client.getParams().setConnectionManagerTimeout(connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });
    if (_needCertificateManager) {
        // TMP CODE to create dummy security certificate manager
        ClientConfig clientConfig = null;
        try {
            final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

                @Override
                public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
                }

                @Override
                public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
                }

                @Override
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
            } };
            // Install the all-trusting trust manager
            SSLContext sslContext;
            sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
            javax.net.ssl.HostnameVerifier hostVerifier = new javax.net.ssl.HostnameVerifier() {

                @Override
                public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
                    return true;
                }
            };
            clientConfig = new com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig();
            clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostVerifier, sslContext));
        } catch (GeneralSecurityException ex) {
            throw new RuntimeException("Failed to obtain ApacheHTTPClient Config");
        }
        _clientHandler = new ApacheHttpClientHandler(client, clientConfig);
    } else {
        _clientHandler = new ApacheHttpClientHandler(client);
    }
    Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 443));
}
Also used : HttpMethodRetryHandler(org.apache.commons.httpclient.HttpMethodRetryHandler) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Protocol(org.apache.commons.httpclient.protocol.Protocol) HTTPSProperties(com.sun.jersey.client.urlconnection.HTTPSProperties) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) SSLContext(javax.net.ssl.SSLContext) X509Certificate(java.security.cert.X509Certificate) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) X509TrustManager(javax.net.ssl.X509TrustManager) 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) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 2 with ApacheHttpClientHandler

use of com.sun.jersey.client.apache.ApacheHttpClientHandler in project coprhd-controller by CoprHD.

the class ECSApiFactory method init.

/**
 * Initialize
 */
public void init() {
    _log.info(" ECSApiFactory:init ECSApi factory initialization");
    _clientMap = new ConcurrentHashMap<String, ECSApi>();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setMaxTotalConnections(_maxConn);
    params.setTcpNoDelay(true);
    params.setConnectionTimeout(_connTimeout);
    params.setSoTimeout(_socketConnTimeout);
    _connectionManager = new MultiThreadedHttpConnectionManager();
    _connectionManager.setParams(params);
    // close idle connections immediately
    _connectionManager.closeIdleConnections(0);
    HttpClient client = new HttpClient(_connectionManager);
    client.getParams().setConnectionManagerTimeout(connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });
    _clientHandler = new ApacheHttpClientHandler(client);
    Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 4443));
}
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 3 with ApacheHttpClientHandler

use of com.sun.jersey.client.apache.ApacheHttpClientHandler in project coprhd-controller by CoprHD.

the class IsilonApiFactory method init.

/**
 * Initialize HTTP client
 */
public void init() {
    _clientMap = new ConcurrentHashMap<String, IsilonApi>();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setMaxTotalConnections(_maxConn);
    params.setTcpNoDelay(true);
    params.setConnectionTimeout(_connTimeout);
    params.setSoTimeout(_socketConnTimeout);
    _connectionManager = new MultiThreadedHttpConnectionManager();
    _connectionManager.setParams(params);
    // close idle connections immediately
    _connectionManager.closeIdleConnections(0);
    HttpClient client = new HttpClient(_connectionManager);
    client.getParams().setConnectionManagerTimeout(connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });
    _clientHandler = new ApacheHttpClientHandler(client);
    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 4 with ApacheHttpClientHandler

use of com.sun.jersey.client.apache.ApacheHttpClientHandler in project coprhd-controller by CoprHD.

the class HDSApiFactory method init.

/**
 * Initialize HTTP client
 */
public void init() {
    // Create the VPlex API client map.
    _clientMap = new ConcurrentHashMap<String, HDSApiClient>();
    // Setup the connection parameters.
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxTotalConnections(_maxConn);
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setConnectionTimeout(_connTimeoutMs);
    params.setSoTimeout(socketConnectionTimeoutMs);
    params.setTcpNoDelay(true);
    // Create the HTTP connection manager for managing the set of HTTP
    // connections.
    MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
    mgr.setParams(params);
    // close idle connections immediately
    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 5 with ApacheHttpClientHandler

use of com.sun.jersey.client.apache.ApacheHttpClientHandler 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)

Aggregations

ApacheHttpClient (com.sun.jersey.client.apache.ApacheHttpClient)5 ApacheHttpClientHandler (com.sun.jersey.client.apache.ApacheHttpClientHandler)5 IOException (java.io.IOException)5 HttpClient (org.apache.commons.httpclient.HttpClient)5 HttpMethod (org.apache.commons.httpclient.HttpMethod)5 HttpMethodRetryHandler (org.apache.commons.httpclient.HttpMethodRetryHandler)5 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)5 HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)5 Protocol (org.apache.commons.httpclient.protocol.Protocol)5 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)1 HTTPSProperties (com.sun.jersey.client.urlconnection.HTTPSProperties)1 GeneralSecurityException (java.security.GeneralSecurityException)1 X509Certificate (java.security.cert.X509Certificate)1 SSLContext (javax.net.ssl.SSLContext)1 TrustManager (javax.net.ssl.TrustManager)1 X509TrustManager (javax.net.ssl.X509TrustManager)1