Skip to content

Commit a2e2c78

Browse files
author
a-brandt
committed
bugfix reconnect (issue #25)
1 parent 0fc9081 commit a2e2c78

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/main/java/com/arangodb/http/HttpManager.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.http.HttpResponse;
3434
import org.apache.http.HttpStatus;
3535
import org.apache.http.NameValuePair;
36+
import org.apache.http.NoHttpResponseException;
3637
import org.apache.http.StatusLine;
3738
import org.apache.http.auth.AuthenticationException;
3839
import org.apache.http.auth.Credentials;
@@ -352,24 +353,29 @@ public HttpResponseEntity execute(HttpRequestEntity requestEntity) throws Arango
352353
try {
353354
return executeInternal(configure.getBaseUrl(), requestEntity);
354355
} catch (SocketException ex) {
355-
retries++;
356-
if (connectRetryCount > 0 && retries > connectRetryCount) {
357-
logger.error(ex.getMessage(), ex);
358-
throw new ArangoException(ex);
359-
}
356+
handleException(++retries, connectRetryCount, ex);
357+
} catch (NoHttpResponseException ex) {
358+
handleException(++retries, connectRetryCount, ex);
359+
}
360+
}
361+
}
360362

361-
if (configure.hasFallbackHost()) {
362-
configure.changeCurrentHost();
363-
}
363+
private void handleException(int retries, int connectRetryCount, Exception ex) throws ArangoException {
364+
if (connectRetryCount > 0 && retries > connectRetryCount) {
365+
logger.error(ex.getMessage(), ex);
366+
throw new ArangoException(ex);
367+
}
364368

365-
logger.warn(ex.getMessage(), ex);
366-
try {
367-
// 1000 milliseconds is one second.
368-
Thread.sleep(configure.getConnectRetryWait());
369-
} catch (InterruptedException iex) {
370-
Thread.currentThread().interrupt();
371-
}
372-
}
369+
if (configure.hasFallbackHost()) {
370+
configure.changeCurrentHost();
371+
}
372+
373+
logger.warn(ex.getMessage(), ex);
374+
try {
375+
// 1000 milliseconds is one second.
376+
Thread.sleep(configure.getConnectRetryWait());
377+
} catch (InterruptedException iex) {
378+
Thread.currentThread().interrupt();
373379
}
374380
}
375381

@@ -380,9 +386,10 @@ public HttpResponseEntity execute(HttpRequestEntity requestEntity) throws Arango
380386
* the request
381387
* @return the response of the request
382388
* @throws ArangoException
389+
* @throws NoHttpResponseException
383390
*/
384391
private HttpResponseEntity executeInternal(String baseUrl, HttpRequestEntity requestEntity)
385-
throws ArangoException, SocketException {
392+
throws ArangoException, SocketException, NoHttpResponseException {
386393

387394
String url = buildUrl(baseUrl, requestEntity);
388395

@@ -430,12 +437,16 @@ private HttpResponseEntity executeInternal(String baseUrl, HttpRequestEntity req
430437
return responseEntity;
431438
}
432439

433-
private HttpResponse executeRequest(HttpRequestBase request) throws SocketException, ArangoException {
440+
private HttpResponse executeRequest(HttpRequestBase request)
441+
throws SocketException, ArangoException, NoHttpResponseException {
434442
try {
435443
return client.execute(request);
436444
} catch (SocketException ex) {
437445
// catch SocketException before IOException
438446
throw ex;
447+
} catch (NoHttpResponseException ex) {
448+
// catch NoHttpResponseException before IOException
449+
throw ex;
439450
} catch (ClientProtocolException e) {
440451
throw new ArangoException(e);
441452
} catch (IOException e) {

0 commit comments

Comments
 (0)