diff --git a/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureHTTPClient.java b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureHTTPClient.java index 954f3acb24c7fde5fa13682a17f1eddc3eae7721..07a94a76e2443a0b3358e2169e237949b39054fc 100644 --- a/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureHTTPClient.java +++ b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureHTTPClient.java @@ -14,10 +14,15 @@ package org.opengroup.osdu.util; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; import lombok.ToString; import lombok.extern.java.Log; - +import javax.ws.rs.core.Response; +import java.net.SocketTimeoutException; +import java.util.Map; @Log @ToString public class AzureHTTPClient extends HTTPClient { @@ -35,4 +40,43 @@ public class AzureHTTPClient extends HTTPClient { } return token; } -} \ No newline at end of file + public ClientResponse send(String httpMethod, String url, String payLoad, Map<String, String> headers, String token) { + ClientResponse response; + System.out.println("in Azure send method"); + String correlationId = java.util.UUID.randomUUID().toString(); + log.info(String.format("Request correlation id: %s", correlationId)); + headers.put(HEADER_CORRELATION_ID, correlationId); + Client client = getClient(); + client.setReadTimeout(300000); + client.setConnectTimeout(300000); + log.info(String.format("httpMethod: %s", httpMethod)); + log.info(String.format("payLoad: %s", payLoad)); + log.info(String.format("headers: %s", headers)); + log.info(String.format("URL: %s", url)); + WebResource webResource = client.resource(url); + log.info("waiting on response in azure send"); + int retryCount = 2; + try{ + response = this.getClientResponse(httpMethod, payLoad, webResource, headers, token); + while (retryCount > 0) { + if (response.getStatusInfo().getFamily().equals(Response.Status.Family.valueOf("SERVER_ERROR"))) { + log.info(String.format("got resoponse : %s", response.getStatusInfo())); + Thread.sleep(5000); + log.info(String.format("Retrying --- ")); + response = this.getClientResponse(httpMethod, payLoad, webResource, headers, token); + } else + break; + retryCount--; + } + System.out.println("sending response from azure send method"); + return response; + } catch (Exception e) { + if (e.getCause() instanceof SocketTimeoutException) { + System.out.println("Retrying in case of socket timeout exception"); + return this.getClientResponse(httpMethod, payLoad, webResource, headers, token); + } + e.printStackTrace(); + throw new AssertionError("Error: Send request error", e); + } + } +} diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/HTTPClient.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/HTTPClient.java index 3d12744f80e9413308eaeb14cb0f3da0e1d7d235..dde76bb8801939a4d148925d563181fcfde2ff35 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/HTTPClient.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/HTTPClient.java @@ -24,11 +24,11 @@ public abstract class HTTPClient { private static Random random = new Random(); private final int MAX_ID_SIZE = 50; - private static final String HEADER_CORRELATION_ID = "correlation-id"; + protected static final String HEADER_CORRELATION_ID = "correlation-id"; public abstract String getAccessToken(); - private static Client getClient() { + protected static Client getClient() { TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { @@ -73,7 +73,7 @@ public abstract class HTTPClient { return response; } - private ClientResponse getClientResponse(String httpMethod, String requestBody, WebResource webResource, Map<String, String> headers, String token) { + protected ClientResponse getClientResponse(String httpMethod, String requestBody, WebResource webResource, Map<String, String> headers, String token) { final WebResource.Builder builder = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).header("Authorization", token); headers.forEach(builder::header); log.info("making request to datalake api");