allow RestClient to configure custom headers 01/117201/3
authorBenjamin, Max (mb388a) <mb388a@att.com>
Thu, 28 Jan 2021 18:12:40 +0000 (13:12 -0500)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Mon, 1 Feb 2021 22:45:32 +0000 (17:45 -0500)
allow RestClient to configure custom headers
always load the first implementation on the classpath

Issue-ID: SO-3495
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I9c433cdaed33a7db6182af259421676c088a1fae

23 files changed:
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmRestClient.java
common/src/main/java/org/onap/so/client/HttpClient.java
common/src/main/java/org/onap/so/client/RestClient.java
common/src/main/java/org/onap/so/client/RestProperties.java
common/src/main/java/org/onap/so/client/RestPropertiesLoader.java
common/src/main/java/org/onap/so/client/RestRequest.java
common/src/main/java/org/onap/so/client/adapter/rest/AdapterRestClient.java
common/src/main/java/org/onap/so/client/dmaap/rest/DMaaPRestClient.java
common/src/main/java/org/onap/so/client/grm/GRMRestClient.java
common/src/main/java/org/onap/so/client/policy/PolicyRestClient.java
common/src/test/java/org/onap/so/client/RestClientTest.java
common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java
common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java
common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIClient.java
graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIDSLQueryClient.java
graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClient.java
graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryClient.java
graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryRestClient.java
graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIDSLQueryClientTest.java
graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIRestClientTest.java
mso-api-handlers/mso-api-handler-infra/pom.xml
pom.xml

index 3faf58e..85d67a8 100644 (file)
 package org.onap.so.client.sdnc.lcm;
 
 import java.net.URI;
-import java.util.Map;
 import java.util.Optional;
-import org.onap.so.client.RestClient;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
 import org.onap.logging.filter.base.ONAPComponents;
+import org.onap.so.client.RestClient;
 import org.onap.so.client.sdnc.lcm.beans.LcmInput;
 import org.onap.so.client.sdnc.lcm.beans.LcmOutput;
 import org.onap.so.client.sdnc.lcm.beans.LcmRestRequest;
@@ -44,8 +45,8 @@ public class SDNCLcmRestClient extends RestClient {
     }
 
     @Override
-    protected void initializeHeaderMap(Map<String, String> headerMap) {
-        headerMap.put("Authorization", sdncLcmProperties.getBasicAuth());
+    protected void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap) {
+        headerMap.add("ALL", Pair.with("Authorization", sdncLcmProperties.getBasicAuth()));
     }
 
     @Override
index eaeb0ab..0420ab2 100644 (file)
 
 package org.onap.so.client;
 
+import static org.apache.commons.lang3.StringUtils.isNotBlank;
 import java.net.URL;
-import java.util.Map;
 import java.util.Optional;
-import static org.apache.commons.lang3.StringUtils.*;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
 import org.onap.logging.filter.base.ONAPComponentsList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,7 +50,7 @@ public class HttpClient extends RestClient {
     }
 
     @Override
