diff options
author | micdzied <michal.1.dziedzic@nokia.com> | 2018-08-30 10:25:19 +0200 |
---|---|---|
committer | micdzied <michal.1.dziedzic@nokia.com> | 2018-08-30 14:53:20 +0200 |
commit | 6fd8c7770fbea30ad2ec6e3f7645b8baab5a49a1 (patch) | |
tree | 78d572b5df8c88047d74edf3c75b28fcab3d0dc6 /prh-aai-client/src | |
parent | 82a6fc31d1905f380fbbae1d0b4a34b67d8258e3 (diff) |
add MDC's
Change-Id: Ie4fe86791f46b790ae42088a5d2b93f491e4549d
Issue-ID: DCAEGEN2-730
Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
Diffstat (limited to 'prh-aai-client/src')
4 files changed, 24 insertions, 17 deletions
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java index 50259bae..4727f4bd 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java @@ -21,9 +21,7 @@ package org.onap.dcaegen2.services.prh.config; import java.io.Serializable; - import java.util.Map; - import org.immutables.gson.Gson; import org.immutables.value.Value; import org.springframework.stereotype.Component; diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClient.java index d79e245a..6daf54a1 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClient.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClient.java @@ -20,12 +20,15 @@ package org.onap.dcaegen2.services.prh.service; +import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.RESPONSE_CODE; +import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.SERVICE_NAME; import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; import java.util.Map; import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; @@ -68,6 +71,7 @@ public class AaiReactiveWebClient { private ExchangeFilterFunction logRequest() { return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> { + MDC.put(SERVICE_NAME, String.valueOf(clientRequest.url())); logger.info("Request: {} {}", clientRequest.method(), clientRequest.url()); clientRequest.headers() .forEach((name, values) -> values.forEach(value -> logger.info("{}={}", name, value))); @@ -77,6 +81,7 @@ public class AaiReactiveWebClient { private ExchangeFilterFunction logResponse() { return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> { + MDC.put(RESPONSE_CODE, String.valueOf(clientResponse.statusCode())); logger.info("Response Status {}", clientResponse.statusCode()); return Mono.just(clientResponse); }); diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java index 0a6c9926..be6c63e0 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java @@ -20,15 +20,20 @@ package org.onap.dcaegen2.services.prh.service.producer; +import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.REQUEST_ID; +import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.X_INVOCATION_ID; +import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.X_ONAP_REQUEST_ID; + import java.net.URI; import java.net.URISyntaxException; - +import java.util.UUID; import org.apache.http.client.utils.URIBuilder; import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.exceptions.AaiRequestException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.http.HttpStatus; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; @@ -37,12 +42,12 @@ import reactor.core.publisher.Mono; public class AaiProducerReactiveHttpClient { - private WebClient webClient; private final String aaiHost; private final String aaiProtocol; private final Integer aaiHostPortNumber; private final String aaiBasePath; private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private WebClient webClient; /** @@ -78,6 +83,8 @@ public class AaiProducerReactiveHttpClient { try { return webClient.patch() .uri(getUri(dmaapModel.getSourceName())) + .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID)) + .header(X_INVOCATION_ID, UUID.randomUUID().toString()) .body(BodyInserters.fromObject(dmaapModel)) .retrieve() .onStatus( diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java index c99deca5..9b0f4fe8 100644 --- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java +++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java @@ -45,10 +45,8 @@ import reactor.test.StepVerifier; class AaiProducerReactiveHttpClientTest { - private static AaiProducerReactiveHttpClient aaiProducerReactiveHttpClient; - private static final Integer SUCCESS_RESPONSE = 200; - + private static AaiProducerReactiveHttpClient aaiProducerReactiveHttpClient; private static AaiClientConfiguration aaiConfigurationMock = mock(AaiClientConfiguration.class); private static WebClient webClient = mock(WebClient.class); @@ -82,6 +80,14 @@ class AaiProducerReactiveHttpClientTest { responseSpec = mock(ResponseSpec.class); } + private static void setupHeaders() { + aaiHeaders = new HashMap<>(); + aaiHeaders.put("X-FromAppId", "PRH"); + aaiHeaders.put("X-TransactionId", "vv-temp"); + aaiHeaders.put("Accept", "application/json"); + aaiHeaders.put("Real-Time", "true"); + aaiHeaders.put("Content-Type", "application/merge-patch+json"); + } @Test void getAaiProducerResponse_shouldReturn200() { @@ -118,24 +124,15 @@ class AaiProducerReactiveHttpClientTest { )).expectSubscription().expectError(Exception.class).verify(); } - private void mockWebClientDependantObject() { WebClient.RequestHeadersSpec requestHeadersSpec = mock(WebClient.RequestHeadersSpec.class); when(webClient.patch()).thenReturn(requestBodyUriSpec); when(requestBodyUriSpec.uri((URI) any())).thenReturn(requestBodyUriSpec); + when(requestBodyUriSpec.header(any(), any())).thenReturn(requestBodyUriSpec); when(requestBodyUriSpec.body(any())).thenReturn(requestHeadersSpec); doReturn(responseSpec).when(requestHeadersSpec).retrieve(); doReturn(responseSpec).when(responseSpec).onStatus(any(), any()); } - private static void setupHeaders() { - aaiHeaders = new HashMap<>(); - aaiHeaders.put("X-FromAppId", "PRH"); - aaiHeaders.put("X-TransactionId", "vv-temp"); - aaiHeaders.put("Accept", "application/json"); - aaiHeaders.put("Real-Time", "true"); - aaiHeaders.put("Content-Type", "application/merge-patch+json"); - } - } |