wood burning stoves 2.0*
The moose likes Web Services and the fly likes Adding JAXB object to Soap Header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Adding JAXB object to Soap Header" Watch "Adding JAXB object to Soap Header" New topic
Author

Adding JAXB object to Soap Header

udhaya kumarG
Greenhorn

Joined: Jul 23, 2011
Posts: 15

Hi,

Could you please tel me how to add the JAXB Object to SOAP Header using JAX-WS???


Thanks in Advance..
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
The usual way to manipulate the headers of a SOAP message using Java is through an object implementing the SOAPHeader interface.
After some calls, you will get an object implementing the SOAPElement interface. This interface extends the DOM interfaces Element and Node, thus you can add a DOM node to a SOAPHeader object.
Then you need to transform the JAXB object into a DOM object, before you can add it to the SOAPHeader object. Take a look at the JavaSE 6 API documentation for javax.xml.bind.Marshaller on how to do this.

An alternate route is to manipulate a string representing the XML message. This is not the solution I would prefer, but it may reduce the amount of code you have to write.

A third alternative is using Groovy, which is good at XML manipulation, or some additional framework. If you have restrictions imposed on you, this may not be a viable option.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
udhaya kumarG
Greenhorn

Joined: Jul 23, 2011
Posts: 15

Hi Ivan Krizsan,

Thanks for your Reply.. I got it. Working fine now!
Vikas Chandra
Greenhorn

Joined: Mar 26, 2006
Posts: 2

Would it be possible to post the code sample. I guess I am missing something while trying to achieve the same
Vikky Chan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Adding JAXB object to Soap Header
 
Similar Threads
Generalized Parsing for SOAP Response
Adding JAXB object to Soap Header
SOAP Format
soap header help
Generate SOAP message from Java class