28
28
import java .net .SocketException ;
29
29
import java .net .UnknownHostException ;
30
30
import java .util .HashSet ;
31
+ import java .util .Iterator ;
31
32
32
33
import javax .net .ssl .SSLHandshakeException ;
33
34
34
35
import org .apache .http .NoHttpResponseException ;
35
- import org .apache .http .client .methods .HttpUriRequest ;
36
36
import org .apache .http .client .HttpRequestRetryHandler ;
37
+ import org .apache .http .client .methods .HttpUriRequest ;
37
38
import org .apache .http .protocol .ExecutionContext ;
38
39
import org .apache .http .protocol .HttpContext ;
39
40
@@ -73,10 +74,10 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte
73
74
if (executionCount > maxRetries ) {
74
75
// Do not retry if over max retry count
75
76
retry = false ;
76
- } else if (exceptionBlacklist . contains ( exception . getClass () )) {
77
+ } else if (isInList ( exceptionBlacklist , exception )) {
77
78
// immediately cancel retry if the error is blacklisted
78
79
retry = false ;
79
- } else if (exceptionWhitelist . contains ( exception . getClass () )) {
80
+ } else if (isInList ( exceptionWhitelist , exception )) {
80
81
// immediately retry if error is whitelisted
81
82
retry = true ;
82
83
} else if (!sent ) {
@@ -99,4 +100,14 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte
99
100
100
101
return retry ;
101
102
}
103
+
104
+ protected boolean isInList (HashSet <Class <?>> list , Throwable error ) {
105
+ Iterator <Class <?>> itr = list .iterator ();
106
+ while (itr .hasNext ()) {
107
+ if (itr .next ().isInstance (error )) {
108
+ return true ;
109
+ }
110
+ }
111
+ return false ;
112
+ }
102
113
}
0 commit comments