I am trying to take in an arbitrary set of HTTP headers and dump it into a WebResource instance. The WebResource interface allows one to do this with query parameters as it offers both a
webResource.queryParam(key, value)
and
webResource.queryParams(MultivaluedMap<String, String> queryMap)
The API however, does not allow the same to be done to headers. There is only one function,
webResource.header(key, value)
which allows one to enter a key-value pair for an HTTP header, but no function
webResource.headers(MultivaluedMap<String, String> headersMap)
To solve the problem, I tried to retrieve the builder from WebResource and iterate over it, adding the headers one by one
WebResource.Builder builder = webResource.getRequestBuilder();
for(Map.Entry<String, String> headersMapEntry : headersMap.entrySet()){
builder = builder.header(
headersMapEntry.getKey(), headersMapEntry.getValue());
}
but it doesn't seem to solve my problem.
Does anyone have an idea how I can do a workaround with Jersey so that I can dump an arbitrary map into the headers of my WebResource?
Thanks, David