I am attempting to set a custom header on an outbound SOAP request using JAX-WS on WebSphere 8.5.5.2. The BindingProvider in the method below is obtained via JNDI for a service declared with a @ServiceRef annotation.
void setHeader(BindingProvider provider, String name, String value) {
Map<String, Object> context = provider.getRequestContext();
Map<String, List<String>> headers = null;
if (context.containsKey(MessageContext.HTTP_REQUEST_HEADERS)) {
headers = (Map<String, List<String>>)
context.get(MessageContext.HTTP_REQUEST_HEADERS);
}
if (headers == null) {
headers = new HashMap<String, List<String>>();
context.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
}
headers.put(name, Arrays.asList(value));
}
They key here, I think, is related to WebSphere. If I instead put the HTTP headers into an IBM-specific entry of the context:
com.ibm.websphere.webservices.Constants.REQUEST_TRANSPORT_PROPERTIES
the headers are properly placed into the SOAP HTTP request. Note that in case, the value is not wrapped inside a List instance.
Has anyone successfully implemented this solution on WebSphere using MessageContext.HTTP_REQUEST_HEADERS
?