PRH:security vulnerabilities fix 89/65689/2
authorwasala <przemyslaw.wasala@nokia.com>
Tue, 11 Sep 2018 07:50:21 +0000 (09:50 +0200)
committerwasala <przemyslaw.wasala@nokia.com>
Tue, 11 Sep 2018 17:51:20 +0000 (19:51 +0200)
*Removed unused libraries
*Fixed vulnerablities in connection
with clm scan
*Replaced AssertJ in tests verification
by using StepVerifier

Change-Id: I81c3ac54e5514735f0fca8150fcc218d96dc5ce3
Issue-ID: DCAEGEN2-770
Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
18 files changed:
pom.xml
prh-aai-client/pom.xml
prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClient.java
prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java
prh-app-server/pom.xml
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java
prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/HttpGetClientTest.java
prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProviderTest.java
prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java
prh-commons/pom.xml
prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtils.java
prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java
prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtilsTest.java
prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java
prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java
prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java

diff --git a/pom.xml b/pom.xml
index 82cdab7..1e773c6 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -51,7 +51,7 @@
     <bouncycastle.version>1.59</bouncycastle.version>
     <spring.version>5.0.5.RELEASE</spring.version>
     <spring-boot.version>2.0.4.RELEASE</spring-boot.version>
-    <tomcat.version>8.5.28</tomcat.version>
+    <tomcat.version>8.5.32</tomcat.version>
     <slf4j.version>1.7.25</slf4j.version>
     <junit-jupiter.version>5.1.0</junit-jupiter.version>
     <junit-vintage.version>5.1.0</junit-vintage.version>
         <artifactId>gson</artifactId>
         <version>${immutables.version}</version>
       </dependency>
-      <dependency>
-        <groupId>org.bouncycastle</groupId>
-        <artifactId>bcprov-jdk15on</artifactId>
-        <version>${bouncycastle.version}</version>
-      </dependency>
       <dependency>
         <groupId>org.bouncycastle</groupId>
         <artifactId>bcpkix-jdk15on</artifactId>
         <version>${bouncycastle.version}</version>
       </dependency>
-      <dependency>
-        <groupId>org.apache.httpcomponents</groupId>
-        <artifactId>httpclient</artifactId>
-        <version>4.5.4</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.commons</groupId>
-        <artifactId>commons-lang3</artifactId>
-        <version>3.6</version>
-      </dependency>
       <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-beans</artifactId>
         <version>2.25.1</version>
         <scope>test</scope>
       </dependency>
-      <dependency>
-        <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-starter-test</artifactId>
-        <version>2.0.1.RELEASE</version>
-        <scope>test</scope>
-      </dependency>
 
       <dependency>
         <groupId>io.springfox</groupId>
index 7edf1b6..d055d52 100644 (file)
       <groupId>org.immutables</groupId>
       <artifactId>gson</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.apache.httpcomponents</groupId>
-      <artifactId>httpclient</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-beans</artifactId>
       <groupId>org.springframework</groupId>
       <artifactId>spring-webflux</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-reactor-netty</artifactId>
index 4e0758c..9e282cd 100644 (file)
@@ -26,17 +26,19 @@ import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.X_INVOCA
 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.model.ConsumerDmaapModel;
 import org.slf4j.MDC;
 import org.springframework.web.reactive.function.client.ClientResponse;
 import org.springframework.web.reactive.function.client.WebClient;
+import org.springframework.web.util.DefaultUriBuilderFactory;
 import reactor.core.publisher.Mono;
 
 
