Skip to content

Commit 307db51

Browse files
author
rathnapandi
committed
- Fix issue #538
1 parent 57595d3 commit 307db51

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAccessAdapter.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
public class APIManagerAPIAccessAdapter {
4141

4242
public static final String APIS = "/apis";
43+
public static final String ERROR = "Unexpected response while creating/updating API Access: {} Response-Code: {} Response Body: {} Ignoring this error.";
44+
public static final String RESOURCE_ALREADY_EXISTS = "resource already exists";
4345

4446
public enum Type {
4547
organizations("Organization"),
@@ -216,8 +218,13 @@ public APIAccess createAPIAccessForApplication(APIAccess apiAccess, String appli
216218
int statusCode = httpResponse.getStatusLine().getStatusCode();
217219
String response = EntityUtils.toString(httpResponse.getEntity());
218220
if (statusCode != 201) {
219-
LOG.error("Error granting access to application id : {} for API-Proxy : {} using URI: {} Received Status-Code: {} Response: {}", applicationId, apiAccess.getApiId(), uri, statusCode, response);
220-
throw new AppException("Can't grant access to API.", ErrorCode.ERR_GRANTING_ACCESS_TO_API);
221+
if (statusCode == 409 && response.contains(RESOURCE_ALREADY_EXISTS)) {
222+
LOG.info(ERROR, apiAccess, statusCode, response);
223+
return apiAccess;
224+
}else {
225+
LOG.error("Error granting access to application id : {} for API-Proxy : {} using URI: {} Received Status-Code: {} Response: {}", applicationId, apiAccess.getApiId(), uri, statusCode, response);
226+
throw new AppException("Can't grant access to API.", ErrorCode.ERR_GRANTING_ACCESS_TO_API);
227+
}
221228
}
222229
removeApplicationFromCache(applicationId);
223230
return mapper.readValue(response, APIAccess.class);
@@ -254,8 +261,8 @@ public void createAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Ty
254261
statusCode = httpResponse.getStatusCode();
255262
if (statusCode < 200 || statusCode > 299) {
256263
//even in second attempt we have to ignore 409 error (resource already exists)
257-
if (statusCode == 409 && response.contains("resource already exists")) {
258-
LOG.info("Unexpected response while creating/updating API Access: {} Response-Code: {} Response Body: {} Ignoring this error.", apiAccess, statusCode, response);
264+
if (statusCode == 409 && response.contains(RESOURCE_ALREADY_EXISTS)) {
265+
LOG.info(ERROR, apiAccess, statusCode, response);
259266
return;
260267
} else {
261268
LOG.error("Error creating/updating API Access: {} Response-Code: {} Response Body: {}", apiAccess, statusCode, response);
@@ -264,8 +271,8 @@ public void createAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Ty
264271
} else {
265272
LOG.info("Successfully created API-Access on retry. Received Status-Code: {}", statusCode);
266273
}
267-
} else if (statusCode == 409 && response.contains("resource already exists")) {
268-
LOG.info("Unexpected response while creating/updating API Access: {} Response-Code: {} Response Body: {} Ignoring this error.", apiAccess, statusCode, response);
274+
} else if (statusCode == 409 && response.contains(RESOURCE_ALREADY_EXISTS)) {
275+
LOG.info(ERROR, apiAccess, statusCode, response);
269276
return;
270277
} else {
271278
LOG.error("Error creating/updating API Access: {} Response-Code: {} Response Body: {}", apiAccess, statusCode, response);

0 commit comments

Comments
 (0)