public void testHeaders() {
try {
// Create message factory and SOAP factory
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPFactory soapFactory = SOAPFactory.newInstance();
// Create a message
SOAPMessage message = messageFactory.createMessage();
// Get the SOAP header from the message and
// add headers to it
SOAPHeader header = message.getSOAPHeader();
String nameSpace = "ns";
String nameSpaceURI = "http://gizmos.com/NSURI";
Name order =
soapFactory.createName("orderDesk", nameSpace, nameSpaceURI);
SOAPHeaderElement orderHeader = header.addHeaderElement(order);
orderHeader.setActor("http://gizmos.com/orders");
Name shipping =
soapFactory.createName("shippingDesk", nameSpace, nameSpaceURI);
SOAPHeaderElement shippingHeader =
header.addHeaderElement(shipping);
shippingHeader.setActor("http://gizmos.com/shipping");
Name confirmation =
soapFactory.createName("confirmationDesk", nameSpace,
nameSpaceURI);
SOAPHeaderElement confirmationHeader =
header.addHeaderElement(confirmation);
confirmationHeader.setActor("http://gizmos.com/confirmations");
Name billing =
soapFactory.createName("billingDesk", nameSpace, nameSpaceURI);
SOAPHeaderElement billingHeader = header.addHeaderElement(billing);
billingHeader.setActor("http://gizmos.com/billing");
// Add header with mustUnderstand attribute
Name tName =
soapFactory.createName("Transaction", "t",
"http://gizmos.com/orders");
SOAPHeaderElement transaction = header.addHeaderElement(tName);
transaction.setMustUnderstand(true);
transaction.addTextNode("5");