For a REST service, I'm adding multiple values to a header and the client expects the values to be comma separated in the response header:
test-header: value1, value2
I have implemented this in a ContainerResponseFilter
like this:
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
String headerOfInterest = "test-header";
List<String> header = responseContext.getStringHeaders().get(headerOfInterest);
if (header == null) {
responseContext.getHeaders().addAll(headerOfInterest, "value1", "value2");
}
}
However this seems to add the headers twice, instead of comma separating the values.
...
test-header: value1
test-header: value2
...
I have tried using responseContext.getHeaders().add()
twice and adding each value, but whichever way I add the values, they end up showing two times in the response instead of being comma separated.
From this SO post, to me it seems comma separated multi value is the standard. So how do I achive this in Jersey?
Jersey version: 2.29 Tomcat version: 9.5