diff options
9 files changed, 21 insertions, 34 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java index 11c75e80..10626a32 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java @@ -26,6 +26,7 @@ import java.util.Properties; import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.prh.config.ImmutableAaiClientConfiguration; import org.onap.dcaegen2.services.prh.model.EnvProperties; import org.onap.dcaegen2.services.prh.service.PrhConfigurationProvider; import org.slf4j.Logger; @@ -99,7 +100,9 @@ public class CloudConfiguration extends AppConfig { @Override public AaiClientConfiguration getAaiClientConfiguration() { - return Optional.ofNullable(aaiClientCloudConfiguration).orElse(super.getAaiClientConfiguration()); + return Optional.ofNullable(ImmutableAaiClientConfiguration.copyOf(aaiClientCloudConfiguration) + .withAaiHeaders(aaiClientConfiguration.aaiHeaders())) + .orElse(ImmutableAaiClientConfiguration.copyOf(super.getAaiClientConfiguration())); } @Override diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java index 414c5a34..c80ecfaf 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java @@ -59,7 +59,7 @@ public class PrhConfigurationProvider { LOGGER.info("Retrieving Config Binding Service endpoint from Consul"); try { return httpGetClient.callHttpGet(getConsulUrl(envProperties), JsonArray.class) - .flatMap(jsonArray -> this.createConfigBindingserviceurl(jsonArray, envProperties.appName())); + .flatMap(jsonArray -> this.createConfigBindingServiceUrl(jsonArray, envProperties.appName())); } catch (URISyntaxException e) { LOGGER.warn("Malformed Consul uri", e); return Mono.error(e); @@ -77,12 +77,12 @@ public class PrhConfigurationProvider { } - private Mono<String> createConfigBindingserviceurl(JsonArray jsonArray, String appName) { + private Mono<String> createConfigBindingServiceUrl(JsonArray jsonArray, String appName) { return getConfigBindingObject(jsonArray) - .flatMap(jsonObject -> buildConfigBindingserviceurl(jsonObject, appName)); + .flatMap(jsonObject -> buildConfigBindingServiceUrl(jsonObject, appName)); } - private Mono<String> buildConfigBindingserviceurl(JsonObject jsonObject, String appName) { + private Mono<String> buildConfigBindingServiceUrl(JsonObject jsonObject, String appName) { try { return Mono.just(getUri(jsonObject.get("ServiceAddress").getAsString(), jsonObject.get("ServicePort").getAsInt(), "/service_component", appName)); diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java index d322a43e..a6baf4a5 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java @@ -43,6 +43,6 @@ abstract class DmaapConsumerTask { protected abstract Mono<ConsumerDmaapModel> execute(String object); WebClient buildWebClient() { - return new DMaaPReactiveWebClient().fromConfiguration(resolveConfiguration()).build(); + return new DMaaPReactiveWebClient().build(); } } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java index 728c0dae..92d810ff 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java @@ -20,7 +20,6 @@ package org.onap.dcaegen2.services.prh.tasks; - import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.INSTANCE_UUID; import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.RESPONSE_CODE; diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java index 4327dfbf..d34728ce 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java @@ -20,7 +20,6 @@ package org.onap.dcaegen2.services.prh.service; -import org.onap.dcaegen2.services.prh.config.DmaapCustomConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -35,21 +34,6 @@ public class DMaaPReactiveWebClient { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private String dmaaPUserName; - private String dmaaPUserPassword; - - /** - * Creating DMaaPReactiveWebClient passing to them basic DMaaPConfig. - * - * @param dmaapCustomConfig - configuration object - * @return DMaaPReactiveWebClient - */ - public DMaaPReactiveWebClient fromConfiguration(DmaapCustomConfig dmaapCustomConfig) { - this.dmaaPUserName = dmaapCustomConfig.dmaapUserName(); - this.dmaaPUserPassword = dmaapCustomConfig.dmaapUserPassword(); - return this; - } - /** * Construct Reactive WebClient with appropriate settings. * diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java index ab6686db..242214d2 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java @@ -27,6 +27,7 @@ import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.X_ONAP_R import java.net.URI; import java.net.URISyntaxException; import java.util.UUID; +import java.util.function.Consumer; import org.apache.http.client.utils.URIBuilder; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.slf4j.MDC; @@ -74,9 +75,7 @@ public class DMaaPConsumerReactiveHttpClient { return webClient .get() .uri(getUri()) - .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID)) - .header(X_INVOCATION_ID, UUID.randomUUID().toString()) - .header(HttpHeaders.CONTENT_TYPE, contentType) + .headers(getHeaders()) .retrieve() .onStatus(HttpStatus::is4xxClientError, clientResponse -> Mono.error(new RuntimeException("DmaaPConsumer HTTP " + clientResponse.statusCode())) @@ -89,6 +88,14 @@ public class DMaaPConsumerReactiveHttpClient { } } + private Consumer<HttpHeaders> getHeaders() { + return httpHeaders -> { + httpHeaders.set(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID)); + httpHeaders.set(X_INVOCATION_ID, UUID.randomUUID().toString()); + httpHeaders.set(HttpHeaders.CONTENT_TYPE, contentType); + }; + } + private String createRequestPath() { return dmaapTopicName + "/" + consumerGroup + "/" + consumerId; } diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java index 0b61f9c2..862ad841 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java @@ -31,8 +31,6 @@ import java.util.UUID; import org.apache.http.client.utils.URIBuilder; import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.slf4j.MDC; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -46,13 +44,12 @@ import reactor.core.publisher.Mono; */ public class DMaaPProducerReactiveHttpClient { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private final String dmaapHostName; private final Integer dmaapPortNumber; private final String dmaapProtocol; private final String dmaapTopicName; private final String dmaapContentType; + private RestTemplate restTemplate; /** @@ -81,7 +78,6 @@ public class DMaaPProducerReactiveHttpClient { HttpEntity<String> request = new HttpEntity<>(createJsonBody(consumerDmaapModelMono), getAllHeaders()); return Mono.just(restTemplate.exchange(getUri(), HttpMethod.POST, request, String.class)); } catch (URISyntaxException e) { - logger.warn("Exception while evaluating URI"); return Mono.error(e); } }); diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java index ee88f1f8..4ca5ceb6 100644 --- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java +++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java @@ -47,7 +47,6 @@ class DMaaPReactiveWebClientTest { when(dmaapConsumerConfiguration.dmaapUserName()).thenReturn(dmaaPUserName); when(dmaapConsumerConfiguration.dmaapUserPassword()).thenReturn(dmaaPUserPassword); WebClient dmaapreactiveWebClient = new DMaaPReactiveWebClient() - .fromConfiguration(dmaapConsumerConfiguration) .build(); //then diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java index 9f693701..26fa65f5 100644 --- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java +++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java @@ -29,7 +29,6 @@ import static org.springframework.web.reactive.function.client.ExchangeFilterFun import java.net.URI; import java.net.URISyntaxException; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -120,7 +119,7 @@ class DMaaPConsumerReactiveHttpClientTest { private void mockDependantObjects() { when(webClient.get()).thenReturn(requestHeadersSpec); when(requestHeadersSpec.uri((URI) any())).thenReturn(requestHeadersSpec); - when(requestHeadersSpec.header(any(), any())).thenReturn(requestHeadersSpec); + when(requestHeadersSpec.headers(any())).thenReturn(requestHeadersSpec); when(requestHeadersSpec.retrieve()).thenReturn(responseSpec); doReturn(responseSpec).when(responseSpec).onStatus(any(), any()); } |