How to implement a re-try logic in RestAssured for a failed REST call : <p>I am using RestAssured for firing API calls and wanted to implement a retry logic if the REST calls fails. </p>

<p>The requirement is because we are getting intermittent 500 response codes for certain APIs which usually work upon a re-try.</p>

<p>I have implemented the following code but it does not seem to work - </p>

<pre><code>HttpClientConfig.HttpClientFactory htc = new HttpClientConfig.HttpClientFactory() {

    @Override
    public HttpClient createHttpClient() {
        DefaultHttpClient d = new DefaultHttpClient();

        d.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(restRetryCount, true));
        return d;
    }
};

RestAssuredConfig rac = RestAssured.config().httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(htc));
</code></pre>

<p>Moreover, since RestAssured does not cater the HTTPClient level logging, I tried enabling the logging for the apache httpclient using the java.util.logging but that also <em>does not seem to be working either</em>.</p>

<p>Created a custom.logging.properties file with - </p>

<pre><code># Enables the header wire and context logging
org.apache.http.level = FINEST
org.apache.http.wire.level = SEVERE

# Enables the context logging for connection management &amp; request execution
org.apache.http.impl.conn.level = FINEST
org.apache.http.impl.client.level = FINEST
org.apache.http.client.level = FINEST
</code></pre>

<p>and wrote the following for initiating the logging - </p>

<pre><code>public static Logger initiateHttpTrafficLogging(){
     Logger log = Logger.getLogger("httptraffic.log");
     ClassLoader loader = Thread.currentThread().getContextClassLoader();
     InputStream is = loader.getResourceAsStream("custom.logging.properties");
     try{
         LogManager.getLogManager().readConfiguration(is);
         log.setLevel(Level.FINEST);
         log.addHandler(new ConsoleHandler());
         log.setUseParentHandlers(false);
         log.info("Initiating HTTP Traffic logging ::\n\n");
     } catch (IOException ie){
         Assert.fail("ERROR: Could not load the loggin properties !!!", ie.fillInStackTrace());
    }
    return log;
 }
</code></pre>

<p>Could anyone please provide me some direction as to where I am going wrong or any pointers to resolve this issue.</p>

<p>Appreciate your responses.
Thanks.</p>
