Having created a java web service client using wsimport on a wsdl, I need to set the Authorization header for each soap message embedded in an http request. Having generated a subclass of javax.xml.ws.Service, how can I append an http header to each outgoing request???
Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name.
Here is the code, based on Femi's answer.
It can be a little tricky to figure out. Works beautifully!
Service jaxwsService = Service.create(wsdlURL, serviceName); Dispatch<SOAPMessage> disp = jaxwsService.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE); //Add HTTP request Headers Map<String, List<String>> requestHeaders = new HashMap<>(); requestHeaders.put("Auth-User", Arrays.asList("BILL_GATES")); disp.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With