Search in sources :

Example 1 with ApacheHttpClient

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

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

the class ECSApiFactory method getRESTClient.

/**
 * Create ECS API client
 *
 * @param endpoint ECS endpoint
 * @return
 */
public ECSApi getRESTClient(URI endpoint) {
    ECSApi ecsApi = _clientMap.get(endpoint.toString() + ":" + ":");
    if (ecsApi == null) {
        Client jerseyClient = new ApacheHttpClient(_clientHandler);
        RESTClient restClient = new RESTClient(jerseyClient);
        ecsApi = new ECSApi(endpoint, restClient);
        _clientMap.putIfAbsent(endpoint.toString() + ":" + ":", ecsApi);
    }
    return ecsApi;
}
Also used : ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) Client(com.sun.jersey.api.client.Client)

Example 3 with ApacheHttpClient

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

the class HDSApiFactory method getClient.

/**
 * Get the HDS API client for the HDS Management Station identified
 * by the passed endpoint using the passed username and password.
 *
 * @param endpoint HDS Management Station endpoint URI.
 * @param username The user name to authenticate.
 * @param password The password to authenticate.
 *
 * @return Reference to a VPlexApiClient.
 */
public HDSApiClient getClient(URI endpoint, String username, String password) {
    // Make the key dependent on user and password in case they
    // change for a client endpoint.
    StringBuilder clientKeyBuilder = new StringBuilder();
    clientKeyBuilder.append(endpoint.toString());
    clientKeyBuilder.append("_");
    clientKeyBuilder.append(username);
    clientKeyBuilder.append("_");
    clientKeyBuilder.append(password);
    String clientKey = clientKeyBuilder.toString();
    HDSApiClient hdsApiClient = _clientMap.get(clientKey);
    if (hdsApiClient == null) {
        Client jerseyClient = new ApacheHttpClient(_clientHandler);
        RESTClient restClient = new RESTClient(jerseyClient, username, password);
        hdsApiClient = new HDSApiClient(endpoint, restClient);
        _clientMap.putIfAbsent(clientKey, hdsApiClient);
    }
    return hdsApiClient;
}
Also used : ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) Client(com.sun.jersey.api.client.Client)

Example 4 with ApacheHttpClient

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

the class IsilonApiFactory method getRESTClient.

/**
 * Create Isilon API client
 *
 * @param endpoint isilon endpoint
 * @return
 */
public IsilonApi getRESTClient(URI endpoint, String username, String password) {
    IsilonApi isilonApi = _clientMap.get(endpoint.toString() + ":" + username + ":" + password);
    if (isilonApi == null) {
        Client jerseyClient = new ApacheHttpClient(_clientHandler);
        jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password));
        RESTClient restClient = new RESTClient(jerseyClient);
        isilonApi = new IsilonApi(endpoint, restClient);
        _clientMap.putIfAbsent(endpoint.toString() + ":" + username + ":" + password, isilonApi);
    }
    return isilonApi;
}
Also used : ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 5 with ApacheHttpClient

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

the class IsilonApiFactory method getRESTClient.

/**
 * Create Isilon API client
 *
 * @param endpoint isilon endpoint
 * @return
 */
public IsilonApi getRESTClient(URI endpoint) {
    IsilonApi isilonApi = _clientMap.get(endpoint.toString() + ":" + ":");
    if (isilonApi == null) {
        Client jerseyClient = new ApacheHttpClient(_clientHandler);
        RESTClient restClient = new RESTClient(jerseyClient);
        isilonApi = new IsilonApi(endpoint, restClient);
        _clientMap.putIfAbsent(endpoint.toString() + ":" + ":", isilonApi);
    }
    return isilonApi;
}
Also used : ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) Client(com.sun.jersey.api.client.Client)

Aggregations

ApacheHttpClient (com.sun.jersey.client.apache.ApacheHttpClient)10 Client (com.sun.jersey.api.client.Client)9 HttpClient (org.apache.commons.httpclient.HttpClient)9 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)4 RestClientItf (com.emc.storageos.services.restutil.RestClientItf)1 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)1 ApacheHttpClientHandler (com.sun.jersey.client.apache.ApacheHttpClientHandler)1 HTTPSProperties (com.sun.jersey.client.urlconnection.HTTPSProperties)1 IOException (java.io.IOException)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 HttpMethod (org.apache.commons.httpclient.HttpMethod)1 HttpMethodRetryHandler (org.apache.commons.httpclient.HttpMethodRetryHandler)1 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)1 HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)1 Protocol (org.apache.commons.httpclient.protocol.Protocol)1