aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2020-01-20 21:46:47 +0200
committerIttay Stern <ittay.stern@att.com>2020-01-23 09:01:17 +0000
commit1420dc4929d35ff6ac3f944b931ad600d061dc4e (patch)
tree8c2d7207a5e131f8c301ffbe18c92aec3b04a13f /vid-app-common/src/main
parent65e0c52538423d50b3405daa57ffa6f49c6fa2c3 (diff)
Promise Request-id header: Check MDC value if no header
Issue-ID: VID-647 Change-Id: I9ed97742db1f37de68bfcf1b9cd58afc996da7bf Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java b/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java
index faaf55ae7..1c96819c8 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java
@@ -41,8 +41,10 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
+import org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs;
import org.onap.vid.logging.Headers;
import org.onap.vid.logging.RequestIdHeader;
+import org.slf4j.MDC;
import org.springframework.web.filter.GenericFilterBean;
@WebFilter(urlPatterns = "/*")
@@ -82,12 +84,17 @@ public class PromiseRequestIdFilter extends GenericFilterBean {
if (isWrapNeeded(highestPriorityHeader, originalRequestId)) {
// Copy originalRequestId to the promised header value
- request = new PromiseRequestIdRequestWrapper(httpRequest, toUuidOrElse(originalRequestId, UUID::randomUUID));
+ request = new PromiseRequestIdRequestWrapper(httpRequest,
+ firstValidUuidOrElse(originalRequestId, requestIdFromMDC(), UUID::randomUUID));
}
return request;
}
+ private String requestIdFromMDC() {
+ return MDC.get(MDCs.REQUEST_ID);
+ }
+
private boolean verifyAndValidateUuid(String value) {
return isNotEmpty(value) && uuidRegex.matcher(value).matches();
}
@@ -99,6 +106,10 @@ public class PromiseRequestIdFilter extends GenericFilterBean {
return !headerExistsAndValid;
}
+ UUID firstValidUuidOrElse(String uuid1, String uuid2, Supplier<UUID> uuidSupplier) {
+ return toUuidOrElse(uuid1, () -> toUuidOrElse(uuid2, uuidSupplier));
+ }
+
UUID toUuidOrElse(String uuid, Supplier<UUID> uuidSupplier) {
if (verifyAndValidateUuid(uuid)) {
try {