Apache CXF: How to add custom SOAP headers to the web service request?
Join the DZone community and get the full member experience.Join For Free
Here’s how to do it in CXF proprietary way:
// Create a list of SOAP headers List<Header> headersList = new ArrayList<Header>(); Header testHeader = new Header(new QName("uri:singz.ws.sample", "test"), "A custom header", new JAXBDataBinding(String.class)); headersList.add(testHeader); ((BindingProvider)proxy).getRequestContext().put(Header.HEADER_LIST, headersList);
The headers in the list are streamed at the appropriate time to the wire according to the databinding object found in the Header object. This doesn’t require changes to WSDL or method signatures. It’s much faster as it doesn’t break streaming and the memory overhead is less.
Opinions expressed by DZone contributors are their own.