aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-09-22 20:25:08 +0300
committerIttay Stern <ittay.stern@att.com>2019-09-22 20:25:08 +0300
commit5a824bbfbe95afd3b1fbaae8c029a8b4c5ad5401 (patch)
tree85524a7e7b0a98fec29fec278ffbf44641f0b9f6
parent15eeb03b12f2c8afd34c38ffad9f2d3a30e4af23 (diff)
Remove injections from filter, as filter is not Spring-controlled
Change-Id: Iecb4d6fbb79c5920d088fe536e6622690f8f881e Issue-ID: VID-253 Signed-off-by: Ittay Stern <ittay.stern@att.com>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseRequestIdFilter.java8
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt24
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/filter/PromiseRequestIdFilterTest.java4
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java4
4 files changed, 14 insertions, 26 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 c0fc96e03..ac93d8751 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
@@ -58,12 +58,6 @@ public class PromiseRequestIdFilter extends GenericFilterBean {
private static final Pattern uuidRegex = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", Pattern.CASE_INSENSITIVE);
- private final Headers headers;
-
- public PromiseRequestIdFilter(Headers headers) {
- this.headers = headers;
- }
-
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
@@ -118,7 +112,7 @@ public class PromiseRequestIdFilter extends GenericFilterBean {
}
String highestPriorityHeader(HttpServletRequest httpRequest) {
- return defaultIfNull(headers.highestPriorityHeader(httpRequest), PROMISED_HEADER_NAME);
+ return defaultIfNull(Headers.highestPriorityHeader(httpRequest), PROMISED_HEADER_NAME);
}
private static class PromiseRequestIdRequestWrapper extends HttpServletRequestWrapper {
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 cc5ebf38c..e710fd973 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
@@ -1,20 +1,18 @@
+@file:JvmName("Headers")
+
package org.onap.vid.logging
import org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID
-import org.springframework.stereotype.Component
import javax.servlet.http.HttpServletRequest
-@Component
-class Headers {
- fun prioritizedRequestIdHeaders() = listOf(
- "X-ONAP-RequestID",
- "X-RequestID",
- "X-TransactionID",
- ECOMP_REQUEST_ID
- )
+fun prioritizedRequestIdHeaders() = listOf(
+ "X-ONAP-RequestID",
+ "X-RequestID",
+ "X-TransactionID",
+ ECOMP_REQUEST_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): String? {
+ val headers = httpRequest.headerNames.asSequence().toSet().map { it.toUpperCase() }
+ return prioritizedRequestIdHeaders().firstOrNull { headers.contains(it.toUpperCase()) }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/filter/PromiseRequestIdFilterTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/filter/PromiseRequestIdFilterTest.java
index a1d15f543..5f80e04a0 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/filter/PromiseRequestIdFilterTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/filter/PromiseRequestIdFilterTest.java
@@ -52,7 +52,6 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.onap.portalsdk.core.web.support.UserUtils;
-import org.onap.vid.logging.Headers;
import org.springframework.mock.web.MockHttpServletResponse;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -68,8 +67,7 @@ public class PromiseRequestIdFilterTest {
private static final String transactionIdHeader = "x-transactionid";
private static final String requestIdHeader = "x-requestid";
- private final PromiseRequestIdFilter promiseRequestIdFilter =
- new PromiseRequestIdFilter(new Headers());
+ private final PromiseRequestIdFilter promiseRequestIdFilter = new PromiseRequestIdFilter();
@Test
public void givenRequestIdHeader_headerValueNotChanged() throws IOException, ServletException {
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 3ea025870..ac05ea706 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
@@ -51,7 +51,6 @@ import org.onap.vid.aai.util.AAIRestInterface;
import org.onap.vid.aai.util.ServletRequestHelper;
import org.onap.vid.aai.util.SystemPropertyHelper;
import org.onap.vid.controller.filter.PromiseRequestIdFilter;
-import org.onap.vid.logging.Headers;
import org.onap.vid.testUtils.TestUtils;
import org.onap.vid.utils.Logging;
import org.onap.vid.utils.Unchecked;
@@ -66,8 +65,7 @@ import org.testng.annotations.Test;
public class OutgoingRequestHeadersTest {
- private static final PromiseRequestIdFilter promiseRequestIdFilter =
- new PromiseRequestIdFilter(new Headers());
+ private static final PromiseRequestIdFilter promiseRequestIdFilter = new PromiseRequestIdFilter();
// @InjectMocks
// private RestMsoImplementation restMsoImplementation;