diff options
Diffstat (limited to 'prh-dmaap-client/src')
5 files changed, 12 insertions, 27 deletions
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()); } |