retry post request

1,396 views
Skip to first unread message

Lalith Choudary

unread,
Aug 17, 2015, 6:25:00 PM8/17/15
to REST assured
Hi Johan/Group,

How r u guys handling retry logic for a post call? I have a non user facing API(basically test mock) which is ok to retry if call fails. Right now I am looping in x times until there is 200 response. Is there a better way to handle such cases?

-thanks for your time,
Lalith

Johan Haleby

unread,
Aug 18, 2015, 12:04:25 AM8/18/15
to rest-a...@googlegroups.com
That's one way but you should also be able to instruct Apache HTTP Client to retry by setting a DefaultHttpRequestRetryHandler (please google for this yourself). You can then set a custom HTTP Client instance by creating a HttpClientFactory and pass it into the com.jayway.restassured.config.HttpClientConfig. For example:

HttpClientFactory myHttpClientFactory = ..
given().config(RestAssured.config().httpClientConfig(httpClientConfig().httpClientFactory(myHttpClientFactory)). ..

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rohan Palkar

unread,
Feb 28, 2017, 12:59:45 AM2/28/17
to REST assured
Hi, 

I implemented the following but I am not able to check if it's working or not. Could anyone please advice where can I check if it retried using logs or any thing else.

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));

Please advice.

Thanks,
Rohan
Reply all
Reply to author
Forward
0 new messages