This is a JAX-RS specific question. According to @HeaderParam
docs:
https://docs.oracle.com/javaee/7/api/javax/ws/rs/HeaderParam.html
Be List, Set or SortedSet, where T satisfies 2, 3 or 4 above. The resulting collection is read-only. If the type is not one of the collection types listed in 5 above and the header parameter is represented by multiple values then the first value (lexically) of the parameter is used.
It's clear from the docs that if there are multiple values for a header then it can be mapped to a collection. Here's my example:
@Path("/")
public class TestResource {
@GET
@Path("test")
public String test(@HeaderParam("myHeader") List<String> list) {
System.out.println(list.size());
list.stream().forEach(System.out::println);
return "response";
}
}
The client:
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080/test");
String response = target.request()
.header("myHeader", "a")
.header("myHeader", "b")
.header("myHeader", "c,d")
.get(String.class);
client.close();
output on the server console:
1
a,b,c,d
Only one element is populated 'a,b,c,d' instead of 4 separate elements. What am I missing here? Googled the problem but didn't find any answers. I'm using Jersey 2.25.1. and running it in embedded tomcat:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.25.1</version>
</dependency>
<!-- ............... -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
Thanks