From ea6da10a65cbfad7b592e0f6ab326bcc2feca827 Mon Sep 17 00:00:00 2001 From: rathnapandi Date: Thu, 21 Nov 2024 11:15:23 -0700 Subject: [PATCH] Fix issue #473 --- .github/workflows/integration-test.yml | 2 +- .../client/apps/APIMgrAppsAdapter.java | 23 +++++++++++-------- .../APIManagerCustomPropertiesAdapter.java | 22 +++++------------- .../src/main/resources/log4j2.xml | 2 +- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 743a3c111..7a0306645 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -35,7 +35,7 @@ jobs: path: ~/cache-docker key: docker-image-cache-${{ runner.os }} - if: steps.cache-docker.outputs.cache-hit != 'true' - name: Login to Axway demo docker registry + name: Login to Axway docker registry uses: docker/login-action@v2 with: registry: docker.repository.axway.com diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/client/apps/APIMgrAppsAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/client/apps/APIMgrAppsAdapter.java index eb4cac60e..da9564c6e 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/client/apps/APIMgrAppsAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/client/apps/APIMgrAppsAdapter.java @@ -67,12 +67,12 @@ public APIMgrAppsAdapter(APIManagerAdapter apiManagerAdapter) { * @throws AppException if applications cannot be retrieved */ private void readApplicationsFromAPIManager(ClientAppFilter filter) throws AppException { - if (this.apiManagerResponse.get(filter) != null) return; + if (apiManagerResponse.get(filter) != null) return; try { String requestedId = ""; if (filter.getApplicationId() != null) { if (applicationsCache.containsKey(filter.getApplicationId())) { - this.apiManagerResponse.put(filter, applicationsCache.get(filter.getApplicationId())); + apiManagerResponse.put(filter, applicationsCache.get(filter.getApplicationId())); return; } requestedId = "/" + filter.getApplicationId(); @@ -86,14 +86,14 @@ private void readApplicationsFromAPIManager(ClientAppFilter filter) throws AppEx int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode == 404) { // Nothing found - Simulate an empty response - this.apiManagerResponse.put(filter, "[]"); + apiManagerResponse.put(filter, "[]"); return; } String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); if (response.startsWith("{")) { // Got a single response! response = "[" + response + "]"; } - this.apiManagerResponse.put(filter, response); + apiManagerResponse.put(filter, response); if (filter.getApplicationId() != null) { applicationsCache.put(filter.getApplicationId(), response); } @@ -118,8 +118,8 @@ public List getApplications(ClientAppFilter filter, boolean l readApplicationsFromAPIManager(filter); List apps; try { - if (this.apiManagerResponse.get(filter) == null) return Collections.emptyList(); - apps = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference<>() { + if (apiManagerResponse.get(filter) == null) return Collections.emptyList(); + apps = mapper.readValue(apiManagerResponse.get(filter), new TypeReference<>() { }); LOG.debug("Found: {} applications", apps.size()); for (int i = 0; i < apps.size(); i++) { @@ -136,7 +136,7 @@ public List getApplications(ClientAppFilter filter, boolean l Utils.progressPercentage(i, apps.size(), "Loading details of " + apps.size() + " applications"); } apps.removeIf(filter::filter); - Utils.addCustomPropertiesForEntity(apps, this.apiManagerResponse.get(filter), filter); + Utils.addCustomPropertiesForEntity(apps, apiManagerResponse.get(filter), filter); if (logProgress && apps.size() > 5) Console.print("\n"); } catch (Exception e) { throw new AppException("Can't initialize API-Manager API-Representation.", ErrorCode.API_MANAGER_COMMUNICATION, e); @@ -152,7 +152,7 @@ public List getAppsSubscribedWithAPI(String apiId) throws App readAppsSubscribedFromAPIManager(apiId); List subscribedApps; try { - subscribedApps = mapper.readValue(this.subscribedAppAPIManagerResponse.get(apiId), new TypeReference<>() { + subscribedApps = mapper.readValue(subscribedAppAPIManagerResponse.get(apiId), new TypeReference<>() { }); } catch (IOException e) { throw new AppException("Error cant load subscribes applications from API-Manager.", ErrorCode.API_MANAGER_COMMUNICATION, e); @@ -161,7 +161,7 @@ public List getAppsSubscribedWithAPI(String apiId) throws App } private void readAppsSubscribedFromAPIManager(String apiId) throws AppException { - if (this.subscribedAppAPIManagerResponse.get(apiId) != null) return; + if (subscribedAppAPIManagerResponse.get(apiId) != null) return; if (applicationsSubscriptionCache.containsKey(apiId)) { subscribedAppAPIManagerResponse.put(apiId, applicationsSubscriptionCache.get(apiId)); return; @@ -171,7 +171,12 @@ private void readAppsSubscribedFromAPIManager(String apiId) throws AppException RestAPICall getRequest = new GETRequest(uri); LOG.debug("Load subscribed applications for API-ID: {} from API-Manager", apiId); try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) getRequest.execute()) { + int statusCode = httpResponse.getStatusLine().getStatusCode(); String response = EntityUtils.toString(httpResponse.getEntity()); + if (statusCode != 200) { + LOG.error("Response from API Manager : {}", response); + throw new AppException("Error from API Manager", ErrorCode.API_MANAGER_COMMUNICATION); + } subscribedAppAPIManagerResponse.put(apiId, response); applicationsSubscriptionCache.put(apiId, response); } diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/custom/properties/APIManagerCustomPropertiesAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/custom/properties/APIManagerCustomPropertiesAdapter.java index 516764cf2..4a6b935b0 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/custom/properties/APIManagerCustomPropertiesAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/custom/properties/APIManagerCustomPropertiesAdapter.java @@ -24,21 +24,13 @@ public class APIManagerCustomPropertiesAdapter { private static final Logger LOG = LoggerFactory.getLogger(APIManagerCustomPropertiesAdapter.class); - ObjectMapper mapper = APIManagerAdapter.mapper; - - CoreParameters cmd = CoreParameters.getInstance(); - public APIManagerCustomPropertiesAdapter() { // Default constructor } - String apiManagerResponse; - - CustomProperties customProperties; - - private void readCustomPropertiesFromAPIManager() throws AppException { - if (apiManagerResponse != null) return; + private String readCustomPropertiesFromAPIManager() throws AppException { try { + CoreParameters cmd = CoreParameters.getInstance(); URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/config/customproperties").build(); RestAPICall getRequest = new GETRequest(uri); LOG.debug("Read configured custom properties from API-Manager"); @@ -49,7 +41,7 @@ private void readCustomPropertiesFromAPIManager() throws AppException { LOG.error("Error loading custom-properties from API-Manager. Response-Code: {} Response Body: {}", statusCode, response); throw new AppException("Error loading custom-properties from API-Manager. Response-Code: " + statusCode, ErrorCode.API_MANAGER_COMMUNICATION); } - apiManagerResponse = response; + return response; } } catch (Exception e) { throw new AppException("Can't read configuration from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e); @@ -57,12 +49,10 @@ private void readCustomPropertiesFromAPIManager() throws AppException { } public CustomProperties getCustomProperties() throws AppException { - if (customProperties != null) return customProperties; - readCustomPropertiesFromAPIManager(); + String apiManagerResponse = readCustomPropertiesFromAPIManager(); try { - CustomProperties props = mapper.readValue(apiManagerResponse, CustomProperties.class); - customProperties = props; - return props; + ObjectMapper mapper = APIManagerAdapter.mapper; + return mapper.readValue(apiManagerResponse, CustomProperties.class); } catch (IOException e) { throw new AppException("Error parsing API-Manager custom properties", ErrorCode.API_MANAGER_COMMUNICATION, e); } diff --git a/modules/apim-adapter/src/main/resources/log4j2.xml b/modules/apim-adapter/src/main/resources/log4j2.xml index b45c39b4a..3ee36a684 100644 --- a/modules/apim-adapter/src/main/resources/log4j2.xml +++ b/modules/apim-adapter/src/main/resources/log4j2.xml @@ -7,7 +7,7 @@ - +