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));
}
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;
}
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;
}
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;
}
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;
}
Aggregations