I am doing some http rest api calls using jersey-client. Now I want to do a retry for a failure request. Say if the return error code is not 200 then I want to retry it again for a few times. How can do it using Jersey client
For implementing retries in any situation, check out Failsafe:
RetryPolicy retryPolicy = new RetryPolicy()
.retryIf((ClientResponse response) -> response.getStatus() != 200)
.withDelay(1, TimeUnit.SECONDS)
.withMaxRetries(3);
Failsafe.with(retryPolicy).get(() -> webResource.post(ClientResponse.class, input));
This example retries if the response status != 200, up to 3 times, with a 1 second delay between retries.