Skip to content
Snippets Groups Projects
Commit f15e02ef authored by Muskan Srivastava's avatar Muskan Srivastava
Browse files

fixed Json parser in Retry Policy

parent 40c2a75c
No related branches found
No related tags found
1 merge request!147Enabling retry for indexer to storage service calls
Pipeline #35829 passed
package org.opengroup.osdu.indexer.azure.service;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.github.resilience4j.core.IntervalFunction;
......@@ -25,8 +26,9 @@ import static java.time.temporal.ChronoUnit.SECONDS;
public class RetryPolicy {
private static final int attempts =3;
private static final int waitDurationInMillis = 1000;
private final int attempts =3;
private final int waitDurationInMillis = 1000;
private final String notFound ="notFound";
Logger logger = LoggerFactory.getLogger(RetryPolicy.class);
......@@ -39,8 +41,9 @@ public class RetryPolicy {
.maxAttempts(attempts)
.waitDuration(Duration.ofMillis(waitDurationInMillis))
.retryOnResult(response -> {
List<String> notFound = new Gson().fromJson(response.getBody(), List.class);
if(notFound.isEmpty()) {
JsonObject jsonObject = new JsonParser().parse(response.getBody()).getAsJsonObject();
JsonArray notFoundArray = (JsonArray) jsonObject.get(notFound);
if (notFoundArray.size() == 0 || notFoundArray.isJsonNull()) {
return false;
}
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment