summaryrefslogtreecommitdiffstats
path: root/prh-aai-client
diff options
context:
space:
mode:
Diffstat (limited to 'prh-aai-client')
-rw-r--r--prh-aai-client/pom.xml4
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java2
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiReactiveWebClient.java5
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java11
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java23
5 files changed, 26 insertions, 19 deletions
diff --git a/prh-aai-client/pom.xml b/prh-aai-client/pom.xml
index 87cdf389..cbd6c868 100644
--- a/prh-aai-client/pom.xml
+++ b/prh-aai-client/pom.xml
@@ -18,8 +18,8 @@
~ limitations under the License.
~ ============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
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");
- }
-
}