-    protected void initializeHeaderMap(Map<String, String> headerMap) {}
+    protected void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap) {}
 
     @Override
     protected Optional<ResponseExceptionMapper> addResponseExceptionMapper() {
@@ -79,7 +80,7 @@ public class HttpClient extends RestClient {
     public void addAdditionalHeader(String name, String value) {
         try {
             if (isNotBlank(name) && isNotBlank(value)) {
-                headerMap.put(name, value);
+                headerMap.add("ALL", Pair.with(name, value));
             } else {
                 log.warn("Not adding " + name + " to headers.");
             }
index f201c7c..d1b4c2b 100644 (file)
@@ -29,10 +29,7 @@ import java.security.GeneralSecurityException;
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Base64;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Predicate;
@@ -43,9 +40,12 @@ import javax.ws.rs.client.ResponseProcessingException;
 import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriBuilder;
+import org.javatuples.Pair;
 import org.onap.logging.filter.base.MDCSetup;
 import org.onap.logging.filter.base.ONAPComponentsList;
 import org.onap.logging.filter.base.PayloadLoggingClientFilter;
@@ -67,7 +67,7 @@ public abstract class RestClient {
     private static final int MAX_PAYLOAD_SIZE = 1024 * 1024;
     private WebTarget webTarget;
 
-    protected final Map<String, String> headerMap;
+    protected final MultivaluedMap<String, Pair<String, String>> headerMap;
     protected final Logger logger = LoggerFactory.getLogger(RestClient.class);
     protected URL host;
     protected Optional<URI> path;
@@ -80,7 +80,7 @@ public abstract class RestClient {
 
     protected RestClient(RestProperties props, Optional<URI> path) {
 
-        headerMap = new HashMap<>();
+        headerMap = new MultivaluedHashMap<>();
         try {
             host = props.getEndpoint();
         } catch (MalformedURLException e) {
@@ -99,7 +99,7 @@ public abstract class RestClient {
     }
 
     protected RestClient(URL host, String contentType) {
-        headerMap = new HashMap<>();
+        headerMap = new MultivaluedHashMap<>();
         this.path = Optional.empty();
         this.host = host;
         this.contentType = contentType;
@@ -107,7 +107,7 @@ public abstract class RestClient {
     }
 
     protected RestClient(URL host, String acceptType, String contentType) {
-        headerMap = new HashMap<>();
+        headerMap = new MultivaluedHashMap<>();
         this.path = Optional.empty();
         this.host = host;
         this.accept = acceptType;
@@ -133,15 +133,23 @@ public abstract class RestClient {
         return MAX_PAYLOAD_SIZE;
     }
 
-    protected Builder getBuilder() {
+    protected Builder getBuilder(String method) {
 
         if (webTarget == null) {
             initializeClient(getClient());
         }
         Builder builder = webTarget.request();
         initializeHeaderMap(headerMap);
-        for (Entry<String, String> entry : headerMap.entrySet()) {
-            builder.header(entry.getKey(), entry.getValue());
+        if (headerMap.containsKey("ALL")) {
+            for (Pair<String, String> pair : headerMap.get("ALL")) {
+                builder.header(pair.getValue0(), pair.getValue1());
+            }
+        }
+
+        if (headerMap.containsKey(method)) {
+            for (Pair<String, String> pair : headerMap.get(method)) {
+                builder.header(pair.getValue0(), pair.getValue1());
+            }
         }
         return builder;
     }
@@ -150,7 +158,7 @@ public abstract class RestClient {
         return this.webTarget;
     }
 
-    protected abstract void initializeHeaderMap(Map<String, String> headerMap);
+    protected abstract void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap);
 
     protected Optional<ResponseExceptionMapper> addResponseExceptionMapper() {
         return Optional.of(new ResponseExceptionMapperImpl());
@@ -170,7 +178,7 @@ public abstract class RestClient {
         try {
             byte[] decryptedAuth = CryptoUtils.decrypt(auth, key).getBytes();
             String authHeaderValue = "Basic " + Base64.getEncoder().encodeToString(decryptedAuth);
-            headerMap.put("Authorization", authHeaderValue);
+            headerMap.add("ALL", Pair.with("Authorization", authHeaderValue));
         } catch (GeneralSecurityException e) {
             logger.error(e.getMessage(), e);
         }
index 79e006b..d1cf77b 100644 (file)
@@ -22,6 +22,9 @@ package org.onap.so.client;
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
 
 public interface RestProperties {
 
@@ -66,4 +69,8 @@ public interface RestProperties {
     public default CacheProperties getCacheProperties() {
         return new CacheProperties() {};
     }
+
+    public default MultivaluedMap<String, Pair<String, String>> additionalHeaders() {
+        return new MultivaluedHashMap<>();
+    }
 }
index efb50cf..952c8de 100644 (file)
@@ -62,9 +62,9 @@ public class RestPropertiesLoader {
             if (clazz.isAssignableFrom(item.getClass())) {
                 try {
                     if (forceNewInstance) {
-                        result = (T) item.getClass().newInstance();
+                        return (T) item.getClass().newInstance();
                     } else {
-                        result = (T) item;
+                        return (T) item;
                     }
                 } catch (InstantiationException | IllegalAccessException e) {
                     /*
index 9e6e818..0a1be75 100644 (file)
@@ -49,23 +49,23 @@ public class RestRequest implements CheckedSupplier<Response> {
     public Response get() throws Exception {
         final Response response;
         if ("GET".equals(method)) {
-            response = this.client.getBuilder().accept(this.client.getAccept()).get();
+            response = this.client.getBuilder(method).accept(this.client.getAccept()).get();
         } else if ("POST".equals(method)) {
-            response = this.client.getBuilder().accept(this.client.getAccept())
+            response = this.client.getBuilder(method).accept(this.client.getAccept())
                     .post(Entity.entity(entity, this.client.getContentType()));
         } else if ("PATCH".equals(method)) {
-            response = this.client.getBuilder().header("X-HTTP-Method-Override", "PATCH")
+            response = this.client.getBuilder(method).header("X-HTTP-Method-Override", "PATCH")
                     .accept(this.client.getAccept()).post(Entity.entity(entity, this.client.getMergeContentType()));
         } else if ("DELETE".equals(method)) {
             if (entity == null) {
-                response = this.client.getBuilder().accept(this.client.getAccept()).delete();
+                response = this.client.getBuilder(method).accept(this.client.getAccept()).delete();
 
             } else {
-                response = this.client.getBuilder().accept(this.client.getAccept())
+                response = this.client.getBuilder(method).accept(this.client.getAccept())
                         .build(HttpMethod.DELETE, Entity.entity(entity, this.client.getContentType())).invoke();
             }
         } else if ("PUT".equals(method)) {
-            response = this.client.getBuilder().accept(this.client.getAccept())
+            response = this.client.getBuilder(method).accept(this.client.getAccept())
                     .put(Entity.entity(entity, this.client.getContentType()));
         } else {
             response = Response.serverError().entity(method + " not valid").build();
index 88899a7..3bac3dc 100644 (file)
@@ -22,14 +22,15 @@ package org.onap.so.client.adapter.rest;
 
 import java.net.URI;
 import java.security.GeneralSecurityException;
-import java.util.Map;
 import java.util.Optional;
+import javax.ws.rs.core.MultivaluedMap;
 import org.apache.commons.codec.binary.Base64;
+import org.javatuples.Pair;
+import org.onap.logging.filter.base.ONAPComponents;
 import org.onap.so.client.RestClient;
 import org.onap.so.client.policy.CommonObjectMapperProvider;
 import org.onap.so.client.policy.JettisonStyleMapperProvider;
 import org.onap.so.utils.CryptoUtils;
-import org.onap.logging.filter.base.ONAPComponents;
 
 public class AdapterRestClient extends RestClient {
 
@@ -51,9 +52,9 @@ public class AdapterRestClient extends RestClient {
     }
 
     @Override
-    protected void initializeHeaderMap(Map<String, String> headerMap) {
-        headerMap.put("Authorization",
-                this.getBasicAuth(adapterRestProperties.getAuth(), adapterRestProperties.getKey()));
+    protected void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap) {
+        headerMap.add("ALL", Pair.with("Authorization",
+                this.getBasicAuth(adapterRestProperties.getAuth(), adapterRestProperties.getKey())));
     }
 
     @Override
index e0c8d4b..85417e0 100644 (file)
 package org.onap.so.client.dmaap.rest;
 
 import java.net.URL;
-import java.util.Map;
 import java.util.UUID;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
+import org.onap.logging.filter.base.ONAPComponents;
 import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.onap.so.client.RestClient;
 import org.onap.logging.filter.base.ONAPComponents;
@@ -46,14 +48,15 @@ public class DMaaPRestClient extends RestClient {
     }
 
     @Override
-    protected void initializeHeaderMap(Map<String, String> headerMap) {
+    protected void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap) {
         if (auth != null && !auth.isEmpty() && key != null && !key.isEmpty()) {
             addBasicAuthHeader(auth, key);
         }
         String onapRequestId = UUID.randomUUID().toString();
-        headerMap.put(ONAPLogConstants.Headers.REQUEST_ID, onapRequestId);
+        headerMap.add("ALL", Pair.with(ONAPLogConstants.Headers.REQUEST_ID, onapRequestId));
         if (MDC.get(ONAPLogConstants.MDCs.REQUEST_ID) != null) {
-            headerMap.put(ONAPLogConstants.Headers.INVOCATION_ID, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
+            headerMap.add("ALL",
+                    Pair.with(ONAPLogConstants.Headers.INVOCATION_ID, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)));
         }
     }
 }
index 147f688..cf73a57 100644 (file)
@@ -22,10 +22,11 @@ package org.onap.so.client.grm;
 
 
 import java.net.URI;
-import java.util.Map;
 import java.util.Optional;
-import org.onap.so.client.RestClient;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
 import org.onap.logging.filter.base.ONAPComponents;
+import org.onap.so.client.RestClient;
 
 public class GRMRestClient extends RestClient {
 
@@ -42,7 +43,7 @@ public class GRMRestClient extends RestClient {
     }
 
     @Override
-    protected void initializeHeaderMap(Map<String, String> headerMap) {
+    protected void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap) {
         String auth = properties.getAuth();
         String key = properties.getKey();
 
index 33ece07..f657c17 100644 (file)
 package org.onap.so.client.policy;
 
 
-import java.util.Map;
 import java.util.Optional;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriBuilder;
+import org.javatuples.Pair;
+import org.onap.logging.filter.base.ONAPComponents;
 import org.onap.so.client.RestClient;
 import org.onap.so.client.policy.entities.PolicyServiceType;
-import org.onap.logging.filter.base.ONAPComponents;
 
 public class PolicyRestClient extends RestClient {
 
@@ -43,10 +44,10 @@ public class PolicyRestClient extends RestClient {
     }
 
     @Override
-    protected void initializeHeaderMap(Map<String, String> headerMap) {
-        headerMap.put("ClientAuth", properties.getClientAuth());
-        headerMap.put("Authorization", properties.getAuth());
-        headerMap.put("Environment", properties.getEnvironment());
+    protected void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap) {
+        headerMap.add("ALL", Pair.with("ClientAuth", properties.getClientAuth()));
+        headerMap.add("ALL", Pair.with("Authorization", properties.getAuth()));
+        headerMap.add("ALL", Pair.with("Environment", properties.getEnvironment()));
     }
 
 }
index 57abf87..3bf4ccf 100644 (file)
@@ -33,13 +33,14 @@ import java.net.SocketTimeoutException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.Map;
 import java.util.Optional;
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.ProcessingException;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriBuilderException;
+import org.javatuples.Pair;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -126,7 +127,7 @@ public class RestClientTest {
         RestClient client = new RestClient(props, Optional.of(new URI("/chunked/delayed"))) {
 
             @Override
-            protected void initializeHeaderMap(Map<String, String> headerMap) {
+            protected void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap) {
                 // TODO Auto-generated method stub
 
             }
index 5075da3..964707a 100644 (file)
 package org.onap.so.client.adapter.rest;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.security.GeneralSecurityException;
-import java.util.HashMap;
-import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
 import org.apache.commons.codec.binary.Base64;
+import org.javatuples.Pair;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.logging.filter.base.ONAPComponents;
 import org.onap.so.client.policy.JettisonStyleMapperProvider;
 import org.onap.so.utils.CryptoUtils;
-import org.onap.logging.filter.base.ONAPComponents;
 
 public class AdapterRestClientTest {
 
     private static final String CRYPTO_KEY = "546573746F736973546573746F736973";
     private static final String INVALID_CRYPTO_KEY = "1234";
 
-    private Map<String, String> headerMap;
+    private MultivaluedMap<String, Pair<String, String>> headerMap;
     private AdapterRestProperties adapterRestPropertiesMock;
 
     @Before
     public void setup() {
-        headerMap = new HashMap<>();
+        headerMap = new MultivaluedHashMap<>();
+
         adapterRestPropertiesMock = mock(AdapterRestProperties.class);
     }
 
@@ -60,7 +61,8 @@ public class AdapterRestClientTest {
         // when
         testedObject.initializeHeaderMap(headerMap);
         // then
-        assertThat(headerMap).containsOnly(entry("Authorization", getExpectedEncodedString(encyptedMessage)));
+        assertThat(headerMap.get("ALL"))
+                .containsOnly(Pair.with("Authorization", getExpectedEncodedString(encyptedMessage)));
     }
 
     @Test
@@ -70,7 +72,7 @@ public class AdapterRestClientTest {
         // when
         testedObject.initializeHeaderMap(headerMap);
         // then
-        assertThat(headerMap).containsOnly(entry("Authorization", null));
+        assertThat(headerMap.get("ALL")).containsOnly(Pair.with("Authorization", null));
     }
 
     @Test
@@ -84,7 +86,7 @@ public class AdapterRestClientTest {
         // when
         testedObject.initializeHeaderMap(headerMap);
         // then
-        assertThat(headerMap).containsOnly(entry("Authorization", null));
+        assertThat(headerMap.get("ALL")).containsOnly(Pair.with("Authorization", null));
     }
 
     @Test
index ca5b5da..4f00b9d 100644 (file)
@@ -24,8 +24,9 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
 import org.junit.Test;
 import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.slf4j.MDC;
@@ -48,11 +49,12 @@ public class DMaaPRestClientTest {
             throw new RuntimeException(e);
         }
         DMaaPRestClient client = new DMaaPRestClient(url, contentType, auth, key);
-        Map<String, String> map = new HashMap<>();
+        MultivaluedMap<String, Pair<String, String>> map = new MultivaluedHashMap<>();
         client.initializeHeaderMap(map);
-        map.put(ONAPLogConstants.MDCs.REQUEST_ID, "1234");
+        map.add("ALL", Pair.with(ONAPLogConstants.MDCs.REQUEST_ID, "1234"));
         assertNotNull(map);
-        assertEquals("Found expected RequesttId", "1234", map.get(ONAPLogConstants.MDCs.REQUEST_ID));
+        assertEquals("Found expected RequestId", true,
+                map.get("ALL").contains(Pair.with(ONAPLogConstants.MDCs.REQUEST_ID, "1234")));
 
     }
 
@@ -67,11 +69,12 @@ public class DMaaPRestClientTest {
         }
         MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, "1234");
         DMaaPRestClient client = new DMaaPRestClient(url, contentType, auth, key);
-        Map<String, String> map = new HashMap<>();
+        MultivaluedMap<String, Pair<String, String>> map = new MultivaluedHashMap<>();
         client.initializeHeaderMap(map);
 
         assertNotNull(map);
-        assertEquals("Found expected RequestId", "1234", map.get(ONAPLogConstants.Headers.INVOCATION_ID));
+        assertEquals("Found expected RequestId", true,
+                map.get("ALL").contains(Pair.with(ONAPLogConstants.Headers.INVOCATION_ID, "1234")));
 
     }
 
@@ -87,11 +90,12 @@ public class DMaaPRestClientTest {
 
         MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, null);
         DMaaPRestClient client = new DMaaPRestClient(url, contentType, auth, key);
-        Map<String, String> map = new HashMap<>();
+        MultivaluedMap<String, Pair<String, String>> map = new MultivaluedHashMap<>();
         client.initializeHeaderMap(map);
 
         assertNotNull(map);
-        assertEquals("header not found as expected", null, map.get(ONAPLogConstants.Headers.INVOCATION_ID));
+        assertEquals("header not found as expected", false,
+                map.get("ALL").contains(Pair.with(ONAPLogConstants.Headers.INVOCATION_ID, "1234")));
 
     }
 }
index 3323fd8..f9547cb 100644 (file)
 package org.onap.so.client.policy;
 
 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.isA;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.assertj.core.api.Assertions.assertThat;
 import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -56,10 +57,10 @@ import org.onap.so.client.policy.entities.PolicyConfig;
 import org.onap.so.client.policy.entities.PolicyDecision;
 import org.onap.so.client.policy.entities.PolicyDecisionRequest;
 import org.onap.so.client.policy.entities.PolicyServiceType;
+import org.onap.so.client.policy.entities.Workstep;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
-import org.onap.so.client.policy.entities.Workstep;
 
 public class PolicyClientImplTest {
 
@@ -79,11 +80,13 @@ public class PolicyClientImplTest {
     @Test
     public void successReadProperties() {
         PolicyRestClient client = new PolicyRestClient(new PolicyRestPropertiesImpl(), PolicyServiceType.GET_DECISION);
-        Map<String, String> map = new HashMap<>();
+        MultivaluedMap<String, Pair<String, String>> map = new MultivaluedHashMap<>();
         client.initializeHeaderMap(map);
-        assertEquals("Found expected Client Auth", "Basic bTAzNzQzOnBvbGljeVIwY2sk", map.get("ClientAuth"));
-        assertEquals("Found expected Authorization", "Basic dGVzdHBkcDphbHBoYTEyMw==", map.get("Authorization"));
-        assertEquals("Found expected Environment", "TEST", map.get("Environment"));
+        assertTrue("Found expected Client Auth",
+                map.get("ALL").contains(Pair.with("ClientAuth", "Basic bTAzNzQzOnBvbGljeVIwY2sk")));
+        assertTrue("Found expected Authorization",
+                map.get("ALL").contains(Pair.with("Authorization", "Basic dGVzdHBkcDphbHBoYTEyMw==")));
+        assertTrue("Found expected Environment", map.get("ALL").contains(Pair.with("Environment", "TEST")));
     }
 
     @Test
index 1f747e6..fc5ef86 100644 (file)
 package org.onap.aaiclient.client.aai;
 
 import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
 import javax.ws.rs.NotFoundException;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriBuilder;
+import org.javatuples.Pair;
 import org.onap.aaiclient.client.graphinventory.GraphInventoryClient;
 import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriComputationException;
 import org.onap.so.client.RestClient;
@@ -38,19 +39,19 @@ public class AAIClient extends GraphInventoryClient {
     protected AAIVersion version;
 
     protected AAIClient() {
-        super(AAIProperties.class, new HashMap<String, String>());
+        super(AAIProperties.class, new MultivaluedHashMap<>());
     }
 
     protected AAIClient(AAIVersion version) {
-        super(AAIProperties.class, new HashMap<String, String>());
+        super(AAIProperties.class, new MultivaluedHashMap<>());
         this.version = version;
     }
 
-    protected AAIClient(Map<String, String> additionalHeaders) {
+    protected AAIClient(MultivaluedMap<String, Pair<String, String>> additionalHeaders) {
         super(AAIProperties.class, additionalHeaders);
     }
 
-    protected AAIClient(AAIVersion version, Map<String, String> additionalHeaders) {
+    protected AAIClient(AAIVersion version, MultivaluedMap<String, Pair<String, String>> additionalHeaders) {
         super(AAIProperties.class, additionalHeaders);
         this.version = version;
     }
index 8b8707e..d894a0f 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.aaiclient.client.aai;
 
+import javax.ws.rs.core.MultivaluedHashMap;
+import org.javatuples.Pair;
 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
 import org.onap.aaiclient.client.aai.entities.uri.AAIFluentTypeReverseLookup;
 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
@@ -33,11 +35,14 @@ public class AAIDSLQueryClient
         extends GraphInventoryQueryClient<AAIDSLQueryClient, DSLQuery, AAIResultWrapper, AAIObjectType> {
 
     public AAIDSLQueryClient() {
-        super(new AAIClient(ImmutableMap.of("X-DslApiVersion", "V2")));
+        super(new AAIClient(new MultivaluedHashMap<String, Pair<String, String>>(
+                ImmutableMap.of("ALL", Pair.with("X-DslApiVersion", "V2")))));
+
     }
 
     public AAIDSLQueryClient(AAIVersion version) {
-        super(new AAIClient(version, ImmutableMap.of("X-DslApiVersion", "V2")));
+        super(new AAIClient(version, new MultivaluedHashMap<String, Pair<String, String>>(
+                ImmutableMap.of("ALL", Pair.with("X-DslApiVersion", "V2")))));
     }
 
     @Override
index 0f69b0c..df124ef 100644 (file)
@@ -21,8 +21,9 @@
 package org.onap.aaiclient.client.aai;
 
 import java.net.URI;
-import java.util.Map;
 import java.util.Optional;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
 import org.onap.aaiclient.client.graphinventory.GraphInventoryPatchConverter;
 import org.onap.aaiclient.client.graphinventory.GraphInventoryRestClient;
 import org.onap.logging.filter.base.ONAPComponents;
@@ -31,9 +32,10 @@ import org.onap.so.client.ResponseExceptionMapper;
 public class AAIRestClient extends GraphInventoryRestClient {
 
     private final AAIProperties aaiProperties;
-    private final Map<String, String> additionalHeaders;
+    private final MultivaluedMap<String, Pair<String, String>> additionalHeaders;
 
-    protected AAIRestClient(AAIProperties props, URI uri, Map<String, String> additionalHeaders) {
+    protected AAIRestClient(AAIProperties props, URI uri,
+            MultivaluedMap<String, Pair<String, String>> additionalHeaders) {
         super(props, uri);
         this.aaiProperties = props;
         this.additionalHeaders = additionalHeaders;
@@ -45,16 +47,24 @@ public class AAIRestClient extends GraphInventoryRestClient {
     }
 
     @Override
-    protected void initializeHeaderMap(Map<String, String> headerMap) {
-        headerMap.put("X-FromAppId", aaiProperties.getSystemName());
-        headerMap.put("X-TransactionId", requestId);
-        headerMap.putAll(additionalHeaders);
+    protected void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap) {
+        headerMap.add("ALL", Pair.with("X-FromAppId", aaiProperties.getSystemName()));
+        headerMap.add("ALL", Pair.with("X-TransactionId", requestId));
+        additionalHeaders.forEach((k, v) -> {
+            headerMap.addAll(k, v);
+        });
         String auth = aaiProperties.getAuth();
         String key = aaiProperties.getKey();
 
         if (auth != null && !auth.isEmpty() && key != null && !key.isEmpty()) {
             addBasicAuthHeader(auth, key);
         }
+
+        if (!aaiProperties.additionalHeaders().isEmpty()) {
+            aaiProperties.additionalHeaders().forEach((k, v) -> {
+                headerMap.addAll(k, v);
+            });
+        }
     }
 
     @Override
index f8f977d..af875fa 100644 (file)
 package org.onap.aaiclient.client.graphinventory;
 
 import java.net.URI;
-import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
 import org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryUri;
 import org.onap.aaiclient.client.graphinventory.entities.uri.HttpAwareUri;
 import org.onap.so.client.RestClient;
 import org.onap.so.client.RestProperties;
 import org.onap.so.client.RestPropertiesLoader;
-import com.google.common.collect.ImmutableMap;
 
 public abstract class GraphInventoryClient {
 
     private RestProperties props;
-    protected final Map<String, String> additionalHeaders;
+    protected final MultivaluedMap<String, Pair<String, String>> additionalHeaders;
 
     protected GraphInventoryClient(Class<? extends RestProperties> propertiesClass,
-            Map<String, String> additionalHeaders) {
-
+            MultivaluedMap<String, Pair<String, String>> additionalHeaders) {
         RestProperties props = RestPropertiesLoader.getInstance().getNewImpl(propertiesClass);
         this.props = props;
         this.additionalHeaders = additionalHeaders;
@@ -70,7 +70,7 @@ public abstract class GraphInventoryClient {
 
     public abstract String getGraphDBName();
 
-    public Map<String, String> getAdditionalHeaders() {
-        return ImmutableMap.copyOf(this.additionalHeaders);
+    public MultivaluedMap<String, Pair<String, String>> getAdditionalHeaders() {
+        return new MultivaluedHashMap<>(this.additionalHeaders);
     }
 }
index c22f2f5..6ccd1a2 100644 (file)
 package org.onap.aaiclient.client.graphinventory;
 
 import java.net.URI;
-import java.util.Map;
 import java.util.Optional;
 import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
+import org.javatuples.Pair;
 import org.onap.aaiclient.client.CacheControlFeature;
 import org.onap.aaiclient.client.FlushCache;
 import org.onap.logging.filter.base.ONAPComponentsList;
@@ -65,7 +66,7 @@ public abstract class GraphInventoryRestClient extends RestClientSSL {
     public abstract ONAPComponentsList getTargetEntity();
 
     @Override
-    protected abstract void initializeHeaderMap(Map<String, String> headerMap);
+    protected abstract void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap);
 
     @Override
     protected abstract Optional<ResponseExceptionMapper> addResponseExceptionMapper();
index 36fc1db..68858de 100644 (file)
@@ -1,7 +1,8 @@
 package org.onap.aaiclient.client.aai;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import java.net.URISyntaxException;
+import org.javatuples.Pair;
 import org.junit.Test;
 
 public class AAIDSLQueryClientTest {
@@ -12,6 +13,6 @@ public class AAIDSLQueryClientTest {
     public void verifyHeadersTest() throws URISyntaxException {
 
         AAIDSLQueryClient client = new AAIDSLQueryClient();
-        assertEquals("V2", client.getClient().getAdditionalHeaders().get("X-DslApiVersion"));
+        assertTrue(client.getClient().getAdditionalHeaders().get("ALL").contains(Pair.with("X-DslApiVersion", "V2")));
     }
 }
index d0f7847..9b34095 100644 (file)
@@ -43,8 +43,9 @@ import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.HashMap;
+import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.Response;
+import org.javatuples.Pair;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -75,7 +76,7 @@ public class AAIRestClientTest {
 
     @Test
     public void failPatchOnComplexObject() throws URISyntaxException {
-        AAIRestClient client = new AAIRestClient(props, new URI(""), new HashMap<String, String>());
+        AAIRestClient client = new AAIRestClient(props, new URI(""), new MultivaluedHashMap<>());
         this.thrown.expect(GraphInventoryPatchDepthExceededException.class);
         this.thrown.expectMessage(containsString("Object exceeds allowed depth for update action"));
         client.patch(
@@ -84,7 +85,7 @@ public class AAIRestClientTest {
 
     @Test
     public void verifyPatchValidation() throws URISyntaxException {
-        AAIRestClient client = new AAIRestClient(props, new URI(""), new HashMap<String, String>());
+        AAIRestClient client = new AAIRestClient(props, new URI(""), new MultivaluedHashMap<>());
         AAIRestClient spy = spy(client);
         GraphInventoryPatchConverter patchValidatorMock = mock(GraphInventoryPatchConverter.class);
         doReturn(patchValidatorMock).when(spy).getPatchConverter();
@@ -97,11 +98,13 @@ public class AAIRestClientTest {
     @Test
     public void verifyAdditionalHeadersTest() throws URISyntaxException {
         AAIRestClient client = new AAIRestClient(new DefaultAAIPropertiesImpl(wireMockRule.port()), new URI("/test"),
-                ImmutableMap.of("test", "value"));
+                new MultivaluedHashMap<String, Pair<String, String>>(
+                        ImmutableMap.of("ALL", Pair.with("test", "value"), "GET", Pair.with("get test", "value"))));
         wireMockRule.stubFor(get(urlPathEqualTo("/test")).willReturn(aResponse().withStatus(200)));
         client.get();
         wireMockRule.verify(getRequestedFor(urlPathEqualTo("/test")).withHeader("X-FromAppId", equalTo("MSO"))
-                .withHeader("X-TransactionId", matching(".*")).withHeader("test", equalTo("value")));
+                .withHeader("X-TransactionId", matching(".*")).withHeader("test", equalTo("value"))
+                .withHeader("get test", equalTo("value")));
     }
 
 
@@ -145,7 +148,7 @@ public class AAIRestClientTest {
             }
 
         };
-        RestClient client = new AAIRestClient(props, new URI("/cached"), new HashMap<String, String>());
+        RestClient client = new AAIRestClient(props, new URI("/cached"), new MultivaluedHashMap<>());
 
         Response response = client.get();
 
@@ -199,7 +202,7 @@ public class AAIRestClientTest {
 
         };
 
-        RestClient client = new AAIRestClient(props, new URI("/cached/1"), new HashMap<String, String>());
+        RestClient client = new AAIRestClient(props, new URI("/cached/1"), new MultivaluedHashMap<>());
 
 
         Response response = client.get();
index 678de23..b902564 100644 (file)
       </exclusions>
     </dependency>
     <dependency>
-        <groupId>org.onap.aaf.authz</groupId>
-        <artifactId>aaf-auth-client</artifactId>
-        <scope>runtime</scope>
+      <groupId>org.onap.aaf.authz</groupId>
+      <artifactId>aaf-auth-client</artifactId>
+      <scope>runtime</scope>
     </dependency>
     <dependency>
-        <groupId>org.onap.aaf.authz</groupId>
-        <artifactId>aaf-misc-env</artifactId>
-        <scope>runtime</scope>
+      <groupId>org.onap.aaf.authz</groupId>
+      <artifactId>aaf-misc-env</artifactId>
+      <scope>runtime</scope>
     </dependency>
     <dependency>
-        <groupId>org.onap.aaf.authz</groupId>
-        <artifactId>aaf-misc-rosetta</artifactId>
-        <scope>runtime</scope>
+      <groupId>org.onap.aaf.authz</groupId>
+      <artifactId>aaf-misc-rosetta</artifactId>
+      <scope>runtime</scope>
     </dependency>
     <dependency>
       <groupId>javax.xml.bind</groupId>
diff --git a/pom.xml b/pom.xml
index 797390a..2cd4de3 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <groupId>org.onap.aaf.authz</groupId>
         <artifactId>aaf-cadi-client</artifactId>
         <version>${aaf.version}</version>
-           </dependency>
-           <dependency>
-             <groupId>org.onap.aaf.authz</groupId>
-             <artifactId>aaf-cadi-aaf</artifactId>
-             <version>${aaf.version}</version>
-             <exclusions>
-               <exclusion>
-                 <groupId>javax.servlet</groupId>
-                 <artifactId>servlet-api</artifactId>
-               </exclusion>
-               <exclusion>
-                 <groupId>log4j</groupId>
-                 <artifactId>log4j</artifactId>
-               </exclusion>
-             </exclusions>
-           </dependency>
-           <dependency>
-               <groupId>org.onap.aaf.authz</groupId>
-               <artifactId>aaf-auth-client</artifactId>
-               <version>${aaf.version}</version>
-               <scope>runtime</scope>
-           </dependency>
-           <dependency>
-               <groupId>org.onap.aaf.authz</groupId>
-               <artifactId>aaf-misc-env</artifactId>
-               <version>${aaf.version}</version>
-               <scope>runtime</scope>
-           </dependency>
-           <dependency>
-               <groupId>org.onap.aaf.authz</groupId>
-               <artifactId>aaf-misc-rosetta</artifactId>
-               <version>${aaf.version}</version>
-               <scope>runtime</scope>
-           </dependency>
+      </dependency>
+      <dependency>
+        <groupId>org.onap.aaf.authz</groupId>
+        <artifactId>aaf-cadi-aaf</artifactId>
+        <version>${aaf.version}</version>
+        <exclusions>
+          <exclusion>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+      <dependency>
+        <groupId>org.onap.aaf.authz</groupId>
+        <artifactId>aaf-auth-client</artifactId>
+        <version>${aaf.version}</version>
+        <scope>runtime</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.onap.aaf.authz</groupId>
+        <artifactId>aaf-misc-env</artifactId>
+        <version>${aaf.version}</version>
+        <scope>runtime</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.onap.aaf.authz</groupId>
+        <artifactId>aaf-misc-rosetta</artifactId>
+        <version>${aaf.version}</version>
+        <scope>runtime</scope>
+      </dependency>
     </dependencies>
   </dependencyManagement>
   <profiles>