private HttpRequestRetryHandler getRetryHandler ( ) { final HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler ( ) { public boolean retryRequest ( IOException exception , int executionCount , HttpContext context ) { if ( executionCount >= connectionConfiguration . getExecutionCount ( ) ) { // Do not retry if over max retry count LOG . debug ( "Execution count {} is bigger than threshold. Stop" , executionCount ) ; return false ; } if ( exception instanceof NoHttpResponseException ) { LOG . debug ( "NoHttpResponseException exception. Retry count {}" , executionCount ) ; return true ; } if ( exception instanceof UnknownHostException ) { LOG . debug ( "UnknownHostException. Retry count {}" , executionCount ) ; return true ; } if ( exception instanceof ConnectTimeoutException ) { LOG . debug ( "ConnectTimeoutException. Retry count {}" , executionCount ) ; return true ; } if ( exception instanceof SocketTimeoutException || exception . getClass ( ) == SocketTimeoutException . class || exception . getClass ( ) . isInstance ( SocketTimeoutException . class ) ) { // Connection refused LOG . debug ( "socketTimeoutException Retry count {}" , executionCount ) ; return true ; } if ( exception instanceof InterruptedIOException ) { // Timeout LOG . debug ( "InterruptedIOException Retry count {}" , executionCount ) ; return true ; } if ( exception instanceof SSLException ) { LOG . debug ( "SSLException Retry count {}" , executionCount ) ; return true ; } final HttpClientContext clientContext = HttpClientContext . adapt ( context ) ; final HttpRequest request = clientContext . getRequest ( ) ; boolean idempotent = ! ( request instanceof HttpEntityEnclosingRequest ) ; if ( idempotent ) { LOG . debug ( "HttpEntityEnclosingRequest. Retry count {}" , executionCount ) ; return true ; } LOG . debug ( "Retry stopped. Retry count {}" , executionCount ) ; return false ; } } ; return myRetryHandler ; }
Creates custom retry handler to be used if HTTP exception happens