diff options
author | Amichai Hemli <amichai.hemli@intl.att.com> | 2019-10-02 22:20:15 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-10-02 22:20:15 +0000 |
commit | ab9cd4374e918187907e19a57585bc57b72f1bc7 (patch) | |
tree | b142fb1a35f4cdb4181330a2715a11e5bde7ef4a /vid-app-common | |
parent | 7dec4b0af4e9600fdced7e1228996339ee5bf35f (diff) | |
parent | ea46d04a9bc5569bd29b83bdeb58f52a88d876c3 (diff) |
Merge "send INVOCATION_ID header via RestMsoImplementation"
Diffstat (limited to 'vid-app-common')
3 files changed, 16 insertions, 6 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 b2969feb2..e9f83ef22 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 @@ -4,6 +4,7 @@ package org.onap.vid.logging import org.onap.portalsdk.core.util.SystemProperties import org.onap.vid.logging.RequestIdHeader.* +import java.util.* import javax.servlet.http.HttpServletRequest interface Header { @@ -20,6 +21,11 @@ val PARTNER_NAME = object : NamedHeader("X-ONAP-PartnerName") { override fun getHeaderValue() = "VID.VID" } +@JvmField +val INVOCATION_ID = object : NamedHeader("X-InvocationID") { + override fun getHeaderValue() = UUID.randomUUID().toString() +} + enum class RequestIdHeader(override val headerName: String) : Header { ONAP_ID("X-ONAP-RequestID"), REQUEST_ID("X-RequestID"), diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java index 3497b4ad3..ae04dbcfd 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java @@ -20,6 +20,7 @@ package org.onap.vid.mso; +import static org.onap.vid.logging.Headers.INVOCATION_ID; import static org.onap.vid.logging.Headers.PARTNER_NAME; import static org.onap.vid.utils.Logging.ONAP_REQUEST_ID_HEADER_KEY; import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY; @@ -115,7 +116,7 @@ public class RestMsoImplementation implements RestInterface { String requestIdValue = Logging.extractOrGenerateRequestId(); commonHeaders.put(REQUEST_ID_HEADER_KEY, Collections.singletonList(requestIdValue)); commonHeaders.put(ONAP_REQUEST_ID_HEADER_KEY, Collections.singletonList(requestIdValue)); - + commonHeaders.put(INVOCATION_ID.getHeaderName(), Collections.singletonList(INVOCATION_ID.getHeaderValue())); boolean useSsl = true; if ( (mso_url != null) && ( !(mso_url.isEmpty()) ) ) { diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java index 01e484f4b..8c5634fbe 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java @@ -143,7 +143,7 @@ public class OutgoingRequestHeadersTest { Invocation.Builder fakeBuilder = mocks.getFakeBuilder(); Object requestIdValue = verifyXEcompRequestIdHeaderWasAdded(fakeBuilder); assertEquals(requestIdValue, captureHeaderKeyAndReturnItsValue(fakeBuilder, "X-ONAP-RequestID")); - + assertRequestHeaderIsUUID(fakeBuilder, "X-InvocationID"); assertThat((String) captureHeaderKeyAndReturnItsValue(fakeBuilder, "Authorization"), startsWith("Basic ")); verifyXOnapPartnerNameHeaderWasAdded(fakeBuilder); } @@ -192,12 +192,15 @@ public class OutgoingRequestHeadersTest { private Object verifyXEcompRequestIdHeaderWasAdded(Invocation.Builder fakeBuilder) { final String requestIdHeader = "x-ecomp-requestid"; - final String uuidRegex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"; - Object requestId = captureHeaderKeyAndReturnItsValue(fakeBuilder, requestIdHeader); + return assertRequestHeaderIsUUID(fakeBuilder, requestIdHeader); + } - assertThat("header '" + requestIdHeader + "' should be a uuid", requestId, + private Object assertRequestHeaderIsUUID(Invocation.Builder fakeBuilder, String headerName) { + Object headerValue = captureHeaderKeyAndReturnItsValue(fakeBuilder, headerName); + final String uuidRegex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"; + assertThat("header '" + headerName + "' should be a uuid", headerValue, allOf(instanceOf(String.class), hasToString(matchesPattern(uuidRegex)))); - return requestId; + return headerValue; } private void verifyXOnapPartnerNameHeaderWasAdded(Invocation.Builder fakeBuilder) { |