All Articles

Setting SOAP Headers in Apache CXF – Client

Adding SOAP headers using Apache CXF – Client

ClientProxyFactoryBean factory = new JaxWsProxyFactoryBean();
// Set the web service endpoint URL here
SampleService serviceClient = (SampleService) factory.create();
// Get the underlying Client object from the proxy object of service interface
Client proxy = ClientProxy.getClient(serviceClient);
// Creating SOAP headers to the web service request
// Create a list for holding all SOAP headers
List<Header> headersList = new ArrayList<Header>();
Header userNameHeader = new Header(new QName("", "userName"), "JohnDoe", new JAXBDataBinding(String.class));
// Add SOAP headers to the web service request
proxy.getRequestContext().put(Header.HEADER_LIST, headersList);