use of org.apache.commons.httpclient.params.HttpClientParams 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.HttpClientParams in project openmeetings by apache.
the class AppointmentManager method createHttpClient.
/**
* Returns a new HttpClient with the inbuilt connection manager in this.
*
* @return HttpClient object that was created.
*/
public HttpClient createHttpClient() {
if (connmanager == null) {
connmanager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS);
params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
connmanager.setParams(params);
}
HttpClientParams clientParams = new HttpClientParams();
clientParams.setConnectionManagerTimeout(CONNECTION_MANAGER_TIMEOUT);
return new HttpClient(connmanager);
}
use of org.apache.commons.httpclient.params.HttpClientParams in project cosmic by MissionCriticalCloud.
the class ClusterServiceServletImpl method getHttpClient.
private HttpClient getHttpClient() {
if (s_client == null) {
final MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
mgr.getParams().setDefaultMaxConnectionsPerHost(4);
// TODO make it configurable
mgr.getParams().setMaxTotalConnections(1000);
s_client = new HttpClient(mgr);
final HttpClientParams clientParams = new HttpClientParams();
clientParams.setSoTimeout(ClusterServiceAdapter.ClusterMessageTimeOut.value() * 1000);
s_client.setParams(clientParams);
}
return s_client;
}
use of org.apache.commons.httpclient.params.HttpClientParams in project maven-plugins by apache.
the class ClassicJiraDownloader method doExecute.
/**
* Execute the query on the JIRA server.
*
* @throws Exception on error
*/
public void doExecute() throws Exception {
try {
HttpClient client = new HttpClient();
// MCHANGES-89 Allow circular redirects
HttpClientParams clientParams = client.getParams();
clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
// MCHANGES-237
clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
HttpState state = new HttpState();
HostConfiguration hc = new HostConfiguration();
client.setHostConfiguration(hc);
client.setState(state);
String baseUrl = JiraHelper.getBaseUrl(project.getIssueManagement().getUrl());
getLog().debug("JIRA lives at: " + baseUrl);
// Here we only need the host part of the URL
determineProxy(baseUrl, client);
prepareBasicAuthentication(client);
boolean jiraAuthenticationSuccessful = false;
if (isJiraAuthenticationConfigured()) {
// Here we only need the parts up to and including the host part of the URL
jiraAuthenticationSuccessful = doJiraAuthentication(client, baseUrl);
}
if ((isJiraAuthenticationConfigured() && jiraAuthenticationSuccessful) || !isJiraAuthenticationConfigured()) {
String fullUrl;
if (useJql) {
fullUrl = getJqlQueryURL();
} else {
fullUrl = getParameterBasedQueryURL(client);
}
if (log.isDebugEnabled()) {
log.debug("download jira issues from url " + fullUrl);
}
// execute the GET
download(client, fullUrl);
}
} catch (Exception e) {
if (project.getIssueManagement() != null) {
getLog().error("Error accessing " + project.getIssueManagement().getUrl(), e);
} else {
getLog().error("Error accessing mock project issues", e);
}
}
}
use of org.apache.commons.httpclient.params.HttpClientParams in project dianping-open-sdk by dianping.
the class DemoApiTool method requestApi.
public static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap) {
String queryString = getQueryString(appKey, secret, paramMap);
StringBuffer response = new StringBuffer();
HttpClientParams httpConnectionParams = new HttpClientParams();
httpConnectionParams.setConnectionManagerTimeout(1000);
HttpClient client = new HttpClient(httpConnectionParams);
HttpMethod method = new GetMethod(apiUrl);
try {
if (StringUtils.isNotBlank(queryString)) {
// Encode query string with UTF-8
String encodeQuery = URIUtil.encodeQuery(queryString, "UTF-8");
LOGGER.debug("Encoded Query:" + encodeQuery);
method.setQueryString(encodeQuery);
}
client.executeMethod(method);
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
response.append(line).append(System.getProperty("line.separator"));
}
reader.close();
} catch (URIException e) {
LOGGER.error("Can not encode query: " + queryString + " with charset UTF-8. ", e);
} catch (IOException e) {
LOGGER.error("Request URL: " + apiUrl + " failed. ", e);
} finally {
method.releaseConnection();
}
return response.toString();
}
Aggregations