diff options
author | pkaras <piotr.karas@nokia.com> | 2018-11-06 12:22:28 +0100 |
---|---|---|
committer | pkaras <piotr.karas@nokia.com> | 2018-11-06 13:14:46 +0100 |
commit | 8a762124d24555d50ce7455398ca3ac02fde1076 (patch) | |
tree | d31fc5feb13438a364e74fc8b4f2d4e9f39f4be7 /prh-app-server/src | |
parent | 8330d0e6c2cf1d9d8215e13b928530c2277fa974 (diff) |
SSL setup for dmaap consumer
Change-Id: I5856554fa05cfd9ad637c0491eb801f9937c967a
Issue-ID: DCAEGEN2-951
Signed-off-by: piotr.karas <piotr.karas@nokia.com>
Diffstat (limited to 'prh-app-server/src')
5 files changed, 25 insertions, 11 deletions
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 58b29d2e..005cc629 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 @@ -20,10 +20,12 @@ package org.onap.dcaegen2.services.prh.tasks; +import javax.net.ssl.SSLException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.service.consumer.DMaaPConsumerReactiveHttpClient; import reactor.core.publisher.Flux; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ @@ -31,7 +33,7 @@ interface DmaapConsumerTask { void initConfigs(); - Flux<ConsumerDmaapModel> execute(String object); + Flux<ConsumerDmaapModel> execute(String object) throws SSLException; - DMaaPConsumerReactiveHttpClient resolveClient(); + DMaaPConsumerReactiveHttpClient resolveClient() throws SSLException; } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java index a52163b7..e46ee89a 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java @@ -20,18 +20,20 @@ package org.onap.dcaegen2.services.prh.tasks; +import javax.net.ssl.SSLException; import org.onap.dcaegen2.services.prh.configuration.Config; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser; import org.onap.dcaegen2.services.prh.service.consumer.ConsumerReactiveHttpClientFactory; import org.onap.dcaegen2.services.prh.service.consumer.DMaaPConsumerReactiveHttpClient; -import org.onap.dcaegen2.services.prh.service.consumer.DMaaPReactiveWebClient; +import org.onap.dcaegen2.services.prh.service.consumer.DMaaPReactiveWebClientFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import reactor.core.publisher.Flux; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 */ @@ -46,7 +48,7 @@ public class DmaapConsumerTaskImpl implements DmaapConsumerTask { @Autowired public DmaapConsumerTaskImpl(Config config) { this(config, new DmaapConsumerJsonParser(), - new ConsumerReactiveHttpClientFactory(new DMaaPReactiveWebClient())); + new ConsumerReactiveHttpClientFactory(new DMaaPReactiveWebClientFactory())); } DmaapConsumerTaskImpl(Config prhAppConfig, @@ -63,14 +65,14 @@ public class DmaapConsumerTaskImpl implements DmaapConsumerTask { } @Override - public Flux<ConsumerDmaapModel> execute(String object) { + public Flux<ConsumerDmaapModel> execute(String object) throws SSLException { DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient = resolveClient(); LOGGER.debug("Method called with arg {}", object); return dmaapConsumerJsonParser.getJsonObject(dmaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()); } @Override - public DMaaPConsumerReactiveHttpClient resolveClient() { + public DMaaPConsumerReactiveHttpClient resolveClient() throws SSLException { return httpClientFactory.create(config.getDmaapConsumerConfiguration()); } } 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 08767428..d6814ed6 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 @@ -127,10 +127,18 @@ public class ScheduledTasks { MDC.put(INSTANCE_UUID, UUID.randomUUID().toString()); logger.info(INVOKE, "Init configs"); dmaapConsumerTask.initConfigs(); - return dmaapConsumerTask.execute(""); + return consumeFromDMaaP(); }); } + private Flux<ConsumerDmaapModel> consumeFromDMaaP() { + try { + return dmaapConsumerTask.execute(""); + } catch (SSLException e) { + return Flux.error(e); + } + } + private Mono<ConsumerDmaapModel> publishToAaiConfiguration(ConsumerDmaapModel monoDMaaPModel) { try { return aaiProducerTask.execute(monoDMaaPModel); diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java index 1a858917..35da3323 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java @@ -82,7 +82,7 @@ class DmaapConsumerTaskImplTest { } @Test - void whenPassedObjectDoesntFit_DoesNotThrowPrhTaskException() { + void whenPassedObjectDoesntFit_DoesNotThrowPrhTaskException() throws Exception { //given prepareMocksForDmaapConsumer(Optional.empty()); @@ -95,7 +95,7 @@ class DmaapConsumerTaskImplTest { } @Test - void whenPassedObjectFits_ReturnsCorrectResponse() { + void whenPassedObjectFits_ReturnsCorrectResponse() throws Exception { //given prepareMocksForDmaapConsumer(Optional.of(message)); @@ -116,7 +116,7 @@ class DmaapConsumerTaskImplTest { verify(appConfig).initFileStreamReader(); } - private void prepareMocksForDmaapConsumer(Optional<String> message) { + private void prepareMocksForDmaapConsumer(Optional<String> message) throws Exception { dMaaPConsumerReactiveHttpClient = mock(DMaaPConsumerReactiveHttpClient.class); when(dMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).thenReturn(Mono.just(message.orElse(""))); when(appConfig.getDmaapConsumerConfiguration()).thenReturn(dmaapConsumerConfiguration); diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java index f42c3962..d2eabfc9 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; +import javax.net.ssl.SSLException; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; import org.onap.dcaegen2.services.prh.service.consumer.DMaaPConsumerReactiveHttpClient; @@ -31,6 +32,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18 */ @@ -44,7 +46,7 @@ public class DmaapConsumerTaskSpy { */ @Bean @Primary - public DmaapConsumerTask registerSimpleDmaapConsumerTask() { + public DmaapConsumerTask registerSimpleDmaapConsumerTask() throws SSLException { AppConfig appConfig = spy(AppConfig.class); doReturn(mock(DmaapConsumerConfiguration.class)).when(appConfig).getDmaapConsumerConfiguration(); DmaapConsumerTaskImpl dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig)); |