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