I'm Singaram Subramanian, and I work with CSC India as a Software Developer. My blog is an attempt to share my learnings with all (mainly, for those who desperately mine google finding ways to solve problems, fix issues, learn about a Java/Open source software, or deciding on tough choices etc. during software development as I do). Singaram is a DZone MVB and is not an employee of DZone and has posted 36 posts at DZone. You can read more from them at their website. View Full User Profile

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

09.16.2011
| 9995 views |
  • submit to reddit

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/

Published at DZone with permission of Singaram Subramanian, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

John David replied on Thu, 2012/01/26 - 3:12am

Thanks for posting this useful information.
Can you please let us know, how we can add child element in a header element.

Java Eclipse

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.