diff options
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt b/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt index e710fd973..a0bbceea1 100644 --- a/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt +++ b/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt @@ -2,17 +2,33 @@ package org.onap.vid.logging -import org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID +import org.onap.portalsdk.core.util.SystemProperties +import org.onap.vid.logging.RequestIdHeader.* import javax.servlet.http.HttpServletRequest +enum class RequestIdHeader(val headerName: String) { + + ONAP_ID("X-ONAP-RequestID"), + REQUEST_ID("X-RequestID"), + TRANSACTION_ID("X-TransactionID"), + ECOMP_ID(SystemProperties.ECOMP_REQUEST_ID), + ; + + fun stringEquals(header: String) = headerName.equals(header, true) + + fun getHeaderValue(request: HttpServletRequest): String? = request.getHeader(headerName) +} + fun prioritizedRequestIdHeaders() = listOf( - "X-ONAP-RequestID", - "X-RequestID", - "X-TransactionID", - ECOMP_REQUEST_ID + ONAP_ID, + REQUEST_ID, + TRANSACTION_ID, + ECOMP_ID ) -fun highestPriorityHeader(httpRequest: HttpServletRequest): String? { - val headers = httpRequest.headerNames.asSequence().toSet().map { it.toUpperCase() } - return prioritizedRequestIdHeaders().firstOrNull { headers.contains(it.toUpperCase()) } +fun highestPriorityHeader(httpRequest: HttpServletRequest): RequestIdHeader? { + val headers = httpRequest.headerNames.asSequence().toSet() + return prioritizedRequestIdHeaders().firstOrNull { + requestIdHeader -> headers.any { requestIdHeader.stringEquals(it) } + } } |