use of org.apache.commons.httpclient.params.HttpConnectionManagerParams in project ovirt-engine by oVirt.
the class HttpUtils method getConnection.
/**
* There are places in the code where use http to communicate with vdsm or external providers
*
* @param connectionTimeOut
* - the instance type of the interface for this connection
* @param clientRetries
* - Number of retries if timeout occurd
* @param maxConnectionsPerHost
* - maximum number of connections allowed for a given host
* @param maxTotalConnections
* - The maximum number of connections allowed
* @return {@link HttpClient}.
*/
public static HttpClient getConnection(int connectionTimeOut, int clientRetries, int maxConnectionsPerHost, int maxTotalConnections) {
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setConnectionTimeout(connectionTimeOut);
params.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
params.setMaxTotalConnections(maxTotalConnections);
MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
httpConnectionManager.setParams(params);
// Create the client:
HttpClient client = new HttpClient(httpConnectionManager);
// Configure the HTTP client so it will retry the execution of
// methods when there are IO errors:
int retries = Config.getValue(ConfigValues.vdsRetries);
HttpMethodRetryHandler handler = new DefaultHttpMethodRetryHandler(retries, false);
HttpClientParams parameters = client.getParams();
parameters.setParameter(HttpMethodParams.RETRY_HANDLER, handler);
// Done:
return client;
}
use of org.apache.commons.httpclient.params.HttpConnectionManagerParams in project wicket by apache.
the class Tester method run.
/**
* Runs the test.
*
* @throws Exception
*/
public void run() throws Exception {
activeThreads = 0;
HttpConnectionManagerParams connManagerParams = new HttpConnectionManagerParams();
connManagerParams.setDefaultMaxConnectionsPerHost(numberOfThreads * 2);
MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
manager.setParams(connManagerParams);
Server server = null;
GetMethod getMethod = new GetMethod("http://localhost:" + port + "/");
try {
getMethod.setFollowRedirects(true);
HttpClient httpClient = new HttpClient(params, manager);
int code = httpClient.executeMethod(getMethod);
if (code != 200) {
server = startServer(port);
}
} catch (Exception e) {
server = startServer(port);
} finally {
getMethod.releaseConnection();
}
try {
ThreadGroup g = new ThreadGroup("runners");
Thread[] threads = new Thread[numberOfThreads];
HttpClient client = null;
for (int i = 0; i < numberOfThreads; i++) {
if (multipleSessions) {
client = new HttpClient(params, manager);
client.getHostConfiguration().setHost(host, port);
} else {
if (client == null) {
client = new HttpClient(params, manager);
client.getHostConfiguration().setHost(host, port);
}
}
threads[i] = new Thread(g, new CommandRunner(commands, client, this));
}
long start = System.currentTimeMillis();
for (int i = 0; i < numberOfThreads; i++) {
activeThreads++;
threads[i].start();
}
while (activeThreads > 0) {
synchronized (this) {
wait();
}
}
long end = System.currentTimeMillis();
long time = end - start;
log.info("\n******** finished in " + Duration.milliseconds(time) + " (" + time + " milis)");
} finally {
MultiThreadedHttpConnectionManager.shutdownAll();
if (server != null) {
server.stop();
}
}
}
use of org.apache.commons.httpclient.params.HttpConnectionManagerParams in project nutch by apache.
the class Http method configureClient.
/**
* Configures the HTTP client
*/
private void configureClient() {
// Set up an HTTPS socket factory that accepts self-signed certs.
ProtocolSocketFactory factory;
if (tlsCheckCertificate) {
factory = new SSLProtocolSocketFactory();
} else {
factory = new DummySSLProtocolSocketFactory();
}
Protocol https = new Protocol("https", factory, 443);
Protocol.registerProtocol("https", https);
HttpConnectionManagerParams params = connectionManager.getParams();
params.setConnectionTimeout(timeout);
params.setSoTimeout(timeout);
params.setSendBufferSize(BUFFER_SIZE);
params.setReceiveBufferSize(BUFFER_SIZE);
// --------------------------------------------------------------------------------
// NUTCH-1836: Modification to increase the number of available connections
// for multi-threaded crawls.
// --------------------------------------------------------------------------------
params.setMaxTotalConnections(conf.getInt("mapreduce.tasktracker.map.tasks.maximum", 5) * conf.getInt("fetcher.threads.fetch", maxThreadsTotal));
// Also set max connections per host to maxThreadsTotal since all threads
// might be used to fetch from the same host - otherwise timeout errors can
// occur
params.setDefaultMaxConnectionsPerHost(conf.getInt("fetcher.threads.fetch", maxThreadsTotal));
// executeMethod(HttpMethod) seems to ignore the connection timeout on the
// connection manager.
// set it explicitly on the HttpClient.
client.getParams().setConnectionManagerTimeout(timeout);
HostConfiguration hostConf = client.getHostConfiguration();
ArrayList<Header> headers = new ArrayList<Header>();
// Note: some header fields (e.g., "User-Agent") are set per GET request
if (!acceptLanguage.isEmpty()) {
headers.add(new Header("Accept-Language", acceptLanguage));
}
if (!acceptCharset.isEmpty()) {
headers.add(new Header("Accept-Charset", acceptCharset));
}
if (!accept.isEmpty()) {
headers.add(new Header("Accept", accept));
}
// accept gzipped content
headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate"));
hostConf.getParams().setParameter("http.default-headers", headers);
// HTTP proxy server details
if (useProxy) {
hostConf.setProxy(proxyHost, proxyPort);
if (proxyUsername.length() > 0) {
AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm);
NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword, Http.agentHost, this.proxyRealm);
client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
}
}
}
use of org.apache.commons.httpclient.params.HttpConnectionManagerParams 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 org.apache.commons.httpclient.params.HttpConnectionManagerParams in project coprhd-controller by CoprHD.
the class HP3PARApiFactory method init.
/**
* Initialize HTTP client
*/
public void init() {
_log.info("3PARDriver:HP3PARApiFactory init enter");
_clientMap = new ConcurrentHashMap<String, HP3PARApi>();
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;
}
});
Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080));
}
Aggregations