Skip to content

Commit ea6da10

Browse files
author
rathnapandi
committed
Fix issue #473
1 parent 8c3329c commit ea6da10

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

.github/workflows/integration-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
path: ~/cache-docker
3636
key: docker-image-cache-${{ runner.os }}
3737
- if: steps.cache-docker.outputs.cache-hit != 'true'
38-
name: Login to Axway demo docker registry
38+
name: Login to Axway docker registry
3939
uses: docker/login-action@v2
4040
with:
4141
registry: docker.repository.axway.com

modules/apim-adapter/src/main/java/com/axway/apim/adapter/client/apps/APIMgrAppsAdapter.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public APIMgrAppsAdapter(APIManagerAdapter apiManagerAdapter) {
6767
* @throws AppException if applications cannot be retrieved
6868
*/
6969
private void readApplicationsFromAPIManager(ClientAppFilter filter) throws AppException {
70-
if (this.apiManagerResponse.get(filter) != null) return;
70+
if (apiManagerResponse.get(filter) != null) return;
7171
try {
7272
String requestedId = "";
7373
if (filter.getApplicationId() != null) {
7474
if (applicationsCache.containsKey(filter.getApplicationId())) {
75-
this.apiManagerResponse.put(filter, applicationsCache.get(filter.getApplicationId()));
75+
apiManagerResponse.put(filter, applicationsCache.get(filter.getApplicationId()));
7676
return;
7777
}
7878
requestedId = "/" + filter.getApplicationId();
@@ -86,14 +86,14 @@ private void readApplicationsFromAPIManager(ClientAppFilter filter) throws AppEx
8686
int statusCode = httpResponse.getStatusLine().getStatusCode();
8787
if (statusCode == 404) {
8888
// Nothing found - Simulate an empty response
89-
this.apiManagerResponse.put(filter, "[]");
89+
apiManagerResponse.put(filter, "[]");
9090
return;
9191
}
9292
String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
9393
if (response.startsWith("{")) { // Got a single response!
9494
response = "[" + response + "]";
9595
}
96-
this.apiManagerResponse.put(filter, response);
96+
apiManagerResponse.put(filter, response);
9797
if (filter.getApplicationId() != null) {
9898
applicationsCache.put(filter.getApplicationId(), response);
9999
}
@@ -118,8 +118,8 @@ public List<ClientApplication> getApplications(ClientAppFilter filter, boolean l
118118
readApplicationsFromAPIManager(filter);
119119
List<ClientApplication> apps;
120120
try {
121-
if (this.apiManagerResponse.get(filter) == null) return Collections.emptyList();
122-
apps = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference<>() {
121+
if (apiManagerResponse.get(filter) == null) return Collections.emptyList();
122+
apps = mapper.readValue(apiManagerResponse.get(filter), new TypeReference<>() {
123123
});
124124
LOG.debug("Found: {} applications", apps.size());
125125
for (int i = 0; i < apps.size(); i++) {
@@ -136,7 +136,7 @@ public List<ClientApplication> getApplications(ClientAppFilter filter, boolean l
136136
Utils.progressPercentage(i, apps.size(), "Loading details of " + apps.size() + " applications");
137137
}
138138
apps.removeIf(filter::filter);
139-
Utils.addCustomPropertiesForEntity(apps, this.apiManagerResponse.get(filter), filter);
139+
Utils.addCustomPropertiesForEntity(apps, apiManagerResponse.get(filter), filter);
140140
if (logProgress && apps.size() > 5) Console.print("\n");
141141
} catch (Exception e) {
142142
throw new AppException("Can't initialize API-Manager API-Representation.", ErrorCode.API_MANAGER_COMMUNICATION, e);
@@ -152,7 +152,7 @@ public List<ClientApplication> getAppsSubscribedWithAPI(String apiId) throws App
152152
readAppsSubscribedFromAPIManager(apiId);
153153
List<ClientApplication> subscribedApps;
154154
try {
155-
subscribedApps = mapper.readValue(this.subscribedAppAPIManagerResponse.get(apiId), new TypeReference<>() {
155+
subscribedApps = mapper.readValue(subscribedAppAPIManagerResponse.get(apiId), new TypeReference<>() {
156156
});
157157
} catch (IOException e) {
158158
throw new AppException("Error cant load subscribes applications from API-Manager.", ErrorCode.API_MANAGER_COMMUNICATION, e);
@@ -161,7 +161,7 @@ public List<ClientApplication> getAppsSubscribedWithAPI(String apiId) throws App
161161
}
162162

163163
private void readAppsSubscribedFromAPIManager(String apiId) throws AppException {
164-
if (this.subscribedAppAPIManagerResponse.get(apiId) != null) return;
164+
if (subscribedAppAPIManagerResponse.get(apiId) != null) return;
165165
if (applicationsSubscriptionCache.containsKey(apiId)) {
166166
subscribedAppAPIManagerResponse.put(apiId, applicationsSubscriptionCache.get(apiId));
167167
return;
@@ -171,7 +171,12 @@ private void readAppsSubscribedFromAPIManager(String apiId) throws AppException
171171
RestAPICall getRequest = new GETRequest(uri);
172172
LOG.debug("Load subscribed applications for API-ID: {} from API-Manager", apiId);
173173
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) getRequest.execute()) {
174+
int statusCode = httpResponse.getStatusLine().getStatusCode();
174175
String response = EntityUtils.toString(httpResponse.getEntity());
176+
if (statusCode != 200) {
177+
LOG.error("Response from API Manager : {}", response);
178+
throw new AppException("Error from API Manager", ErrorCode.API_MANAGER_COMMUNICATION);
179+
}
175180
subscribedAppAPIManagerResponse.put(apiId, response);
176181
applicationsSubscriptionCache.put(apiId, response);
177182
}

modules/apim-adapter/src/main/java/com/axway/apim/adapter/custom/properties/APIManagerCustomPropertiesAdapter.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,13 @@ public class APIManagerCustomPropertiesAdapter {
2424

2525
private static final Logger LOG = LoggerFactory.getLogger(APIManagerCustomPropertiesAdapter.class);
2626

27-
ObjectMapper mapper = APIManagerAdapter.mapper;
28-
29-
CoreParameters cmd = CoreParameters.getInstance();
30-
3127
public APIManagerCustomPropertiesAdapter() {
3228
// Default constructor
3329
}
3430

35-
String apiManagerResponse;
36-
37-
CustomProperties customProperties;
38-
39-
private void readCustomPropertiesFromAPIManager() throws AppException {
40-
if (apiManagerResponse != null) return;
31+
private String readCustomPropertiesFromAPIManager() throws AppException {
4132
try {
33+
CoreParameters cmd = CoreParameters.getInstance();
4234
URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/config/customproperties").build();
4335
RestAPICall getRequest = new GETRequest(uri);
4436
LOG.debug("Read configured custom properties from API-Manager");
@@ -49,20 +41,18 @@ private void readCustomPropertiesFromAPIManager() throws AppException {
4941
LOG.error("Error loading custom-properties from API-Manager. Response-Code: {} Response Body: {}", statusCode, response);
5042
throw new AppException("Error loading custom-properties from API-Manager. Response-Code: " + statusCode, ErrorCode.API_MANAGER_COMMUNICATION);
5143
}
52-
apiManagerResponse = response;
44+
return response;
5345
}
5446
} catch (Exception e) {
5547
throw new AppException("Can't read configuration from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e);
5648
}
5749
}
5850

5951
public CustomProperties getCustomProperties() throws AppException {
60-
if (customProperties != null) return customProperties;
61-
readCustomPropertiesFromAPIManager();
52+
String apiManagerResponse = readCustomPropertiesFromAPIManager();
6253
try {
63-
CustomProperties props = mapper.readValue(apiManagerResponse, CustomProperties.class);
64-
customProperties = props;
65-
return props;
54+
ObjectMapper mapper = APIManagerAdapter.mapper;
55+
return mapper.readValue(apiManagerResponse, CustomProperties.class);
6656
} catch (IOException e) {
6757
throw new AppException("Error parsing API-Manager custom properties", ErrorCode.API_MANAGER_COMMUNICATION, e);
6858
}

modules/apim-adapter/src/main/resources/log4j2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</Console>
88
</Appenders>
99
<Loggers>
10-
<Logger name="com.axway.apim" level="${env:LOG_LEVEL:-info}"/>
10+
<Logger name="com.axway.apim" level="${env:LOG_LEVEL:-debug}"/>
1111
<Logger name="com.consol.citrus" level="info"/>
1212
<Logger name="org.apache" level="info"/>
1313
<Logger name="org.ehcache" level="error"/>

0 commit comments

Comments
 (0)