Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java: apache HttpClient > how to disable retry

I'm using Apache Httpclient for Ajax-calls on a website. In some cases requests to external webservice fail, often with:

I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect.

In that case, more often than not, I want to skip retrying the request (something that Httpclient seems to do automatically) .

However, I can't find any method, param, etc. to skip retrying.

anyone?

Thanks Geert-Jan

like image 758
Geert-Jan Avatar asked Feb 18 '10 01:02

Geert-Jan


2 Answers

From httpclient 4.3 use HttpClientBuilder

HttpClientBuilder.create().disableAutomaticRetries().build();
like image 127
Manoj Avatar answered Sep 23 '22 17:09

Manoj


client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));

That would do it.

like image 32
Elie Avatar answered Sep 24 '22 17:09

Elie