Search in sources :

Example 16 with HttpRequestRetryHandler

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);
}
Also used : UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) HttpRequestRetryHandler(org.apache.http.client.HttpRequestRetryHandler) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 17 with HttpRequestRetryHandler

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();
}
Also used : BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) HttpRequestRetryHandler(org.apache.http.client.HttpRequestRetryHandler) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory)

Aggregations

HttpRequestRetryHandler (org.apache.http.client.HttpRequestRetryHandler)17 IOException (java.io.IOException)14 UnknownHostException (java.net.UnknownHostException)10 HttpResponse (org.apache.http.HttpResponse)7 HttpContext (org.apache.http.protocol.HttpContext)4 MalformedURLException (java.net.MalformedURLException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 HttpHost (org.apache.http.HttpHost)3 AuthScope (org.apache.http.auth.AuthScope)3 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)3 InstrumentedHttpRequestExecutor (com.codahale.metrics.httpclient.InstrumentedHttpRequestExecutor)2 HttpException (com.lidroid.xutils.exception.HttpException)2 AuthConfiguration (io.dropwizard.client.proxy.AuthConfiguration)2 ProxyConfiguration (io.dropwizard.client.proxy.ProxyConfiguration)2 File (java.io.File)2 ConnectException (java.net.ConnectException)2 SocketException (java.net.SocketException)2 HttpRequest (org.apache.http.HttpRequest)2 DnsResolver (org.apache.http.conn.DnsResolver)2 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)2