+
+
 public class AaiProducerReactiveHttpClient {
 
     private WebClient webClient;
@@ -66,11 +68,7 @@ public class AaiProducerReactiveHttpClient {
      * @return status code of operation
      */
     public Mono<ClientResponse> getAaiProducerResponse(ConsumerDmaapModel consumerDmaapModelMono) {
-        try {
-            return patchAaiRequest(consumerDmaapModelMono);
-        } catch (URISyntaxException e) {
-            return Mono.error(e);
-        }
+        return patchAaiRequest(consumerDmaapModelMono);
     }
 
     public AaiProducerReactiveHttpClient createAaiWebClient(WebClient webClient) {
@@ -78,7 +76,7 @@ public class AaiProducerReactiveHttpClient {
         return this;
     }
 
-    private Mono<ClientResponse> patchAaiRequest(ConsumerDmaapModel dmaapModel) throws URISyntaxException {
+    private Mono<ClientResponse> patchAaiRequest(ConsumerDmaapModel dmaapModel) {
         return
             webClient.patch()
                 .uri(getUri(dmaapModel.getSourceName()))
@@ -88,12 +86,8 @@ public class AaiProducerReactiveHttpClient {
                 .exchange();
     }
 
-    URI getUri(String pnfName) throws URISyntaxException {
-        return new URIBuilder()
-            .setScheme(aaiProtocol)
-            .setHost(aaiHost)
-            .setPort(aaiHostPortNumber)
-            .setPath(aaiBasePath + aaiPnfPath + "/" + pnfName)
-            .build();
+    URI getUri(String pnfName) {
+        return new DefaultUriBuilderFactory().builder().scheme(aaiProtocol).host(aaiHost).port(aaiHostPortNumber)
+            .path(aaiBasePath + aaiPnfPath + "/" + pnfName).build();
     }
 }
index 4160f35..03f9ec6 100644 (file)
@@ -105,23 +105,9 @@ class AaiProducerReactiveHttpClientTest {
             }).verifyComplete();
     }
 
-    @Test
-    void getHttpResponse_whenUriSyntaxExceptionHasBeenThrown() throws URISyntaxException {
-        ///given
-        aaiProducerReactiveHttpClient = spy(aaiProducerReactiveHttpClient);
-        //when
-        when(webClient.patch()).thenReturn(requestBodyUriSpec);
-        aaiProducerReactiveHttpClient.createAaiWebClient(webClient);
-        doThrow(URISyntaxException.class).when(aaiProducerReactiveHttpClient).getUri(any());
-        //then
-        StepVerifier.create(
-            aaiProducerReactiveHttpClient.getAaiProducerResponse(
-                dmaapModel
-            )).expectSubscription().expectError(Exception.class).verify();
-    }
 
     @Test
-    void getAppropriateUri_whenPassingCorrectedPathForPnf() throws URISyntaxException {
+    void getAppropriateUri_whenPassingCorrectedPathForPnf() {
         Assertions.assertEquals(aaiProducerReactiveHttpClient.getUri("NOKnhfsadhff"),
             URI.create("https://54.45.33.2:1234/aai/v11/network/pnfs/pnf/NOKnhfsadhff"));
     }
index b04c06b..f663227 100644 (file)
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>com.fasterxml.jackson.core</groupId>
+          <artifactId>jackson-databind</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <groupId>org.immutables</groupId>
       <artifactId>gson</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.bouncycastle</groupId>
-      <artifactId>bcprov-jdk15on</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.bouncycastle</groupId>
       <artifactId>bcpkix-jdk15on</artifactId>
       <artifactId>junit-platform-launcher</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-starter-test</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
       <artifactId>testng</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>io.springfox</groupId>
index 8b3cdcd..3967dc0 100644 (file)
@@ -48,7 +48,7 @@ public class MainApp {
     }
 
     @Bean
-    Map<String, String> mdcContextMap(){
+    Map<String, String> mdcContextMap() {
         MDC.put(REQUEST_ID, "SampleRequestID");
         MDC.put(INVOCATION_ID, UUID.randomUUID().toString());
         return MDC.getCopyOfContextMap();
index c80ecfa..38b060e 100644 (file)
@@ -22,12 +22,11 @@ package org.onap.dcaegen2.services.prh.service;
 
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
-import java.net.URISyntaxException;
-import org.apache.http.client.utils.URIBuilder;
 import org.onap.dcaegen2.services.prh.model.EnvProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
+import org.springframework.web.util.DefaultUriBuilderFactory;
 import reactor.core.publisher.Mono;
 
 
@@ -57,16 +56,12 @@ public class PrhConfigurationProvider {
 
     private Mono<String> callConsulForConfigBindingServiceEndpoint(EnvProperties envProperties) {
         LOGGER.info("Retrieving Config Binding Service endpoint from Consul");
-        try {
-            return httpGetClient.callHttpGet(getConsulUrl(envProperties), JsonArray.class)
-                .flatMap(jsonArray -> this.createConfigBindingServiceUrl(jsonArray, envProperties.appName()));
-        } catch (URISyntaxException e) {
-            LOGGER.warn("Malformed Consul uri", e);
-            return Mono.error(e);
-        }
+        return httpGetClient.callHttpGet(getConsulUrl(envProperties), JsonArray.class)
+            .flatMap(jsonArray -> this.createConfigBindingServiceUrl(jsonArray, envProperties.appName()));
+
     }
 
-    private String getConsulUrl(EnvProperties envProperties) throws URISyntaxException {
+    private String getConsulUrl(EnvProperties envProperties) {
         return getUri(envProperties.consulHost(), envProperties.consulPort(), "/v1/catalog/service",
             envProperties.cbsName());
     }
@@ -83,13 +78,8 @@ public class PrhConfigurationProvider {
     }
 
     private Mono<String> buildConfigBindingServiceUrl(JsonObject jsonObject, String appName) {
-        try {
-            return Mono.just(getUri(jsonObject.get("ServiceAddress").getAsString(),
-                jsonObject.get("ServicePort").getAsInt(), "/service_component", appName));
-        } catch (URISyntaxException e) {
-            LOGGER.warn("Malformed Config Binding Service uri", e);
-            return Mono.error(e);
-        }
+        return Mono.just(getUri(jsonObject.get("ServiceAddress").getAsString(),
+            jsonObject.get("ServicePort").getAsInt(), "/service_component", appName));
     }
 
     private Mono<JsonObject> getConfigBindingObject(JsonArray jsonArray) {
@@ -105,12 +95,12 @@ public class PrhConfigurationProvider {
         }
     }
 
-    private String getUri(String host, Integer port, String... paths) throws URISyntaxException {
-        return new URIBuilder()
-            .setScheme("http")
-            .setHost(host)
-            .setPort(port)
-            .setPath(String.join("/", paths))
+    private String getUri(String host, Integer port, String... paths) {
+        return new DefaultUriBuilderFactory().builder()
+            .scheme("http")
+            .host(host)
+            .port(port)
+            .path(String.join("/", paths))
             .build().toString();
     }
 }
index 20fbc6b..ab789a0 100644 (file)
@@ -21,8 +21,6 @@
 
 package org.onap.dcaegen2.services.prh.service;
 
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -34,6 +32,8 @@ import com.google.gson.JsonSyntaxException;
 import org.junit.jupiter.api.Test;
 import org.springframework.web.reactive.function.client.WebClient;
 import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
 
 class HttpGetClientTest {
     private static final String SOMEURL = "http://someurl";
@@ -50,12 +50,9 @@ class HttpGetClientTest {
         HttpGetClient httpGetClient = new HttpGetClient(webClient);
         when(responseSpec.bodyToMono(String.class)).thenReturn(Mono.just(DATA));
 
-        //when
-        Mono<JsonObject> jsonObjectMono = httpGetClient.callHttpGet(SOMEURL, JsonObject.class);
-
-        //then
-        assertThat(jsonObjectMono).isNotNull();
-        assertThat(jsonObjectMono.block()).isEqualTo(gson.fromJson(DATA, JsonObject.class));
+        //when/then
+        StepVerifier.create(httpGetClient.callHttpGet(SOMEURL, JsonObject.class)).expectSubscription()
+            .expectNext(gson.fromJson(DATA, JsonObject.class)).verifyComplete();
     }
 
     @Test
@@ -65,16 +62,12 @@ class HttpGetClientTest {
         HttpGetClient httpGetClient = new HttpGetClient(webClient);
         when(responseSpec.bodyToMono(String.class)).thenReturn(Mono.just("some wrong data"));
 
-        //when
-        Mono<JsonObject> jsonObjectMono = httpGetClient.callHttpGet(SOMEURL, JsonObject.class);
-
-        //then
-        assertThat(jsonObjectMono).isNotNull();
-        assertThrows(JsonSyntaxException.class, jsonObjectMono::block);
+        //when/then
+        StepVerifier.create(httpGetClient.callHttpGet(SOMEURL, JsonObject.class)).expectSubscription()
+            .expectError(JsonSyntaxException.class).verify();
     }
 
 
-
     private void mockWebClientDependantObject() {
         doReturn(requestBodyUriSpec).when(webClient).get();
         when(requestBodyUriSpec.uri(SOMEURL)).thenReturn(requestBodyUriSpec);
index 7b30522..e99389f 100644 (file)
 
 package org.onap.dcaegen2.services.prh.service;
 
-import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import com.google.gson.Gson;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
-import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.onap.dcaegen2.services.prh.model.EnvProperties;
 import org.onap.dcaegen2.services.prh.model.ImmutableEnvProperties;
 import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
 
 
 class PrhConfigurationProviderTest {
@@ -72,12 +71,9 @@ class PrhConfigurationProviderTest {
 
         PrhConfigurationProvider provider = new PrhConfigurationProvider(webClient);
 
-        // when
-        Mono<JsonObject> jsonObjectMono = provider.callForPrhConfiguration(envProperties);
-
-        // then
-        assertThat(jsonObjectMono).isNotNull();
-        assertThat(jsonObjectMono.block()).isEqualTo(prhMockConfigurationJson);
+        //when/then
+        StepVerifier.create(provider.callForPrhConfiguration(envProperties)).expectSubscription()
+            .expectNext(prhMockConfigurationJson).verifyComplete();
     }
 
     @Test
@@ -90,11 +86,8 @@ class PrhConfigurationProviderTest {
 
         PrhConfigurationProvider provider = new PrhConfigurationProvider(webClient);
 
-        // when
-        Mono<JsonObject> jsonObjectMono = provider.callForPrhConfiguration(envProperties);
-
-        // then
-        assertThat(jsonObjectMono).isNotNull();
-        Assertions.assertThrows(IllegalStateException.class, jsonObjectMono::block);
+        //when/then
+        StepVerifier.create(provider.callForPrhConfiguration(envProperties)).expectSubscription()
+            .expectError(IllegalStateException.class).verify();
     }
 }
\ No newline at end of file
index 5aa63e0..2f7ff61 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.dcaegen2.services.prh.tasks;
 import static org.mockito.Mockito.spy;
 
 import java.util.Map;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -49,6 +50,7 @@ public class ScheduleControllerSpy {
     @Bean
     @Primary
     public ScheduledTasks registerSimpleScheduledTask() {
-        return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy, mdcContextMap));
+        return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy,
+            mdcContextMap));
     }
 }
index 94cd245..231e402 100644 (file)
       <groupId>org.immutables</groupId>
       <artifactId>gson</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.apache.httpcomponents</groupId>
-      <artifactId>httpclient</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-    </dependency>
-
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-api</artifactId>
       <groupId>org.slf4j</groupId>
       <artifactId>log4j-over-slf4j</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-web</artifactId>
+      <version>5.0.5.RELEASE</version>
+    </dependency>
   </dependencies>
 </project>
index e0264eb..89d9c4f 100644 (file)
 
 package org.onap.dcaegen2.services.prh.model.utils;
 
-import org.apache.http.HttpStatus;
+import org.springframework.http.HttpStatus;
 
-public final class HttpUtils implements HttpStatus {
+public final class HttpUtils {
 
     private HttpUtils() {
     }
 
     public static boolean isSuccessfulResponseCode(Integer statusCode) {
-        return statusCode >= 200 && statusCode < 300;
+        return statusCode >= HttpStatus.OK.value() && statusCode < HttpStatus.MULTIPLE_CHOICES.value();
     }
 }
index b3fc87a..90b32a0 100644 (file)
 package org.onap.dcaegen2.services.prh.model;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.StatusLine;
-import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
 class CommonFunctionsTest {
 
-    private static final HttpResponse httpResponseMock = mock(HttpResponse.class);
-    private static final HttpEntity httpEntityMock = mock(HttpEntity.class);
-    private static final StatusLine statusLineMock = mock(StatusLine.class);
-    // Given
-    private ConsumerDmaapModel model = new ConsumerDmaapModelForUnitTest();
-
-    @BeforeAll
-    static void setup() {
-        when(httpResponseMock.getEntity()).thenReturn(httpEntityMock);
-        when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
-    }
-
     @Test
     void createJsonBody_shouldReturnJsonInString() {
         String expectedResult = "{\"sourceName\":\"NOKnhfsadhff\",\"ipaddress-v4-oam\":\"256.22.33.155\""
             + ",\"ipaddress-v6-oam\":\"2001:0db8:85a3:0000:0000:8a2e:0370:7334\"}";
-        assertEquals(expectedResult, CommonFunctions.createJsonBody(model));
+        assertEquals(expectedResult, CommonFunctions.createJsonBody(new ConsumerDmaapModelForUnitTest()));
     }
 }
index 334bd1b..89c7202 100644 (file)
@@ -23,18 +23,17 @@ package org.onap.dcaegen2.services.prh.model.utils;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import org.apache.http.HttpStatus;
 import org.junit.jupiter.api.Test;
 
 class HttpUtilsTest {
 
     @Test
     void isSuccessfulResponseCode_shouldReturnTrue() {
-        assertTrue(HttpUtils.isSuccessfulResponseCode(HttpUtils.SC_ACCEPTED));
+        assertTrue(HttpUtils.isSuccessfulResponseCode(202));
     }
 
     @Test
     void isSuccessfulResponseCode_shouldReturnFalse() {
-        assertFalse(HttpUtils.isSuccessfulResponseCode(HttpStatus.SC_BAD_GATEWAY));
+        assertFalse(HttpUtils.isSuccessfulResponseCode(502));
     }
 }
\ No newline at end of file
index 242214d..02c6ba9 100644 (file)
@@ -25,15 +25,14 @@ import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.X_INVOCA
 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 java.util.function.Consumer;
-import org.apache.http.client.utils.URIBuilder;
 import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
 import org.slf4j.MDC;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.reactive.function.client.WebClient;
+import org.springframework.web.util.DefaultUriBuilderFactory;
 import reactor.core.publisher.Mono;
 
 /**
@@ -71,21 +70,17 @@ public class DMaaPConsumerReactiveHttpClient {
      * @return reactive response from DMaaP in string format
      */
     public Mono<String> getDMaaPConsumerResponse() {
-        try {
-            return webClient
-                .get()
-                .uri(getUri())
-                .headers(getHeaders())
-                .retrieve()
-                .onStatus(HttpStatus::is4xxClientError, clientResponse ->
-                    Mono.error(new RuntimeException("DmaaPConsumer HTTP " + clientResponse.statusCode()))
-                )
-                .onStatus(HttpStatus::is5xxServerError, clientResponse ->
-                    Mono.error(new RuntimeException("DmaaPConsumer HTTP " + clientResponse.statusCode())))
-                .bodyToMono(String.class);
-        } catch (URISyntaxException e) {
-            return Mono.error(e);
-        }
+        return webClient
+            .get()
+            .uri(getUri())
+            .headers(getHeaders())
+            .retrieve()
+            .onStatus(HttpStatus::is4xxClientError, clientResponse ->
+                Mono.error(new RuntimeException("DmaaPConsumer HTTP " + clientResponse.statusCode()))
+            )
+            .onStatus(HttpStatus::is5xxServerError, clientResponse ->
+                Mono.error(new RuntimeException("DmaaPConsumer HTTP " + clientResponse.statusCode())))
+            .bodyToMono(String.class);
     }
 
     private Consumer<HttpHeaders> getHeaders() {
@@ -105,8 +100,8 @@ public class DMaaPConsumerReactiveHttpClient {
         return this;
     }
 
-    URI getUri() throws URISyntaxException {
-        return new URIBuilder().setScheme(dmaapProtocol).setHost(dmaapHostName).setPort(dmaapPortNumber)
-            .setPath(createRequestPath()).build();
+    URI getUri() {
+        return new DefaultUriBuilderFactory().builder().scheme(dmaapProtocol).host(dmaapHostName).port(dmaapPortNumber)
+            .path(createRequestPath()).build();
     }
 }
index 862ad84..6cd5484 100644 (file)
@@ -26,9 +26,7 @@ import static org.onap.dcaegen2.services.prh.model.logging.MdcVariables.X_INVOCA
 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.DmaapPublisherConfiguration;
 import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
 import org.slf4j.MDC;
@@ -37,8 +35,11 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.DefaultUriBuilderFactory;
 import reactor.core.publisher.Mono;
 
+
+
 /**
  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18
  */
@@ -74,12 +75,9 @@ public class DMaaPProducerReactiveHttpClient {
 
     public Mono<ResponseEntity<String>> getDMaaPProducerResponse(ConsumerDmaapModel consumerDmaapModelMono) {
         return Mono.defer(() -> {
-            try {
-                HttpEntity<String> request = new HttpEntity<>(createJsonBody(consumerDmaapModelMono), getAllHeaders());
-                return Mono.just(restTemplate.exchange(getUri(), HttpMethod.POST, request, String.class));
-            } catch (URISyntaxException e) {
-                return Mono.error(e);
-            }
+            HttpEntity<String> request = new HttpEntity<>(createJsonBody(consumerDmaapModelMono), getAllHeaders());
+            return Mono.just(restTemplate.exchange(getUri(), HttpMethod.POST, request, String.class));
+
         });
     }
 
@@ -97,9 +95,9 @@ public class DMaaPProducerReactiveHttpClient {
         return this;
     }
 
-    URI getUri() throws URISyntaxException {
-        return new URIBuilder().setScheme(dmaapProtocol).setHost(dmaapHostName).setPort(dmaapPortNumber)
-            .setPath(dmaapTopicName).build();
+    URI getUri() {
+        return new DefaultUriBuilderFactory().builder().scheme(dmaapProtocol).host(dmaapHostName).port(dmaapPortNumber)
+            .path(dmaapTopicName).build();
     }
 
 }
index 26fa65f..c8ffd12 100644 (file)
@@ -96,20 +96,6 @@ class DMaaPConsumerReactiveHttpClientTest {
             }).verifyComplete();
     }
 
-    @Test
-    void getHttpResponse_whenUriSyntaxExceptionHasBeenThrown() throws URISyntaxException {
-        //given
-        dmaapConsumerReactiveHttpClient = spy(dmaapConsumerReactiveHttpClient);
-        //when
-        when(webClient.get()).thenReturn(requestHeadersSpec);
-        dmaapConsumerReactiveHttpClient.createDMaaPWebClient(webClient);
-        when(dmaapConsumerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class);
-
-        //then
-        StepVerifier.create(dmaapConsumerReactiveHttpClient.getDMaaPConsumerResponse()).expectSubscription()
-            .expectError(Exception.class).verify();
-    }
-
     @Test
     void getAppropriateUri_whenPassingCorrectedPathForPnf() throws URISyntaxException {
         Assertions.assertEquals(dmaapConsumerReactiveHttpClient.getUri(),
index 05b7489..29d1039 100644 (file)
@@ -23,12 +23,9 @@ package org.onap.dcaegen2.services.prh.service.producer;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 
 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;
@@ -42,6 +39,8 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.web.client.RestTemplate;
 import reactor.test.StepVerifier;
 
+
+
 /**
  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18
  */
@@ -86,19 +85,7 @@ class DMaaPProducerReactiveHttpClientTest {
     }
 
     @Test
-    void getHttpResponse_whenUriSyntaxExceptionHasBeenThrown() throws URISyntaxException {
-        //given
-        dmaapProducerReactiveHttpClient = spy(dmaapProducerReactiveHttpClient);
-        //when
-        when(dmaapProducerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class);
-
-        //then
-        StepVerifier.create(dmaapProducerReactiveHttpClient.getDMaaPProducerResponse(any())).expectSubscription()
-            .expectError(Exception.class).verify();
-    }
-
-    @Test
-    void getAppropriateUri_whenPassingCorrectedPathForPnf() throws URISyntaxException {
+    void getAppropriateUri_whenPassingCorrectedPathForPnf() {
         Assertions.assertEquals(dmaapProducerReactiveHttpClient.getUri(),
             URI.create("https://54.45.33.2:1234/unauthenticated.PNF_READY"));
     }