summaryrefslogtreecommitdiffstats
path: root/datafile-app-server/src/main/java
diff options
context:
space:
mode:
authorRehanRaza <muhammad.rehan.raza@est.tech>2019-05-13 14:02:39 +0000
committerRehanRaza <muhammad.rehan.raza@est.tech>2019-05-13 14:02:39 +0000
commit75d51a299e7d36cb988ef074fce00eb4b29a3394 (patch)
treece2c20f9d24c30822473098556991dec39f58490 /datafile-app-server/src/main/java
parent0e7fe2901b830841efb9d575c14c6c7ada7c7e0f (diff)
Bugfix: add MDC context to http redirect logs
Change-Id: Icdf00480eed43536a8b4693cbb208560f0881c95 Issue-ID: DCAEGEN2-1462 Signed-off-by: RehanRaza <muhammad.rehan.raza@est.tech>
Diffstat (limited to 'datafile-app-server/src/main/java')
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java9
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategy.java14
2 files changed, 18 insertions, 5 deletions
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java
index c61b7a4d..8d433827 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java
@@ -85,7 +85,7 @@ public class DmaapProducerHttpClient {
public HttpResponse getDmaapProducerResponseWithRedirect(HttpUriRequest request, Map<String, String> contextMap)
throws DatafileTaskException {
MDC.setContextMap(contextMap);
- try (CloseableHttpAsyncClient webClient = createWebClient(true, DEFAULT_REQUEST_TIMEOUT)) {
+ try (CloseableHttpAsyncClient webClient = createWebClient(true, DEFAULT_REQUEST_TIMEOUT, contextMap)) {
webClient.start();
logger.trace(INVOKE, "Starting to produce to DR {}", request);
@@ -112,7 +112,7 @@ public class DmaapProducerHttpClient {
public HttpResponse getDmaapProducerResponseWithCustomTimeout(HttpUriRequest request, Duration requestTimeout,
Map<String, String> contextMap) throws DatafileTaskException {
MDC.setContextMap(contextMap);
- try (CloseableHttpAsyncClient webClient = createWebClient(false, requestTimeout)) {
+ try (CloseableHttpAsyncClient webClient = createWebClient(false, requestTimeout, contextMap)) {
webClient.start();
logger.trace(INVOKE, "Starting to produce to DR {}", request);
@@ -152,7 +152,8 @@ public class DmaapProducerHttpClient {
.port(configuration.dmaapPortNumber());
}
- private CloseableHttpAsyncClient createWebClient(boolean expectRedirect, Duration requestTimeout)
+ private CloseableHttpAsyncClient createWebClient(boolean expectRedirect, Duration requestTimeout,
+ Map<String, String> contextMap)
throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
SSLContext sslContext =
new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build();
@@ -162,7 +163,7 @@ public class DmaapProducerHttpClient {
.setSslHostnameVerifier(new NoopHostnameVerifier());
if (expectRedirect) {
- clientBuilder.setRedirectStrategy(PublishRedirectStrategy.INSTANCE);
+ clientBuilder.setRedirectStrategy(new PublishRedirectStrategy(contextMap));
}
if (requestTimeout.toMillis() > 0) {
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategy.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategy.java
index de07461c..3ceec627 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategy.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategy.java
@@ -17,6 +17,7 @@
package org.onap.dcaegen2.collectors.datafile.web;
import java.net.URI;
+import java.util.Map;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolException;
@@ -33,6 +34,7 @@ import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.protocol.HttpContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
/**
* PublishRedirectStrategy implementation
@@ -44,8 +46,17 @@ import org.slf4j.LoggerFactory;
@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class PublishRedirectStrategy extends DefaultRedirectStrategy {
- public static final PublishRedirectStrategy INSTANCE = new PublishRedirectStrategy();
private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private final Map<String, String> contextMap;
+
+ /**
+ * Constructor PublishRedirectStrategy.
+ *
+ * @param contextMap - MDC context map
+ */
+ public PublishRedirectStrategy(Map<String, String> contextMap) {
+ this.contextMap = contextMap;
+ }
/**
* Redirectable methods.
@@ -71,6 +82,7 @@ public class PublishRedirectStrategy extends DefaultRedirectStrategy {
@Override
public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context)
throws ProtocolException {
+ MDC.setContextMap(contextMap);
final URI uri = getLocationURI(request, response, context);
logger.trace("getRedirect...: {}", request);
return RequestBuilder.copy(request).setUri(uri).build();