35
35
import org .apache .http .auth .AuthenticationException ;
36
36
import org .apache .http .auth .Credentials ;
37
37
import org .apache .http .auth .UsernamePasswordCredentials ;
38
+ import org .apache .http .client .HttpRequestRetryHandler ;
38
39
import org .apache .http .client .config .RequestConfig ;
39
40
import org .apache .http .client .methods .*;
40
41
import org .apache .http .client .utils .URLEncodedUtils ;
@@ -90,6 +91,7 @@ public static class Builder {
90
91
private SSLContext sslContext ;
91
92
private HostnameVerifier hostnameVerifier ;
92
93
private Integer timeout ;
94
+ private HttpRequestRetryHandler httpRequestRetryHandler ;
93
95
94
96
public Builder user (final String user ) {
95
97
this .user = user ;
@@ -146,8 +148,14 @@ public Builder timeout(final Integer timeout) {
146
148
return this ;
147
149
}
148
150
151
+ public Builder httpRequestRetryHandler (final HttpRequestRetryHandler httpRequestRetryHandler ) {
152
+ this .httpRequestRetryHandler = httpRequestRetryHandler ;
153
+ return this ;
154
+ }
155
+
149
156
public HttpConnection build () {
150
- return new HttpConnection (host , timeout , user , password , useSsl , sslContext , hostnameVerifier , util , contentType , ttl , httpCookieSpec );
157
+ return new HttpConnection (host , timeout , user , password , useSsl , sslContext , hostnameVerifier , util ,
158
+ contentType , ttl , httpCookieSpec , httpRequestRetryHandler );
151
159
}
152
160
}
153
161
@@ -162,7 +170,7 @@ public HttpConnection build() {
162
170
163
171
private HttpConnection (final HostDescription host , final Integer timeout , final String user , final String password ,
164
172
final Boolean useSsl , final SSLContext sslContext , final HostnameVerifier hostnameVerifier , final ArangoSerialization util , final Protocol contentType ,
165
- final Long ttl , final String httpCookieSpec ) {
173
+ final Long ttl , final String httpCookieSpec , final HttpRequestRetryHandler httpRequestRetryHandler ) {
166
174
super ();
167
175
this .host = host ;
168
176
this .user = user ;
@@ -197,7 +205,7 @@ private HttpConnection(final HostDescription host, final Integer timeout, final
197
205
final ConnectionKeepAliveStrategy keepAliveStrategy = (response , context ) -> HttpConnection .this .getKeepAliveDuration (response );
198
206
final HttpClientBuilder builder = HttpClientBuilder .create ().setDefaultRequestConfig (requestConfig .build ())
199
207
.setConnectionManager (cm ).setKeepAliveStrategy (keepAliveStrategy )
200
- .setRetryHandler (new DefaultHttpRequestRetryHandler ());
208
+ .setRetryHandler (httpRequestRetryHandler != null ? httpRequestRetryHandler : new DefaultHttpRequestRetryHandler ());
201
209
if (ttl != null ) {
202
210
builder .setConnectionTimeToLive (ttl , TimeUnit .MILLISECONDS );
203
211
}
0 commit comments