diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 408dc1b99..743a3c111 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -3,11 +3,11 @@ name: APIM CLI Integration Tests on: [push] env: - CASSANDRA_DOCKER_IMAGE: cassandra:4.0.13 - APIM_DOCKER_IMAGE: docker.repository.axway.com/apigateway-docker-prod/7.7/gateway:7.7.0.20240530-2-BN0004-ubi9 - CACHE_FILE_APIM: api-manager_7_7_20240530.cache.tar - CACHE_FILE_CASSANDRA: cassandra_4_0_13.cache.tar - FED_FILE: swagger-promote-7.7-20240530.fed + CASSANDRA_DOCKER_IMAGE: cassandra:4.1.6 + APIM_DOCKER_IMAGE: docker.repository.axway.com/apigateway-docker-prod/7.7/gateway:7.7.0.20240830-4-BN0145-ubi9 + CACHE_FILE_APIM: api-manager_7_7_20240830.cache.tar + CACHE_FILE_CASSANDRA: cassandra_4_1_6.cache.tar + FED_FILE: swagger-promote-7.7-20240830.fed LOG_LEVEL: debug jobs: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2af2b0857..0d3eeef78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). + +# [1.14.7] In progress +## Fixed +- NullPointerException: Cannot invoke "com.axway.apim.api.model.APIMethod.getName() (See issue [#512](https://github.com/Axway-API-Management-Plus/apim-cli/issues/512)) +- Enable caching for API Import action (See issue [#500](https://github.com/Axway-API-Management-Plus/apim-cli/issues/500)) + +### Added +- allow APIM cli to connect to API Manager protected by Cloudflare (See issue [#505](https://github.com/Axway-API-Management-Plus/apim-cli/issues/505)) + + - Added new paramater named customHeaders to handle additonal headers. + E.g ./apim.sh api get -n CalculatorService3 -o json -h localhost -u apiadmin -customHeaders abc:xyz +- Support August 2024 APIM Release (See issue [#504](https://github.com/Axway-API-Management-Plus/apim-cli/issues/504)) + # [1.14.6] 2024-10-11 ## Fixed - Importing SOAP API with different endpoints (for import and for runtime calls) (See issue [#501](https://github.com/Axway-API-Management-Plus/apim-cli/issues/501)) diff --git a/README.md b/README.md index 34b4b60bf..4edda3026 100644 --- a/README.md +++ b/README.md @@ -68,19 +68,20 @@ In addition to a number of executed unit-tests, sophisticated integration tests The automated End-2-End test suite contains of __116__ different scenarios, which includes more than __284__ executions of CLI (Import & Export) following each by a validation step. The test suite is executed at Travis CI for the following versions and you may check yourself what is done by clicking on the badge icon: -| Version | Branch | Status | Comment | -|:-------------|:----------------------------------------------------| :---: |:-------------------------------------------------------------------| -| 7.7-20240530 | develop |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.5 | -| 7.7-20240228 | test-with-7.7-20240228 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.4 | -| 7.7-20230130 | test-with-7.7-20231130 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.3 | -| 7.7-20230830 | test-with-7.7-20230830 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.2 | -| 7.7-20230530 | test-with-7.7-20230530 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.0 | -| 7.7-20230228 | test-with-7.7-20230228 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.13.4 | -| 7.7-20221130 | test-with-7.7-20221130 |[![APIM CLI Integration test](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml)| Requires version >=1.13.2, Multi-Org supported from version 1.13.3 | -| 7.7-20220830 | test-with-7.7-20220830 |[![APIM CLI Integration test](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg?branch=test-with-7.7-20220830)](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml)| Requires version >=1.13.0, Multi-Org is not yet supported | -| 7.7-20220530 | test-with-7.7-20220530 | [![Build Status](https://img.shields.io/travis/Axway-API-Management-Plus/apim-cli/test-with-7.7-20211130)](https://app.travis-ci.com/github/Axway-API-Management-Plus/apim-cli/branches)| Requires version >=1.12.0, Multi-Org is not yet supported | -| 7.7-20220228 | test-with-7.7-20220228 | [![Build Status](https://img.shields.io/travis/Axway-API-Management-Plus/apim-cli/test-with-7.7-20220228)](https://app.travis-ci.com/github/Axway-API-Management-Plus/apim-cli/branches)| Requires version >=1.10.1, Multi-Org is not yet supported | -| 7.7-20211130 | test-with-7.7-20211130 | [![Build Status](https://img.shields.io/travis/Axway-API-Management-Plus/apim-cli/test-with-7.7-20211130)](https://app.travis-ci.com/github/Axway-API-Management-Plus/apim-cli/branches)| Requires version >=1.3.11, Multi-Org is not yet supported | +| Version | Branch | Status | Comment | +|:-------------|:-----------------------| :---: |:-------------------------------------------------------------------| +| 7.7-20240830 | develop |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.7 | +| 7.7-20240530 | test-with-7.7-20240530 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.5 | +| 7.7-20240228 | test-with-7.7-20240228 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.4 | +| 7.7-20230130 | test-with-7.7-20231130 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.3 | +| 7.7-20230830 | test-with-7.7-20230830 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.2 | +| 7.7-20230530 | test-with-7.7-20230530 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.14.0 | +| 7.7-20230228 | test-with-7.7-20230228 |![Build Status](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)| Requires version >=1.13.4 | +| 7.7-20221130 | test-with-7.7-20221130 |[![APIM CLI Integration test](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg)](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml)| Requires version >=1.13.2, Multi-Org supported from version 1.13.3 | +| 7.7-20220830 | test-with-7.7-20220830 |[![APIM CLI Integration test](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml/badge.svg?branch=test-with-7.7-20220830)](https://github.com/Axway-API-Management-Plus/apim-cli/actions/workflows/integration-test.yml)| Requires version >=1.13.0, Multi-Org is not yet supported | +| 7.7-20220530 | test-with-7.7-20220530 | [![Build Status](https://img.shields.io/travis/Axway-API-Management-Plus/apim-cli/test-with-7.7-20211130)](https://app.travis-ci.com/github/Axway-API-Management-Plus/apim-cli/branches)| Requires version >=1.12.0, Multi-Org is not yet supported | +| 7.7-20220228 | test-with-7.7-20220228 | [![Build Status](https://img.shields.io/travis/Axway-API-Management-Plus/apim-cli/test-with-7.7-20220228)](https://app.travis-ci.com/github/Axway-API-Management-Plus/apim-cli/branches)| Requires version >=1.10.1, Multi-Org is not yet supported | +| 7.7-20211130 | test-with-7.7-20211130 | [![Build Status](https://img.shields.io/travis/Axway-API-Management-Plus/apim-cli/test-with-7.7-20211130)](https://app.travis-ci.com/github/Axway-API-Management-Plus/apim-cli/branches)| Requires version >=1.3.11, Multi-Org is not yet supported | At least version 7.7-20211130 is required. diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java index 66d84a150..2c280a2a1 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java @@ -582,17 +582,17 @@ public static String getCertInfo(InputStream certificate, String password, CaCer * Helper method to translate a Base64 encoded format * as it's needed by the API-Manager. * - * @param fileFontent the certificate content + * @param fileContent the certificate content * @param filename the name of the certificate file used as a reference in the generated Json object * @param contentType the content type * @return a Json-Object structure as needed by the API-Manager * @throws AppException when the certificate information can't be created */ - public static JsonNode getFileData(byte[] fileFontent, String filename, ContentType contentType) throws AppException { + public JsonNode getFileData(byte[] fileContent, String filename, ContentType contentType) throws AppException { try { URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/filedata/").build(); HttpEntity entity = MultipartEntityBuilder.create() - .addBinaryBody("file", fileFontent, contentType, filename) + .addBinaryBody("file", fileContent, contentType, filename) .build(); POSTRequest postRequest = new POSTRequest(entity, uri); try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) postRequest.execute()) { diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIFilter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIFilter.java index dabc79e0b..2a8cd6398 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIFilter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIFilter.java @@ -44,10 +44,8 @@ public enum FILTER_OP { ne, gt, lt, - ge, le, - like, - gele + like } private String id; @@ -642,7 +640,6 @@ public Builder(APIType type) { * @param loadBackendAPI is search backendEndAPI if set to true */ public Builder(APIType type, boolean loadBackendAPI) { - super(); initType(type); this.apiType = type; this.loadBackendAPI = loadBackendAPI; diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAccessAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAccessAdapter.java index d45516818..4c4161a9f 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAccessAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAccessAdapter.java @@ -39,6 +39,8 @@ public class APIManagerAPIAccessAdapter { + public static final String APIS = "/apis"; + public enum Type { organizations("Organization"), applications("Application"); @@ -79,7 +81,7 @@ private void readAPIAccessFromAPIManager(Type type, String id) throws AppExcepti return; } try { - URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/" + type + "/" + id + "/apis").build(); + URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/" + type + "/" + id + APIS).build(); RestAPICall getRequest = new GETRequest(uri); LOG.debug("Load API-Access with type: {} from API-Manager with ID: {}", type, id); try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) getRequest.execute()) { @@ -110,7 +112,7 @@ public List getAPIAccess(AbstractEntity entity, Type type, boolean in String apiAccessResponse; try { apiAccessResponse = apiManagerResponse.get(type).get(entity.getId()); - List allApiAccess = mapper.readValue(apiAccessResponse, new TypeReference>() { + List allApiAccess = mapper.readValue(apiAccessResponse, new TypeReference<>() { }); if (includeAPIName) { for (APIAccess apiAccess : allApiAccess) { @@ -153,6 +155,13 @@ private void removeFromCache(String id, Type type) { } } + private void removeApplicationFromCache(String id) { + Cache usedCache = caches.get(Type.applications); + if (usedCache != null && usedCache.containsKey(id)) + usedCache.remove(id); + + } + public void saveAPIAccess(List apiAccess, AbstractEntity entity, Type type) throws AppException { List existingAPIAccess = getAPIAccess(entity, type, true); List toBeRemovedAccesses = getMissingAPIAccesses(existingAPIAccess, apiAccess); @@ -194,6 +203,30 @@ public void populateApiId(APIAccess apiAccess) throws AppException { } } + public APIAccess createAPIAccessForApplication(APIAccess apiAccess, String applicationId) throws AppException { + try { + URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/applications/" + applicationId + APIS).build(); + mapper.setSerializationInclusion(Include.NON_NULL); + FilterProvider filter = new SimpleFilterProvider().setDefaultFilter( + SimpleBeanPropertyFilter.serializeAllExcept("apiName", "apiVersion")); + mapper.setFilterProvider(filter); + HttpEntity entity = new StringEntity(mapper.writeValueAsString(apiAccess), ContentType.APPLICATION_JSON); + RestAPICall request = new POSTRequest(entity, uri); + try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) request.execute()) { + int statusCode = httpResponse.getStatusLine().getStatusCode(); + String response = EntityUtils.toString(httpResponse.getEntity()); + if (statusCode != 201) { + LOG.error("Error granting access to application id : {} for API-Proxy : {} using URI: {} Received Status-Code: {} Response: {}", applicationId, apiAccess.getApiId(), uri, statusCode, response); + throw new AppException("Can't grant access to API.", ErrorCode.ERR_GRANTING_ACCESS_TO_API); + } + removeApplicationFromCache(applicationId); + return mapper.readValue(response, APIAccess.class); + } + } catch (Exception e) { + throw new AppException("Can't grant access to API.", ErrorCode.ERR_GRANTING_ACCESS_TO_API, e); + } + } + public void createAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Type type) throws AppException { List existingAPIAccess = getAPIAccess(parentEntity, type, true); if (existingAPIAccess != null && existingAPIAccess.contains(apiAccess)) { @@ -201,7 +234,7 @@ public void createAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Ty return; } try { - URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/" + type + "/" + parentEntity.getId() + "/apis").build(); + URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/" + type + "/" + parentEntity.getId() + APIS).build(); mapper.setSerializationInclusion(Include.NON_NULL); FilterProvider filter = new SimpleFilterProvider().setDefaultFilter( SimpleBeanPropertyFilter.serializeAllExcept("apiName", "apiVersion")); @@ -252,12 +285,12 @@ public void deleteAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Ty if (statusCode < 200 || statusCode > 299) { String errorResponse = EntityUtils.toString(httpResponse.getEntity()); LOG.error("Can't delete API access requests for application. Response-Code: {}. Got response: {}", statusCode, errorResponse); - throw new AppException("Can't delete API access requests for application. Response-Code: " + statusCode, ErrorCode.API_MANAGER_COMMUNICATION); + throw new AppException("Can't delete API access requests for application. Response-Code: " + statusCode, ErrorCode.REVOKE_ACCESS_APPLICATION_ERR); } removeFromCache(parentEntity.getId(), type); } } catch (Exception e) { - throw new AppException("Can't delete API access requests for application.", ErrorCode.CANT_CREATE_API_PROXY, e); + throw new AppException("Can't delete API access requests for application.", ErrorCode.REVOKE_ACCESS_APPLICATION_ERR, e); } } @@ -291,7 +324,7 @@ public List getMissingAPIAccesses(List apiAccess, List getApiAccess(String apiId) throws AppException{ + public List getSubscribedOrganizationsAndApplications(String apiId) throws AppException { try { URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/proxies/" + apiId + "/apiaccess").build(); RestAPICall request = new GETRequest(uri); @@ -302,7 +335,8 @@ public List getApiAccess(String apiId) throws AppEx LOG.error("Can't get API access requests for API. Response-Code: {}. Got response: {}", statusCode, response); throw new AppException("Can't get API access requests for API: " + statusCode, ErrorCode.API_MANAGER_COMMUNICATION); } - return mapper.readValue(response, new TypeReference>(){}); + return mapper.readValue(response, new TypeReference<>() { + }); } } catch (Exception e) { throw new AppException("Can't delete API access requests for application.", ErrorCode.API_MANAGER_COMMUNICATION, e); diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java index 05cd7b57b..eef2f31b7 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java @@ -69,12 +69,6 @@ public class APIManagerAPIAdapter { Map apiManagerResponse = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); private final CoreParameters cmd; - private final List queryStringPassThroughBreakingVersion = Arrays.asList("7.7.20220530", "7.7.20220830", "7.7.20221130", "7.7.20230228", "7.7.20230530", "7.7.20230830", "7.7.20231130", "7.7.20240228", "7.7.20240530"); - - /** - * Maps the provided status to the REST-API endpoint to change the status! - */ - public APIManagerAPIAdapter() { cmd = CoreParameters.getInstance(); @@ -98,7 +92,7 @@ public List getAPIs(APIFilter filter, boolean logProgress) throws AppExcept API api = apis.get(i); translateMethodIds(api, filter.getTranslateMethodMode()); addQuotaConfiguration(api, filter.isIncludeQuotas()); - addClientOrganizations(api, filter.isIncludeClientOrganizations()); + addClientOrganizations(api); addClientApplications(api, filter); addExistingClientAppQuotas(api, filter.isIncludeQuotas()); addOriginalAPIDefinitionFromAPIM(api, filter); @@ -211,7 +205,7 @@ public String getVersion(APIFilter apiFilter) { } private List filterAPIs(APIFilter filter) throws IOException { - List apis = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference>() { + List apis = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference<>() { }); apis.removeIf(filter::filter); @@ -232,7 +226,7 @@ private List filterAPIs(APIFilter filter) throws IOException { * Translates the methodIds of the given api. The operations are loaded from the API-Manager based on the apiId * * @param api in which the methods should be translated - * @param apiId the methods are loaded based on this API-ID (this might be an another referenced API) + * @param apiId the methods are loaded based on this API-ID (this might be a referenced API) * @param mode translation direction * @throws AppException when something goes wrong */ @@ -303,9 +297,7 @@ private void addRemoteHost(API api, boolean includeRemoteHost) throws AppExcepti RemoteHost remoteHost = APIManagerAdapter.getInstance().getRemoteHostsAdapter().getRemoteHost(url.getHost(), url.getPort()); api.setRemotehost(remoteHost); } catch (Exception e) { - if (LOG.isDebugEnabled()) { - LOG.error("Error setting remote host for API based on backendBasePath: " + backendBasePath, e); - } + LOG.error("Error setting remote host for API based on backendBasePath: {}", backendBasePath, e); } } @@ -349,8 +341,8 @@ public void updateAPIImage(API api, Image image) throws AppException { } } - private void translateMethodIds(Map profiles, METHOD_TRANSLATION mode, List apiIds) throws AppException { - Map updatedEntries = new HashMap<>(); + private void translateMethodIds(Map profiles, METHOD_TRANSLATION mode, List apiIds) throws AppException { + Map updatedEntries = new HashMap<>(); if (profiles != null) { Iterator keys = profiles.keySet().iterator(); while (keys.hasNext()) { @@ -365,7 +357,7 @@ private void translateMethodIds(Map profiles, } if (method != null) break; } - ProfileType profileWithType = profiles.get(key); + T profileWithType = profiles.get(key); Profile profile = (Profile) profileWithType; if (profile instanceof OutboundProfile) { if (method != null) { @@ -439,26 +431,19 @@ private void addExistingClientAppQuotas(API api, boolean addQuota) throws AppExc } } - public void addClientOrganizations(API api, boolean addClientOrganizations) throws AppException { - if (!addClientOrganizations || !APIManagerAdapter.getInstance().hasAdminAccount()) return; - List grantedOrgs; - List allOrgs = APIManagerAdapter.getInstance().getOrgAdapter().getAllOrgs(); - grantedOrgs = new ArrayList<>(); - for (Organization org : allOrgs) { - List orgAPIAccess = APIManagerAdapter.getInstance().getAccessAdapter().getAPIAccess(org, APIManagerAPIAccessAdapter.Type.organizations); - for (APIAccess access : orgAPIAccess) { - if (access.getApiId().equals(api.getId())) { - grantedOrgs.add(org); - } - } + public void addClientOrganizations(API api) throws AppException { + List grantedOrgs = new ArrayList<>(); + List apiOrganizationSubscriptions = APIManagerAdapter.getInstance().getAccessAdapter().getSubscribedOrganizationsAndApplications(api.getId()); + for (ApiOrganizationSubscription apiOrganizationSubscription : apiOrganizationSubscriptions) { + grantedOrgs.add(new Organization(apiOrganizationSubscription.getOrganizationName())); } api.setClientOrganizations(grantedOrgs); } public void addClientApplications(API api, APIFilter filter) throws AppException { if (!filter.isIncludeClientApplications()) return; - List apps; - apps = APIManagerAdapter.getInstance().getAppAdapter().getAppsSubscribedWithAPI(api.getId()); + List apps = APIManagerAdapter.getInstance().getAppAdapter().getAppsSubscribedWithAPI(api.getId()); + LOG.debug("Adding client-applications : {}", apps); api.setApplications(apps); } @@ -605,15 +590,8 @@ public API updateAPIProxy(API api) throws AppException { } } - public String[] getSerializeAllExcept() throws AppException { - String[] serializeAllExcept; - // queryStringPassThrough added in inboundProfiles on API manager version 7.7.20220530 - if (queryStringPassThroughBreakingVersion.contains(APIManagerAdapter.getInstance().getApiManagerVersion())) { - serializeAllExcept = new String[]{"apiDefinition", "certFile", "useForInbound", "useForOutbound", "organization", "applications", "image", "clientOrganizations", "applicationQuota", "systemQuota", "backendBasepath", "remoteHost"}; - } else { - serializeAllExcept = new String[]{"queryStringPassThrough", "apiDefinition", "certFile", "useForInbound", "useForOutbound", "organization", "applications", "image", "clientOrganizations", "applicationQuota", "systemQuota", "backendBasepath", "remoteHost"}; - } - return serializeAllExcept; + public String[] getSerializeAllExcept() { + return new String[]{"queryStringPassThrough", "apiDefinition", "certFile", "useForInbound", "useForOutbound", "organization", "applications", "image", "clientOrganizations", "applicationQuota", "systemQuota", "backendBasepath", "remoteHost"}; } public void deleteAPIProxy(API api) throws AppException { diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIMethodAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIMethodAdapter.java index 4c9b300b9..a5e232668 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIMethodAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIMethodAdapter.java @@ -58,7 +58,7 @@ public List getAllMethodsForAPI(String apiId) throws AppException { readMethodsFromAPIManager(apiId); List apiMethods; try { - apiMethods = mapper.readValue(this.apiManagerResponse.get(apiId), new TypeReference>() { + apiMethods = mapper.readValue(this.apiManagerResponse.get(apiId), new TypeReference<>() { }); } catch (IOException e) { throw new AppException(ERROR_CANT_LOAD_API_METHODS_FOR_API + apiId + "' from API-Manager.", ErrorCode.API_MANAGER_COMMUNICATION, e); @@ -69,7 +69,7 @@ public List getAllMethodsForAPI(String apiId) throws AppException { public APIMethod getMethodForName(String apiId, String methodName) throws AppException { List apiMethods = getAllMethodsForAPI(apiId); if (apiMethods.isEmpty()) { - LOG.warn("No operations found for API with id: {}", apiId); + logMessage(apiId); return null; } for (APIMethod method : apiMethods) { @@ -78,16 +78,19 @@ public APIMethod getMethodForName(String apiId, String methodName) throws AppExc return method; } } - LOG.debug("{} - {}",apiId, methodName); throw new AppException("No operation found with name: '" + methodName + "'", ErrorCode.API_OPERATION_NOT_FOUND); } + private void logMessage(String apiId) { + LOG.warn("No operations found for API with id: {}", apiId); + } + public APIMethod getMethodForId(String apiId, String methodId) throws AppException { - if(methodId.equals("*")) + if (methodId.equals("*")) return null; List apiMethods = getAllMethodsForAPI(apiId); if (apiMethods.isEmpty()) { - LOG.warn("No operations found for API with id: {}", apiId); + logMessage(apiId); return null; } for (APIMethod method : apiMethods) { diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerOAuthClientProfilesAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerOAuthClientProfilesAdapter.java index b803e9f70..932896a6f 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerOAuthClientProfilesAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerOAuthClientProfilesAdapter.java @@ -65,7 +65,7 @@ public List getOAuthClientProfiles() throws AppException { readOAuthClientProfilesFromAPIManager(); List clientProfiles; try { - clientProfiles = mapper.readValue(this.apiManagerResponse, new TypeReference>(){}); + clientProfiles = mapper.readValue(this.apiManagerResponse, new TypeReference<>() {}); } catch (IOException e) { throw new AppException("Can't parse OAuth Client profiles returned from API-Manager.", ErrorCode.API_MANAGER_COMMUNICATION, e); } diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerOrganizationAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerOrganizationAdapter.java index 28684f1e4..0e32e3fca 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerOrganizationAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerOrganizationAdapter.java @@ -202,8 +202,7 @@ private void saveImage(Organization org, Organization actualOrg) throws URISynta public List getOrgs(OrgFilter filter) throws AppException { readOrgsFromAPIManager(filter); try { - List allOrgs = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference>() { - }); + List allOrgs = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference<>() {}); allOrgs.removeIf(filter::filter); for (Organization org : allOrgs) { addImage(org, filter.isIncludeImage()); diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerPoliciesAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerPoliciesAdapter.java index b8b3198b7..203655840 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerPoliciesAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerPoliciesAdapter.java @@ -105,8 +105,7 @@ private void initPoliciesType(PolicyType type) throws AppException { readPoliciesFromAPIManager(type); } try { - List policies = APIManagerAdapter.mapper.readValue(apiManagerResponse.get(type), new TypeReference>() { - }); + List policies = APIManagerAdapter.mapper.readValue(apiManagerResponse.get(type), new TypeReference<>() {}); for (Policy policy : policies) { policy.setType(type); } diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerRemoteHostsAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerRemoteHostsAdapter.java index 5c07fac3e..9ec66c0b2 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerRemoteHostsAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerRemoteHostsAdapter.java @@ -68,8 +68,7 @@ private void readRemoteHostsFromAPIManager(RemoteHostFilter filter) throws AppEx public Map getRemoteHosts(RemoteHostFilter filter) throws AppException { readRemoteHostsFromAPIManager(filter); try { - List remoteHostsList = mapper.readValue(apiManagerResponse.get(filter), new TypeReference>() { - }); + List remoteHostsList = mapper.readValue(apiManagerResponse.get(filter), new TypeReference<>() {}); remoteHostsList.removeIf(filter::filter); Map remoteHosts = new HashMap<>(); for (RemoteHost remoteHost : remoteHostsList) { 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 d182aa260..eb4cac60e 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 @@ -119,7 +119,7 @@ public List getApplications(ClientAppFilter filter, boolean l List apps; try { if (this.apiManagerResponse.get(filter) == null) return Collections.emptyList(); - apps = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference>() { + apps = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference<>() { }); LOG.debug("Found: {} applications", apps.size()); for (int i = 0; i < apps.size(); i++) { @@ -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(this.subscribedAppAPIManagerResponse.get(apiId), new TypeReference<>() { }); } catch (IOException e) { throw new AppException("Error cant load subscribes applications from API-Manager.", ErrorCode.API_MANAGER_COMMUNICATION, e); @@ -244,7 +244,7 @@ private void addOauthResources(ClientApplication app, boolean includeOauthResour LOG.error("Error reading application oauth resources. Response-Code: {} Got response: {}", statusCode, response); throw new AppException("Error reading application oauth resources' Response-Code: " + statusCode, ErrorCode.API_MANAGER_COMMUNICATION); } - TypeReference> classType = new TypeReference>() { + TypeReference> classType = new TypeReference<>() { }; List oauthResources = mapper.readValue(response, classType); app.getOauthResources().addAll(oauthResources); @@ -268,7 +268,7 @@ private void addApplicationPermissions(ClientApplication app, boolean includeApp LOG.error("Error reading application permissions. Response-Code: {} Got response: {}", statusCode, response); throw new AppException("Error reading application permissions' Response-Code: " + statusCode, ErrorCode.API_MANAGER_COMMUNICATION); } - TypeReference> classType = new TypeReference>() { + TypeReference> classType = new TypeReference<>() { }; List appPermissions = mapper.readValue(response, classType); for (ApplicationPermission permission : appPermissions) { 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 ce17ffc3a..516764cf2 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 @@ -47,7 +47,7 @@ private void readCustomPropertiesFromAPIManager() throws AppException { int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode > 299) { 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); + throw new AppException("Error loading custom-properties from API-Manager. Response-Code: " + statusCode, ErrorCode.API_MANAGER_COMMUNICATION); } apiManagerResponse = response; } diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/jackson/QuotaRestrictionDeserializer.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/jackson/QuotaRestrictionDeserializer.java index 8132e6f2c..74a19e8eb 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/jackson/QuotaRestrictionDeserializer.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/jackson/QuotaRestrictionDeserializer.java @@ -44,7 +44,6 @@ public QuotaRestrictionDeserializer(DeserializeMode deserializeMode) { } public QuotaRestrictionDeserializer(DeserializeMode deserializeMode, boolean addRestrictedAPI) { - super(); this.deserializeMode = deserializeMode; this.addRestrictedAPI = addRestrictedAPI; try { diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/user/APIManagerUserAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/user/APIManagerUserAdapter.java index d1db60cb8..0a2a06d8f 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/user/APIManagerUserAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/user/APIManagerUserAdapter.java @@ -98,7 +98,7 @@ private void readUsersFromAPIManager(UserFilter filter) throws AppException { public List getUsers(UserFilter filter) throws AppException { readUsersFromAPIManager(filter); try { - List allUsers = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference>() { + List allUsers = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference<>() { }); List foundUsers = new ArrayList<>(); for (User user : allUsers) { @@ -232,11 +232,11 @@ public void changePassword(String newPassword, User actualUser) throws AppExcept if (statusCode != 204) { LOG.error("Error changing password of user. Response-Code: {}", statusCode); Utils.logPayload(LOG, httpResponse); - throw new AppException("Error changing password of user. Response-Code: " + statusCode, ErrorCode.ERROR_CHANGEPASSWORD); + throw new AppException("Error changing password of user. Response-Code: " + statusCode, ErrorCode.ERROR_CHANGE_PASSWORD); } } } catch (Exception e) { - throw new AppException("Error changing password of user.", ErrorCode.ERROR_CHANGEPASSWORD, e); + throw new AppException("Error changing password of user.", ErrorCode.ERROR_CHANGE_PASSWORD, e); } } diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/APIQuota.java b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/APIQuota.java index ddef14913..f1dcca0f6 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/APIQuota.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/APIQuota.java @@ -17,7 +17,7 @@ public class APIQuota { String description; - Boolean system; + boolean system; List restrictions; @@ -61,11 +61,11 @@ public void setId(String id) { this.id = id; } - public Boolean getSystem() { + public boolean getSystem() { return system; } - public void setSystem(Boolean system) { + public void setSystem(boolean system) { this.system = system; } diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/CustomProperties.java b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/CustomProperties.java index 4697d25c8..e2777891d 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/CustomProperties.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/CustomProperties.java @@ -49,7 +49,7 @@ public enum Type { organization("Organization"), application("Application"); - public String niceName; + public final String niceName; Type(String niceName) { this.niceName = niceName; diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/CustomProperty.java b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/CustomProperty.java index 1ae6f9d52..e9345566a 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/api/model/CustomProperty.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/api/model/CustomProperty.java @@ -3,33 +3,33 @@ import java.util.List; public class CustomProperty { - + private String label; - + private String type; - - private Boolean disabled; - - private Boolean required; - + + private boolean disabled; + + private boolean required; + private String help; - + private List