use of org.apache.http.client.HttpRequestRetryHandler in project SeaStar by 13120241790.
the class AsyncHttpRequest method makeRequestWithRetries.
private void makeRequestWithRetries() throws IOException {
boolean retry = true;
IOException cause = null;
HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
try {
while (retry) {
try {
makeRequest();
return;
} catch (UnknownHostException e) {
// switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
// while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
// (to assist in genuine cases of unknown host) which seems better than outright failure
cause = new IOException("UnknownHostException exception: " + e.getMessage());
retry = (executionCount > 0) && retryHandler.retryRequest(cause, ++executionCount, context);
} catch (NullPointerException e) {
// there's a bug in HttpClient 4.0.x that on some occasions causes
// DefaultRequestExecutor to throw an NPE, see
// http://code.google.com/p/android/issues/detail?id=5255
cause = new IOException("NPE in HttpClient: " + e.getMessage());
retry = retryHandler.retryRequest(cause, ++executionCount, context);
} catch (IOException e) {
cause = e;
retry = retryHandler.retryRequest(cause, ++executionCount, context);
}
if (retry && (responseHandler != null)) {
responseHandler.sendRetryMessage();
}
}
} catch (Exception e) {
// catch anything else to ensure failure message is propagated
Log.e("AsyncHttpRequest", "Unhandled exception origin cause", e);
cause = new IOException("Unhandled exception: " + e.getMessage());
}
// cleaned up to throw IOException
throw (cause);
}
use of org.apache.http.client.HttpRequestRetryHandler in project ddf by codice.
the class HttpSolrClientFactory method getSecureHttpClient.
private static CloseableHttpClient getSecureHttpClient(boolean retryRequestsOnError) {
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(getSslContext(), getProtocols(), getCipherSuites(), SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
HttpRequestRetryHandler solrRetryHandler = new SolrHttpRequestRetryHandler();
HttpClientBuilder builder = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory).setDefaultCookieStore(new BasicCookieStore()).setMaxConnTotal(128).setMaxConnPerRoute(32);
if (retryRequestsOnError) {
builder.setRetryHandler(solrRetryHandler);
}
return builder.build();
}
Aggregations