diff --git a/src/main/java/io/cdap/plugin/successfactors/connector/SuccessFactorsConnector.java b/src/main/java/io/cdap/plugin/successfactors/connector/SuccessFactorsConnector.java index da10995..86bf4d1 100644 --- a/src/main/java/io/cdap/plugin/successfactors/connector/SuccessFactorsConnector.java +++ b/src/main/java/io/cdap/plugin/successfactors/connector/SuccessFactorsConnector.java @@ -225,7 +225,8 @@ private InputStream callEntityData(long top, String entityName) addQueryParameter(TOP_OPTION, String.valueOf(top)).addQueryParameter(SELECT_OPTION, selectFields.toString()) .build().url(); SuccessFactorsTransporter successFactorsHttpClient = new SuccessFactorsTransporter(config); - SuccessFactorsResponseContainer responseContainer = successFactorsHttpClient.callSuccessFactorsWithRetry(dataURL); + SuccessFactorsResponseContainer responseContainer = successFactorsHttpClient + .callSuccessFactorsWithRetry(dataURL, MediaType.APPLICATION_JSON); ExceptionParser.checkAndThrowException("", responseContainer); return responseContainer.getResponseStream(); diff --git a/src/main/java/io/cdap/plugin/successfactors/source/service/SuccessFactorsService.java b/src/main/java/io/cdap/plugin/successfactors/source/service/SuccessFactorsService.java index 0780dc6..31cbe05 100644 --- a/src/main/java/io/cdap/plugin/successfactors/source/service/SuccessFactorsService.java +++ b/src/main/java/io/cdap/plugin/successfactors/source/service/SuccessFactorsService.java @@ -162,9 +162,14 @@ private SuccessFactorsEntityProvider fetchServiceMetadata(InputStream metadataSt * @throws TransportException any http client exceptions are wrapped under it. */ private InputStream callEntityMetadata() throws TransportException { + try { SuccessFactorsResponseContainer responseContainer = successFactorsHttpClient - .callSuccessFactorsEntity(urlContainer.getMetadataURL(), MediaType.APPLICATION_XML, METADATA); + .callSuccessFactorsWithRetry(urlContainer.getMetadataURL(), MediaType.APPLICATION_XML); return responseContainer.getResponseStream(); + } catch (IOException e) { + LOG.error("Error occurred while fetching metadata for entity {}", pluginConfig.getEntityName()); + throw new RuntimeException(e); + } } /** @@ -320,7 +325,8 @@ private InputStream callEntityData(@Nullable Long skip, @Nullable Long top) } else { dataURL = urlContainer.getDataFetchURL(skip, top); } - SuccessFactorsResponseContainer responseContainer = successFactorsHttpClient.callSuccessFactorsWithRetry(dataURL); + SuccessFactorsResponseContainer responseContainer = successFactorsHttpClient + .callSuccessFactorsWithRetry(dataURL, MediaType.APPLICATION_JSON); ExceptionParser.checkAndThrowException("", responseContainer); return responseContainer.getResponseStream(); diff --git a/src/main/java/io/cdap/plugin/successfactors/source/transport/SuccessFactorsTransporter.java b/src/main/java/io/cdap/plugin/successfactors/source/transport/SuccessFactorsTransporter.java index 730a50a..d55eae2 100644 --- a/src/main/java/io/cdap/plugin/successfactors/source/transport/SuccessFactorsTransporter.java +++ b/src/main/java/io/cdap/plugin/successfactors/source/transport/SuccessFactorsTransporter.java @@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.net.ConnectException; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.MalformedURLException; @@ -59,7 +60,7 @@ public class SuccessFactorsTransporter { private static final Logger LOG = LoggerFactory.getLogger(SuccessFactorsTransporter.class); private static final long CONNECTION_TIMEOUT = 300; private static final long WAIT_TIME = 5; - private static final long MAX_NUMBER_OF_RETRY_ATTEMPTS = 5; + private static final long MAX_NUMBER_OF_RETRY_ATTEMPTS = 10; private SuccessFactorsConnectorConfig config; private Response response; @@ -103,10 +104,10 @@ public SuccessFactorsResponseContainer callSuccessFactorsEntity(URL endpoint, St * @throws IOException any http client exceptions * @throws TransportException any error while preparing the {@code OkHttpClient} */ - public SuccessFactorsResponseContainer callSuccessFactorsWithRetry(URL endpoint) + public SuccessFactorsResponseContainer callSuccessFactorsWithRetry(URL endpoint, String mediaType) throws IOException, TransportException { - Response res = retrySapTransportCall(endpoint, MediaType.APPLICATION_JSON); + Response res = retrySapTransportCall(endpoint, mediaType); try { return prepareResponseContainer(res); @@ -126,8 +127,19 @@ public SuccessFactorsResponseContainer callSuccessFactorsWithRetry(URL endpoint) */ public Response retrySapTransportCall(URL endpoint, String mediaType) throws IOException { Callable fetchRecords = () -> { - response = transport(endpoint, mediaType); - if (response != null && response.code() >= HttpURLConnection.HTTP_INTERNAL_ERROR) { + try { + LOG.debug("Retrying the call to URL {}.", endpoint); + response = transport(endpoint, mediaType); + if (response != null && response.code() >= HttpURLConnection.HTTP_INTERNAL_ERROR) { + throw new RetryableException(); + } + } catch (ConnectException e) { + LOG.error("Retry Failed with ConnectException for URL {}.", endpoint); + LOG.error(e.toString()); + throw new RetryableException(); + } catch (IOException e) { + LOG.error("Retry Failed with IOException for URL {}.", endpoint); + LOG.error(e.toString()); throw new RetryableException(); } return true; @@ -135,7 +147,7 @@ public Response retrySapTransportCall(URL endpoint, String mediaType) throws IOE Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(RetryableException.class) - .withWaitStrategy(WaitStrategies.exponentialWait(WAIT_TIME, TimeUnit.SECONDS)) + .withWaitStrategy(WaitStrategies.exponentialWait(100, 5 * 60, TimeUnit.SECONDS)) .withStopStrategy(StopStrategies.stopAfterAttempt((int) MAX_NUMBER_OF_RETRY_ATTEMPTS)) .build();