Skip to content

Commit

Permalink
Fix issue #473
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Nov 21, 2024
1 parent 8c3329c commit ea6da10
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand All @@ -118,8 +118,8 @@ public List<ClientApplication> getApplications(ClientAppFilter filter, boolean l
readApplicationsFromAPIManager(filter);
List<ClientApplication> 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++) {
Expand All @@ -136,7 +136,7 @@ public List<ClientApplication> 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);
Expand All @@ -152,7 +152,7 @@ public List<ClientApplication> getAppsSubscribedWithAPI(String apiId) throws App
readAppsSubscribedFromAPIManager(apiId);
List<ClientApplication> 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);
Expand All @@ -161,7 +161,7 @@ public List<ClientApplication> 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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -49,20 +41,18 @@ 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);
}
}

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);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/apim-adapter/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</Console>
</Appenders>
<Loggers>
<Logger name="com.axway.apim" level="${env:LOG_LEVEL:-info}"/>
<Logger name="com.axway.apim" level="${env:LOG_LEVEL:-debug}"/>
<Logger name="com.consol.citrus" level="info"/>
<Logger name="org.apache" level="info"/>
<Logger name="org.ehcache" level="error"/>
Expand Down

0 comments on commit ea6da10

Please sign in to comment.