java: apache HttpClient > how to disable retry

Viewed 37893

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

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

That would do it.

There's a description in the HttpClient tutorial.

 client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
           new DefaultHttpMethodRetryHandler());

See the tutorial for more information, for instance this may be harmful if the request has side effects (i.e. is not idempotent).

Related