File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Web Services
Reply locked New topic

Adding JAXB object to Soap Header

udhaya kumarG

Joined: Jul 23, 2011
Posts: 15

I have created a JAX-WS client from a business partner's WSDL. I now have many JAXB objects for everything in the WSDL/XSD.
They have provided a data structure for me to fill in and add to the SOAP header which is used for message routing and authentication. After doing some reading I think the proper solution is for me to create a SOAPHandler that intercepts every request and adds the SOAPHeader. Below is a snippet of what my handleMessage method looks like:

public boolean handleMessage(SOAPMessageContext msgCtx) {

SOAPEnvelope soapEnvelope;
SOAPHeader soapHeader;
PartnerHeader partnerHeader; // JAXB object

boolean isOutboundMessage = ((Boolean) msgCtx.get(

if (isOutboundMessage) {

try {

soapEnvelope = msgCtx.getMessage().getSOAPPart().getEnvelope();

soapHeader = envelope.getHeader();

partnerHeader = new PartnerHeader(); // JAXB object

// fill in partnerHeader JAXB object

// add partnerHeader to soapHeader

} catch .... {





Can someone please show me how to add the filled-in JAXB object into the SOAPHeader?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
Question already asked here:
Locking this thread.

My free books and tutorials:
It is sorta covered in the JavaRanch Style Guide.
subject: Adding JAXB object to Soap Header