From f15e02ef33656627a6053431ff929eb670d5114f Mon Sep 17 00:00:00 2001 From: Muskan Srivastava <t-muskans@microsoft.com> Date: Tue, 13 Apr 2021 21:36:46 +0530 Subject: [PATCH] fixed Json parser in Retry Policy --- .../osdu/indexer/azure/service/RetryPolicy.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/service/RetryPolicy.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/service/RetryPolicy.java index d6c23f566..7cee54ec9 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/service/RetryPolicy.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/service/RetryPolicy.java @@ -1,6 +1,7 @@ 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; -- GitLab