diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerQuotaAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerQuotaAdapter.java index ebe53658c..d3bddff2c 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerQuotaAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerQuotaAdapter.java @@ -151,17 +151,12 @@ public void saveQuota(APIQuota quotaConfig, String quotaId) throws AppException int statusCode = httpResponse.getStatusCode(); String response = httpResponse.getResponseBody(); if (statusCode < 200 || statusCode > 299) { - if ((statusCode == 400) && (response.contains("API not found"))) { - LOG.warn("Got unexpected error: 'API not found' while saving quota configuration ... Try again in {} milliseconds. (you may set -retryDelay )", cmd.getRetryDelay()); + if ((statusCode == 400 && response.contains("API not found")) + || (statusCode == 500 && response.contains("Internal server error")) + ) { + LOG.warn("Got unexpected error while saving quota configuration ... Try again in {} milliseconds. (you may set -retryDelay )", cmd.getRetryDelay()); Thread.sleep(cmd.getRetryDelay()); - httpResponse = httpHelper.execute(request, true); - response = httpResponse.getResponseBody(); - statusCode = httpResponse.getStatusCode(); - if (statusCode < 200 || statusCode > 299) { - throw new AppException("Can't update API-Manager Quota-Configuration. Response: '" + response + "'", ErrorCode.API_MANAGER_COMMUNICATION); - } else { - LOG.info("Successfully created API-Access on retry. Received Status-Code: {}", statusCode); - } + retrySaveQuota(request); } else { throw new AppException("Can't update API-Manager Quota-Configuration. Response: '" + response + "'", ErrorCode.API_MANAGER_COMMUNICATION); } @@ -188,6 +183,17 @@ public APIQuota getDefaultQuota(Quota quotaType) throws AppException { return quotaConfig; } + private static void retrySaveQuota(RestAPICall request) throws IOException { + Response httpResponse = httpHelper.execute(request, true); + String response = httpResponse.getResponseBody(); + int statusCode = httpResponse.getStatusCode(); + if (statusCode < 200 || statusCode > 299) { + throw new AppException("Can't update API-Manager Quota-Configuration. Response: '" + response + "'", ErrorCode.API_MANAGER_COMMUNICATION); + } else { + LOG.info("Successfully created API-Access on retry. Received Status-Code: {}", statusCode); + } + } + private static APIQuota filterQuotaForAPI(APIQuota quotaConfig, API api) throws AppException { List apiRestrictions = new ArrayList<>(); try {