From 3606dd6ba61a4ae9e1674d3d9e0f884a54a7f52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Sala=C4=8D?= Date: Thu, 29 Aug 2024 14:54:43 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20stacktrace=20on=20unreachable=20swagger?= =?UTF-8?q?=20and=20remove=20handling=20for=20depreca=E2=80=A6=20(#3699)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: stacktrace on unreachable swagger and remove deprecated z/OSMF swagger workaround Signed-off-by: Richard Salač Co-authored-by: Pablo Carle --- .../status/APIDocRetrievalService.java | 57 +++----- .../resources/apicatalog-log-messages.yml | 7 + .../status/LocalApiDocServiceTest.java | 129 +++++++----------- .../product/logging/ApimlLogInjector.java | 4 +- 4 files changed, 75 insertions(+), 122 deletions(-) diff --git a/api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/services/status/APIDocRetrievalService.java b/api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/services/status/APIDocRetrievalService.java index 19efc59d8c..b5c4729ab5 100644 --- a/api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/services/status/APIDocRetrievalService.java +++ b/api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/services/status/APIDocRetrievalService.java @@ -14,12 +14,10 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; -import org.apache.hc.core5.http.HttpEntity; -import org.apache.hc.core5.http.HttpStatus; -import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.*; import org.apache.hc.core5.http.io.entity.EntityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -35,9 +33,11 @@ import org.zowe.apiml.apicatalog.swagger.SubstituteSwaggerGenerator; import org.zowe.apiml.config.ApiInfo; import org.zowe.apiml.eurekaservice.client.util.EurekaMetadataParser; +import org.zowe.apiml.message.log.ApimlLogger; import org.zowe.apiml.product.gateway.GatewayClient; import org.zowe.apiml.product.instance.ServiceAddress; import org.zowe.apiml.product.instance.InstanceInitializationException; +import org.zowe.apiml.product.logging.annotations.InjectApimlLogger; import org.zowe.apiml.product.routing.RoutedService; import org.zowe.apiml.product.routing.RoutedServices; @@ -70,6 +70,9 @@ public class APIDocRetrievalService { private final EurekaMetadataParser metadataParser = new EurekaMetadataParser(); private final SubstituteSwaggerGenerator swaggerGenerator = new SubstituteSwaggerGenerator(); + @InjectApimlLogger + private ApimlLogger apimlLogger = ApimlLogger.empty(); + /** * Retrieves the available API versions for a registered service. * Takes the versions available in each 'apiml.service.apiInfo' element. @@ -175,26 +178,12 @@ private ApiDocInfo buildApiDocInfo(String serviceId, ApiInfo apiInfo, InstanceIn return getApiDocInfoBySubstituteSwagger(instanceInfo, routes, apiInfo); } - // The Swagger generated by zOSMF is invalid because it has null in enum values for boolean. - // Remove once we know that zOSMF APARs for zOS2.2 and 2.3 is prerequisite - if (serviceId.equals("zosmf") || serviceId.equals("ibmzosmf")) { - try { - String apiDocContent = getApiDocContentByUrl(serviceId, apiDocUrl); - if (apiDocContent != null) { - apiDocContent = apiDocContent.replace("null, null", "true, false"); - } - return new ApiDocInfo(apiInfo, apiDocContent, routes); - } catch (Exception e) { - log.error("Error retrieving api doc for '{}'", serviceId, e); - return getApiDocInfoBySubstituteSwagger(instanceInfo, routes, apiInfo); - } - } - String apiDocContent = ""; try { apiDocContent = getApiDocContentByUrl(serviceId, apiDocUrl); - } catch (IOException | ParseException e) { //TODO: Is it handled correctly? - log.error("Error retrieving api doc for '{}'", serviceId, e); + } catch (IOException e) { + apimlLogger.log("org.zowe.apiml.apicatalog.apiDocHostCommunication", serviceId, e.getMessage()); + log.debug("Error retrieving api doc for '{}'", serviceId, e); } return new ApiDocInfo(apiInfo, apiDocContent, routes); } @@ -310,7 +299,6 @@ private String getApiDocUrl(ApiInfo apiInfo, InstanceInfo instanceInfo, RoutedSe return apiDocUrl; } - /** * Get ApiDoc content by Url * @@ -319,26 +307,21 @@ private String getApiDocUrl(ApiInfo apiInfo, InstanceInfo instanceInfo, RoutedSe * @return the information about ApiDoc content as application/json * @throws ApiDocNotFoundException if the response is error */ - private String getApiDocContentByUrl(@NonNull String serviceId, String apiDocUrl) throws IOException, ParseException { + private String getApiDocContentByUrl(@NonNull String serviceId, String apiDocUrl) throws IOException { HttpGet httpGet = new HttpGet(apiDocUrl); httpGet.setHeader(org.apache.http.HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE); - String responseBody = null; - try { - CloseableHttpResponse response = secureHttpClientWithoutKeystore.execute(httpGet); - final HttpEntity responseEntity = response.getEntity(); - if (responseEntity != null) { - responseBody = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8); + var responseCodeBodyPair = secureHttpClientWithoutKeystore.execute(httpGet, response -> { + var responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); + return Pair.of(response.getCode(), responseBody); } - if (response.getCode() != HttpStatus.SC_OK) { - throw new ApiDocNotFoundException("No API Documentation was retrieved due to " + serviceId + - " server error: '" + responseBody + "'."); - } - } catch (Exception e) { - log.error("Error retrieving api doc by url for {} at {}", serviceId, apiDocUrl, e); - throw e; + ); + + if (responseCodeBodyPair.getLeft() != HttpStatus.SC_OK) { + throw new ApiDocNotFoundException("No API Documentation was retrieved due to " + serviceId + + " server error: '" + responseCodeBodyPair.getRight() + "'."); } - return responseBody; + return responseCodeBodyPair.getRight(); } /** diff --git a/api-catalog-services/src/main/resources/apicatalog-log-messages.yml b/api-catalog-services/src/main/resources/apicatalog-log-messages.yml index c830720b45..dd84f811d0 100644 --- a/api-catalog-services/src/main/resources/apicatalog-log-messages.yml +++ b/api-catalog-services/src/main/resources/apicatalog-log-messages.yml @@ -39,6 +39,13 @@ messages: reason: "The status of one or more containers could not be retrieved." action: "Check the status of the message for more information and the health of the Discovery Service." + - key: org.zowe.apiml.apicatalog.apiDocHostCommunication + number: ZWEAC105 + type: WARNING + text: "API Documentation not retrieved for service '%s' due to communication error, %s" + reason: "Unable to fetch API documentation." + action: "Make sure the service documentation url or server transport encoding is configured correctly." + # HTTP, Protocol messages # 400-499\ # TLS, Certificate messages diff --git a/api-catalog-services/src/test/java/org/zowe/apiml/apicatalog/services/status/LocalApiDocServiceTest.java b/api-catalog-services/src/test/java/org/zowe/apiml/apicatalog/services/status/LocalApiDocServiceTest.java index 74be34678e..79ab45d2a9 100644 --- a/api-catalog-services/src/test/java/org/zowe/apiml/apicatalog/services/status/LocalApiDocServiceTest.java +++ b/api-catalog-services/src/test/java/org/zowe/apiml/apicatalog/services/status/LocalApiDocServiceTest.java @@ -11,11 +11,10 @@ package org.zowe.apiml.apicatalog.services.status; import com.netflix.appinfo.InstanceInfo; -import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.tuple.Pair; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.HttpStatus; -import org.apache.hc.core5.http.io.entity.BasicHttpEntity; +import org.apache.hc.core5.http.io.HttpClientResponseHandler; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -24,35 +23,30 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; +import org.springframework.test.util.ReflectionTestUtils; import org.zowe.apiml.apicatalog.instance.InstanceRetrievalService; import org.zowe.apiml.apicatalog.services.cached.model.ApiDocInfo; import org.zowe.apiml.apicatalog.services.status.model.ApiDocNotFoundException; import org.zowe.apiml.apicatalog.services.status.model.ApiVersionNotFoundException; +import org.zowe.apiml.message.log.ApimlLogger; import org.zowe.apiml.product.gateway.GatewayClient; import org.zowe.apiml.product.instance.ServiceAddress; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.apache.hc.core5.http.ContentType.APPLICATION_JSON; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.zowe.apiml.constants.EurekaMetadataDefinition.*; @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) class LocalApiDocServiceTest { private static final String SERVICE_ID = "service"; - private static final String ZOSMF_ID = "ibmzosmf"; private static final String SERVICE_HOST = "service"; private static final int SERVICE_PORT = 8080; private static final String SERVICE_VERSION = "1.0.0"; @@ -67,37 +61,36 @@ class LocalApiDocServiceTest { @Mock private CloseableHttpClient httpClient; - private CloseableHttpResponse response; @Mock private InstanceRetrievalService instanceRetrievalService; private APIDocRetrievalService apiDocRetrievalService; - @BeforeEach - void setup() throws IOException { - response = mock(CloseableHttpResponse.class); - when(response.getCode()).thenReturn(HttpStatus.SC_OK); - when(httpClient.execute(any())).thenReturn(response); + @Mock + private ApimlLogger apimlLogger; + @BeforeEach + void setup() { GatewayClient gatewayClient = new GatewayClient(getProperties()); apiDocRetrievalService = new APIDocRetrievalService( httpClient, instanceRetrievalService, gatewayClient); + + ReflectionTestUtils.setField(apiDocRetrievalService, "apimlLogger", apimlLogger); } @Nested class WhenGetApiDoc { @Test - void givenValidApiInfo_thenReturnApiDoc() { + void givenValidApiInfo_thenReturnApiDoc() throws IOException { String responseBody = "api-doc body"; when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(getStandardMetadata(), true)); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_OK, responseBody)); ApiDocInfo actualResponse = apiDocRetrievalService.retrieveApiDoc(SERVICE_ID, SERVICE_VERSION_V); @@ -122,36 +115,35 @@ void givenNoApiDocFoundForService() { } @Test - void givenServerErrorWhenRequestingSwaggerUrl() { + void givenServerErrorWhenRequestingSwaggerUrl() throws IOException { String responseBody = "Server not found"; when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(getStandardMetadata(), true)); - when(response.getCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_INTERNAL_SERVER_ERROR, responseBody)); Exception exception = assertThrows(ApiDocNotFoundException.class, () -> apiDocRetrievalService.retrieveApiDoc(SERVICE_ID, SERVICE_VERSION_V)); assertEquals("No API Documentation was retrieved due to " + SERVICE_ID + " server error: '" + responseBody + "'.", exception.getMessage()); } @Test - void givenNoInstanceMetadata() { + void givenNoInstanceMetadata() throws IOException { String responseBody = "api-doc body"; when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(new HashMap<>(), true)); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_OK, responseBody)); Exception exception = assertThrows(ApiDocNotFoundException.class, () -> apiDocRetrievalService.retrieveApiDoc(SERVICE_ID, SERVICE_VERSION_V)); assertEquals("No API Documentation defined for service " + SERVICE_ID + ".", exception.getMessage()); } + } + @Test - void givenNoSwaggerUrl_thenReturnSubstituteApiDoc() { + void givenNoSwaggerUrl_thenReturnSubstituteApiDoc() throws IOException { String generatedResponseBody = "{\n" + " \"swagger\": \"2.0\",\n" + " \"info\": {\n" + @@ -186,8 +178,7 @@ void givenNoSwaggerUrl_thenReturnSubstituteApiDoc() { when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(getMetadataWithoutSwaggerUrl(), true)); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_OK, responseBody)); ApiDocInfo actualResponse = apiDocRetrievalService.retrieveApiDoc(SERVICE_ID, SERVICE_VERSION_V); @@ -204,14 +195,13 @@ void givenNoSwaggerUrl_thenReturnSubstituteApiDoc() { } @Test - void givenApiDocUrlInRouting_thenCreateApiDocUrlFromRoutingAndReturnApiDoc() { + void givenApiDocUrlInRouting_thenCreateApiDocUrlFromRoutingAndReturnApiDoc() throws IOException { String responseBody = "api-doc body"; when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(getMetadataWithoutApiInfo(), true)); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_OK, responseBody)); ApiDocInfo actualResponse = apiDocRetrievalService.retrieveApiDoc(SERVICE_ID, SERVICE_VERSION_V); @@ -222,14 +212,13 @@ void givenApiDocUrlInRouting_thenCreateApiDocUrlFromRoutingAndReturnApiDoc() { } @Test - void shouldCreateApiDocUrlFromRoutingAndUseHttp() { + void shouldCreateApiDocUrlFromRoutingAndUseHttp() throws IOException { String responseBody = "api-doc body"; when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(getMetadataWithoutApiInfo(), false)); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_OK, responseBody)); ApiDocInfo actualResponse = apiDocRetrievalService.retrieveApiDoc(SERVICE_ID, SERVICE_VERSION_V); @@ -239,61 +228,38 @@ void shouldCreateApiDocUrlFromRoutingAndUseHttp() { assertEquals(responseBody, actualResponse.getApiDocContent()); } - @Nested - class GivenZosmfId { - @Test - void thenReturnApiDoc() { - String responseBody = "api-doc [ null, null ] body"; - String expectedResponseBody = "api-doc [ true, false ] body"; - - when(instanceRetrievalService.getInstanceInfo(ZOSMF_ID)) - .thenReturn(getStandardInstance(getStandardMetadata(), true)); - - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); - - ApiDocInfo actualResponse = apiDocRetrievalService.retrieveApiDoc(ZOSMF_ID, SERVICE_VERSION_V); - - assertEquals(API_ID, actualResponse.getApiInfo().getApiId()); - assertEquals(GATEWAY_URL, actualResponse.getApiInfo().getGatewayUrl()); - assertEquals(SERVICE_VERSION, actualResponse.getApiInfo().getVersion()); - assertEquals(SWAGGER_URL, actualResponse.getApiInfo().getSwaggerUrl()); - - assertNotNull(actualResponse); - assertNotNull(actualResponse.getApiDocContent()); - assertEquals(expectedResponseBody, actualResponse.getApiDocContent()); + @Test + void givenServerCommunicationErrorWhenRequestingSwaggerUrl_thenLogCustomError() throws IOException { + when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) + .thenReturn(getStandardInstance(getStandardMetadata(), true)); - assertEquals("[api -> api=RoutedService(subServiceId=api-v1, gatewayUrl=api, serviceUrl=/)]", actualResponse.getRoutes().toString()); - } + var exception = new IOException("Unable to reach the host"); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenThrow(exception); - @Test - void whenIncorrectResponseFromServer_thenReturnDefaultDoc() { - String responseBody = "Server not found"; + ApiDocInfo actualResponse = apiDocRetrievalService.retrieveDefaultApiDoc(SERVICE_ID); - when(instanceRetrievalService.getInstanceInfo(ZOSMF_ID)) - .thenReturn(getStandardInstance(getStandardMetadata(), true)); + assertEquals(API_ID, actualResponse.getApiInfo().getApiId()); + assertEquals(GATEWAY_URL, actualResponse.getApiInfo().getGatewayUrl()); + assertEquals(SERVICE_VERSION, actualResponse.getApiInfo().getVersion()); + assertEquals(SWAGGER_URL, actualResponse.getApiInfo().getSwaggerUrl()); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + assertEquals("", actualResponse.getApiDocContent()); - ApiDocInfo result = apiDocRetrievalService.retrieveApiDoc(ZOSMF_ID, SERVICE_VERSION_V); - assertThat(result.getApiDocContent(), is(notNullValue())); - } + verify(apimlLogger, times(1)).log("org.zowe.apiml.apicatalog.apiDocHostCommunication", SERVICE_ID, exception.getMessage()); } } @Nested class WhenGetDefaultApiDoc { @Test - void givenDefaultApiDoc_thenReturnIt() { + void givenDefaultApiDoc_thenReturnIt() throws IOException { String responseBody = "api-doc body"; Map metadata = getMetadataWithMultipleApiInfo(); when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(metadata, true)); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_OK, responseBody)); ApiDocInfo actualResponse = apiDocRetrievalService.retrieveDefaultApiDoc(SERVICE_ID); @@ -310,7 +276,7 @@ void givenDefaultApiDoc_thenReturnIt() { } @Test - void givenNoDefaultApiDoc_thenReturnHighestVersion() { + void givenNoDefaultApiDoc_thenReturnHighestVersion() throws IOException { String responseBody = "api-doc body"; Map metadata = getMetadataWithMultipleApiInfo(); metadata.remove(API_INFO + ".1." + API_INFO_IS_DEFAULT); // unset default API, so higher version becomes default @@ -318,8 +284,7 @@ void givenNoDefaultApiDoc_thenReturnHighestVersion() { when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(metadata, true)); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_OK, responseBody)); ApiDocInfo actualResponse = apiDocRetrievalService.retrieveDefaultApiDoc(SERVICE_ID); @@ -336,14 +301,13 @@ void givenNoDefaultApiDoc_thenReturnHighestVersion() { } @Test - void givenNoDefaultApiDocAndDifferentVersionFormat_thenReturnHighestVersion() { + void givenNoDefaultApiDocAndDifferentVersionFormat_thenReturnHighestVersion() throws IOException { String responseBody = "api-doc body"; when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(getMetadataWithMultipleApiInfoWithDifferentVersionFormat(), true)); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_OK, responseBody)); ApiDocInfo actualResponse = apiDocRetrievalService.retrieveDefaultApiDoc(SERVICE_ID); @@ -360,14 +324,13 @@ void givenNoDefaultApiDocAndDifferentVersionFormat_thenReturnHighestVersion() { } @Test - void givenNoApiDocs_thenReturnNull() { + void givenNoApiDocs_thenReturnNull() throws IOException { String responseBody = "api-doc body"; when(instanceRetrievalService.getInstanceInfo(SERVICE_ID)) .thenReturn(getStandardInstance(getMetadataWithoutApiInfo(), true)); - BasicHttpEntity responseEntity = new BasicHttpEntity(IOUtils.toInputStream(responseBody, StandardCharsets.UTF_8), APPLICATION_JSON); - when(response.getEntity()).thenReturn(responseEntity); + when(httpClient.execute(any(), any(HttpClientResponseHandler.class))).thenReturn(Pair.of(HttpStatus.SC_OK, responseBody)); ApiDocInfo actualResponse = apiDocRetrievalService.retrieveDefaultApiDoc(SERVICE_ID); diff --git a/apiml-utility/src/main/java/org/zowe/apiml/product/logging/ApimlLogInjector.java b/apiml-utility/src/main/java/org/zowe/apiml/product/logging/ApimlLogInjector.java index 195324c573..88bbec48f6 100644 --- a/apiml-utility/src/main/java/org/zowe/apiml/product/logging/ApimlLogInjector.java +++ b/apiml-utility/src/main/java/org/zowe/apiml/product/logging/ApimlLogInjector.java @@ -37,9 +37,9 @@ public Object postProcessAfterInitialization(@Nonnull Object bean, @Nonnull Stri @Override public Object postProcessBeforeInitialization(final Object bean, @Nonnull String name) { ReflectionUtils.doWithFields(bean.getClass(), field -> { - // make the field accessible if defined private - ReflectionUtils.makeAccessible(field); if (field.getAnnotation(InjectApimlLogger.class) != null) { + // make the field accessible if defined private + ReflectionUtils.makeAccessible(field); Class clazz = getClass(bean); ApimlLogger log = ApimlLogger.of(clazz, YamlMessageServiceInstance.getInstance()); field.set(bean, log);