feat(echo): Allow multiple headers with same key in echoed response.
Current echo implementation uses a standard map. This change ensures it uses the already extant
HeaderMap implementation to allow multiple HTTP headers with the same key.
MODIFY
test/common/src/main/java/io/apiman/test/common/echo/EchoServerVertx.java
test/common/src/main/java/io/apiman/test/common/echo/EchoServerVertx.java
@@ -18,7 +18,7 @@ package io.apiman.test.common.echo;
import io.apiman.common.util.SimpleStringUtils;
import io.apiman.gateway.engine.beans.EngineErrorResponse;
-import io.apiman.gateway.engine.beans.util.CaseInsensitiveStringMultiMap;
+import io.apiman.gateway.engine.beans.util.HeaderMap;
import io.apiman.test.common.mock.EchoResponse;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
@@ -263,8 +263,8 @@ public class EchoServerVertx extends AbstractVerticle {
}
}
- private CaseInsensitiveStringMultiMap multimapToMap(MultiMap headers) {
- CaseInsensitiveStringMultiMap map = new CaseInsensitiveStringMultiMap();
+ private HeaderMap multimapToMap(MultiMap headers) {
+ HeaderMap map = new HeaderMap();
headers.forEach(pair -> map.add(pair.getKey(), pair.getValue()));
return map;
}

MODIFY
test/common/src/main/java/io/apiman/test/common/mock/EchoResponse.java
test/common/src/main/java/io/apiman/test/common/mock/EchoResponse.java
*/
package io.apiman.test.common.mock;
-import java.util.HashMap;
-import java.util.Map;
+import io.apiman.gateway.engine.beans.util.HeaderMap;
import javax.xml.bind.annotation.XmlRootElement;
@@ -31,7 +30,7 @@ public class EchoResponse {
private String method;
private String resource;
private String uri;
- private Map<String, String> headers = new HashMap<>();
+ private HeaderMap headers = new HeaderMap();
private Long bodyLength;
private String bodySha1;
private Long counter;
@@ -73,14 +72,14 @@ public class EchoResponse {
/**
* @return the headers
*/
- public Map<String, String> getHeaders() {
+ public HeaderMap getHeaders() {
return headers;
}
/**
* @param headers the headers to set
*/
- public void setHeaders(Map<String, String> headers) {
+ public void setHeaders(HeaderMap headers) {
this.headers = headers;
}

MODIFY
test/policies/src/main/java/io/apiman/test/policies/EchoBackEndApi.java
test/policies/src/main/java/io/apiman/test/policies/EchoBackEndApi.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.util.Date;
import org.apache.commons.codec.digest.DigestUtils;
+
import com.fasterxml.jackson.databind.ObjectMapper;
/**
@@ -49,7 +50,7 @@ public class EchoBackEndApi implements IPolicyTestBackEndApi {
echoResponse.setBodySha1(DigestUtils.sha1Hex(requestBody));
}
echoResponse.setCounter(counter++);
- echoResponse.setHeaders(request.getHeaders().toMap());
+ echoResponse.setHeaders(request.getHeaders());
echoResponse.setMethod(request.getType());
echoResponse.setResource(request.getDestination());
echoResponse.setUri("urn:" + request.getDestination());

feat(echo): Allow multiple headers with same key in echoed response.

Current echo implementation uses a standard map. This change ensures it uses the already extant
HeaderMap implementation to allow multiple HTTP headers with the same key.

Signed-off-by: Marc Savy <marc@rhymewithgravy.com>