aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-dmaap-client
diff options
context:
space:
mode:
Diffstat (limited to 'datafile-dmaap-client')
-rw-r--r--datafile-dmaap-client/pom.xml8
-rw-r--r--datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClient.java15
-rw-r--r--datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java (renamed from datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java)30
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java (renamed from datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClientTest.java)16
4 files changed, 36 insertions, 33 deletions
diff --git a/datafile-dmaap-client/pom.xml b/datafile-dmaap-client/pom.xml
index 0f3cf6aa..8d972573 100644
--- a/datafile-dmaap-client/pom.xml
+++ b/datafile-dmaap-client/pom.xml
@@ -116,13 +116,7 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
-
- <!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher -->
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-launcher</artifactId>
- <scope>test</scope>
- </dependency>
+
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClient.java
index 21266fbc..23fd0bc7 100644
--- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClient.java
+++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapReactiveWebClient.java
@@ -16,9 +16,10 @@
package org.onap.dcaegen2.collectors.datafile.service;
-import static org.onap.dcaegen2.collectors.datafile.model.logging.MdcVariables.RESPONSE_CODE;
-import static org.onap.dcaegen2.collectors.datafile.model.logging.MdcVariables.SERVICE_NAME;
+import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.RESPONSE_CODE;
+import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.SERVICE_NAME;
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
+
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapCustomConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,6 +28,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClient.Builder;
+
import reactor.core.publisher.Mono;
/**
@@ -57,12 +59,13 @@ public class DmaapReactiveWebClient {
* @return WebClient
*/
public WebClient build() {
- Builder webClientBuilder = WebClient.builder().defaultHeader(HttpHeaders.CONTENT_TYPE, dmaaPContentType)
- .filter(logRequest()).filter(logResponse());
+ Builder webClientBuilder = WebClient.builder()
+ .defaultHeader(HttpHeaders.CONTENT_TYPE, dmaaPContentType) //
+ .filter(logRequest()) //
+ .filter(logResponse());
if (dmaaPUserName != null && !dmaaPUserName.isEmpty() && dmaaPUserPassword != null
&& !dmaaPUserPassword.isEmpty()) {
webClientBuilder.filter(basicAuthentication(dmaaPUserName, dmaaPUserPassword));
-
}
return webClientBuilder.build();
}
@@ -81,7 +84,7 @@ public class DmaapReactiveWebClient {
MDC.put(SERVICE_NAME, String.valueOf(clientRequest.url()));
logger.trace("Request: {} {}", clientRequest.method(), clientRequest.url());
clientRequest.headers()
- .forEach((name, values) -> values.forEach(value -> logger.info("{}={}", name, value)));
+ .forEach((name, values) -> values.forEach(value -> logger.trace("{}={}", name, value)));
logger.trace("HTTP request headers: {}", clientRequest.headers());
MDC.remove(SERVICE_NAME);
return Mono.just(clientRequest);
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java
index 944d3b34..b0904b29 100644
--- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClient.java
+++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java
@@ -20,6 +20,7 @@ import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
+import java.time.Duration;
import java.util.Map;
import java.util.concurrent.Future;
@@ -35,11 +36,11 @@ import org.apache.http.ssl.SSLContextBuilder;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.http.HttpAsyncClientBuilderWrapper;
import org.onap.dcaegen2.collectors.datafile.http.IHttpAsyncClientBuilder;
-import org.onap.dcaegen2.collectors.datafile.model.logging.MdcVariables;
import org.onap.dcaegen2.collectors.datafile.web.PublishRedirectStrategy;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.web.util.DefaultUriBuilderFactory;
@@ -49,9 +50,9 @@ import org.springframework.web.util.UriBuilder;
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
-public class DmaapProducerReactiveHttpClient {
+public class DmaapProducerHttpClient {
- private static final int NO_REQUEST_TIMEOUT = -1;
+ private static final Duration DEFAULT_REQUEST_TIMEOUT = Duration.ofMinutes(2);
private static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE_RETURN");
@@ -64,14 +65,14 @@ public class DmaapProducerReactiveHttpClient {
*
* @param dmaapPublisherConfiguration - DMaaP producer configuration object
*/
- public DmaapProducerReactiveHttpClient(DmaapPublisherConfiguration dmaapPublisherConfiguration) {
+ public DmaapProducerHttpClient(DmaapPublisherConfiguration dmaapPublisherConfiguration) {
this.configuration = dmaapPublisherConfiguration;
}
public HttpResponse getDmaapProducerResponseWithRedirect(HttpUriRequest request, Map<String, String> contextMap)
throws DatafileTaskException {
- try (CloseableHttpAsyncClient webClient = createWebClient(true, NO_REQUEST_TIMEOUT)) {
- MdcVariables.setMdcContextMap(contextMap);
+ MDC.setContextMap(contextMap);
+ try (CloseableHttpAsyncClient webClient = createWebClient(true, DEFAULT_REQUEST_TIMEOUT)) {
webClient.start();
logger.trace(INVOKE, "Starting to produce to DR {}", request);
@@ -84,10 +85,10 @@ public class DmaapProducerReactiveHttpClient {
}
}
- public HttpResponse getDmaapProducerResponseWithCustomTimeout(HttpUriRequest request, int requestTimeout,
+ public HttpResponse getDmaapProducerResponseWithCustomTimeout(HttpUriRequest request, Duration requestTimeout,
Map<String, String> contextMap) throws DatafileTaskException {
+ MDC.setContextMap(contextMap);
try (CloseableHttpAsyncClient webClient = createWebClient(false, requestTimeout)) {
- MdcVariables.setMdcContextMap(contextMap);
webClient.start();
logger.trace(INVOKE, "Starting to produce to DR {}", request);
@@ -116,7 +117,7 @@ public class DmaapProducerReactiveHttpClient {
.port(configuration.dmaapPortNumber());
}
- private CloseableHttpAsyncClient createWebClient(boolean expectRedirect, int requestTimeout)
+ private CloseableHttpAsyncClient createWebClient(boolean expectRedirect, Duration requestTimeout)
throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
SSLContext sslContext =
new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build();
@@ -129,14 +130,17 @@ public class DmaapProducerReactiveHttpClient {
clientBuilder.setRedirectStrategy(PublishRedirectStrategy.INSTANCE);
}
- if (requestTimeout > NO_REQUEST_TIMEOUT) {
+ if (requestTimeout.toMillis() > 0) {
+ int millis = (int)requestTimeout.toMillis();
RequestConfig requestConfig = RequestConfig.custom() //
- .setSocketTimeout(requestTimeout) //
- .setConnectTimeout(requestTimeout) //
- .setConnectionRequestTimeout(requestTimeout) //
+ .setSocketTimeout(millis) //
+ .setConnectTimeout(millis) //
+ .setConnectionRequestTimeout(millis) //
.build();
clientBuilder.setDefaultRequestConfig(requestConfig);
+ } else {
+ logger.error("WEB client without timeout created {}", requestTimeout);
}
return clientBuilder.build();
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClientTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java
index 91c4c334..92a14997 100644
--- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerReactiveHttpClientTest.java
+++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java
@@ -32,6 +32,7 @@ import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
+import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Future;
@@ -59,18 +60,18 @@ import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPub
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
-class DmaapProducerReactiveHttpClientTest {
+class DmaapProducerHttpClientTest {
private static final String HOST = "54.45.33.2";
private static final String HTTPS_SCHEME = "https";
private static final int PORT = 1234;
private static final String USER_NAME = "dradmin";
- private static final int TWO_SECOND_TIMEOUT = 2000;
+ private static final Duration TWO_SECOND_TIMEOUT = Duration.ofSeconds(2);
private static final Map<String, String> CONTEXT_MAP = new HashMap<>();
- private DmaapProducerReactiveHttpClient producerClientUnderTestSpy;
+ private DmaapProducerHttpClient producerClientUnderTestSpy;
private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(DmaapPublisherConfiguration.class);
@@ -88,7 +89,7 @@ class DmaapProducerReactiveHttpClientTest {
when(dmaapPublisherConfigurationMock.dmaapUserName()).thenReturn("dradmin");
when(dmaapPublisherConfigurationMock.dmaapUserPassword()).thenReturn("dradmin");
- producerClientUnderTestSpy = spy(new DmaapProducerReactiveHttpClient(dmaapPublisherConfigurationMock));
+ producerClientUnderTestSpy = spy(new DmaapProducerHttpClient(dmaapPublisherConfigurationMock));
clientBuilderMock = mock(IHttpAsyncClientBuilder.class);
clientMock = mock(CloseableHttpAsyncClient.class);
@@ -110,6 +111,7 @@ class DmaapProducerReactiveHttpClientTest {
verify(clientBuilderMock).setSSLContext(any(SSLContext.class));
verify(clientBuilderMock).setSSLHostnameVerifier(any(NoopHostnameVerifier.class));
verify(clientBuilderMock).setRedirectStrategy(PublishRedirectStrategy.INSTANCE);
+ verify(clientBuilderMock).setDefaultRequestConfig(any());
verify(clientBuilderMock).build();
verifyNoMoreInteractions(clientBuilderMock);
@@ -138,9 +140,9 @@ class DmaapProducerReactiveHttpClientTest {
verify(clientBuilderMock).setSSLHostnameVerifier(any(NoopHostnameVerifier.class));
verify(clientBuilderMock).setDefaultRequestConfig(requestConfigCaptor.capture());
RequestConfig requestConfig = requestConfigCaptor.getValue();
- assertEquals(TWO_SECOND_TIMEOUT, requestConfig.getSocketTimeout());
- assertEquals(TWO_SECOND_TIMEOUT, requestConfig.getConnectTimeout());
- assertEquals(TWO_SECOND_TIMEOUT, requestConfig.getConnectionRequestTimeout());
+ assertEquals(TWO_SECOND_TIMEOUT.toMillis(), requestConfig.getSocketTimeout());
+ assertEquals(TWO_SECOND_TIMEOUT.toMillis(), requestConfig.getConnectTimeout());
+ assertEquals(TWO_SECOND_TIMEOUT.toMillis(), requestConfig.getConnectionRequestTimeout());
verify(clientBuilderMock).build();
verifyNoMoreInteractions(clientBuilderMock);