use of org.apache.commons.httpclient.DefaultHttpMethodRetryHandler in project janrufmonitor by tbrandt77.
the class JakartaRequester method request.
public IHttpResponse request() {
HttpClientParams params = new HttpClientParams();
params.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, false));
HttpClient client = new HttpClient(params);
try {
if (this.m_r instanceof Request) {
HttpMethod m = null;
byte[] result = null;
if (this.m_r != null && this.m_r.getMethod().equalsIgnoreCase(Request.METHOD_POST)) {
String url = "http://" + this.getServer() + ":" + this.getPort() + this.m_r.getURI();
m = new PostMethod(url);
if (this.m_r.getContent() != null) {
((PostMethod) m).setRequestEntity(new ByteArrayRequestEntity(this.m_r.getContent()));
// removed: 27.05.2005: changed to httpclient 3.0
// ((PostMethod)m).setRequestBody(new ByteArrayInputStream(this.m_r.getContent()));
// ((PostMethod)m).setRequestContentLength(this.m_r.getContent().length);
}
this.m_responseCode = client.executeMethod(m);
if (this.m_responseCode == HttpStatus.SC_OK)
result = m.getResponseBody();
}
if (this.m_r != null && this.m_r.getMethod().equalsIgnoreCase(Request.METHOD_GET)) {
String url = "http://" + this.getServer() + ":" + this.getPort() + this.m_r.getURI();
m = new GetMethod(url);
this.m_responseCode = client.executeMethod(m);
if (this.m_responseCode == HttpStatus.SC_OK)
result = m.getResponseBody();
}
Response resp = new Response();
Header[] headers = m.getResponseHeaders();
for (int i = 0; i < headers.length; i++) {
resp.setParameter(headers[i].getName(), headers[i].getValue());
}
resp.setCode(this.m_responseCode);
resp.setContent(result);
String debugEnabled = System.getProperty("jam.http.debug");
if (debugEnabled != null && debugEnabled.equalsIgnoreCase("true")) {
this.dump(this.m_r.toString());
this.dump(resp.toString());
}
if (m != null)
m.releaseConnection();
return resp;
}
} catch (IOException ex) {
this.m_responseCode = 0;
} catch (Exception e) {
this.m_responseCode = 0;
}
Response resp = new Response();
resp.setCode(0);
return resp;
}
use of org.apache.commons.httpclient.DefaultHttpMethodRetryHandler in project product-iots by wso2.
the class IOTHttpClient method delete.
public IOTResponse delete(String endpoint) {
HttpClient client = new HttpClient();
try {
ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
Protocol.registerProtocol(Constants.HTTPS, https);
String url = backEndUrl + endpoint;
DeleteMethod method = new DeleteMethod(url);
method.setRequestHeader(AUTHORIZATION, authorizationString);
method.setRequestHeader(Constants.CONTENT_TYPE, requestHeaders.get(Constants.CONTENT_TYPE));
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
IOTResponse iotResponse = new IOTResponse();
iotResponse.setStatus(client.executeMethod(method));
iotResponse.setBody(method.getResponseBodyAsString());
return iotResponse;
} catch (GeneralSecurityException e) {
log.error("Failure occurred at IOTResponse delete for GeneralSecurityException", e);
} catch (IOException e) {
log.error("Failure occurred at IOTResponse delete for IOException", e);
}
return null;
}
use of org.apache.commons.httpclient.DefaultHttpMethodRetryHandler in project product-iots by wso2.
the class IOTHttpClient method get.
public IOTResponse get(String endpoint) {
HttpClient client = new HttpClient();
try {
ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
Protocol.registerProtocol(Constants.HTTPS, https);
String url = backEndUrl + endpoint;
GetMethod method = new GetMethod(url);
method.setRequestHeader(AUTHORIZATION, authorizationString);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
IOTResponse iotResponse = new IOTResponse();
iotResponse.setStatus(client.executeMethod(method));
iotResponse.setBody(new String(method.getResponseBody()));
return iotResponse;
} catch (GeneralSecurityException e) {
log.error("Failure occurred at IOTResponse get for GeneralSecurityException", e);
} catch (IOException e) {
log.error("Failure occurred at IOTResponse get for IOException", e);
}
return null;
}
use of org.apache.commons.httpclient.DefaultHttpMethodRetryHandler 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.DefaultHttpMethodRetryHandler in project pinpoint by naver.
the class HttpClientIT method hostConfig.
@Test
public void hostConfig() {
HttpClient client = new HttpClient();
client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
client.getParams().setSoTimeout(SO_TIMEOUT);
HostConfiguration config = new HostConfiguration();
config.setHost("weather.naver.com", 80, "http");
GetMethod method = new GetMethod("/rgn/cityWetrMain.nhn");
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") });
try {
// Execute the method.
client.executeMethod(config, method);
} catch (Exception ignored) {
} finally {
method.releaseConnection();
}
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
}
Aggregations