Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Apache CXF: How to add custom SOAP headers to the web service request?

DZone's Guide to

Apache CXF: How to add custom SOAP headers to the web service request?

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

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.

More on this @ http://cxf.apache.org/faq.html#FAQ-HowcanIaddsoapheaderstotherequest%2Fresponse%3F

From http://singztechmusings.wordpress.com/2011/09/08/apache-cxf-how-to-add-custom-soap-headers-to-the-web-service-request/

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}