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");
// Get the SOAP body from the message but leave
// it empty
SOAPBody body = message.getSOAPBody();
message.saveChanges();
// Display the message that would be sent
//System.out.println("\n----- Request Message ----\n");
//message.writeTo(System.out);
// Look at the headers
Iterator allHeaders = header.examineAllHeaderElements();
while (allHeaders.hasNext()) {
SOAPHeaderElement headerElement =
(SOAPHeaderElement)allHeaders.next();
Name headerName = headerElement.getElementName();
//System.out.println("\nHeader name is " +
// headerName.getQualifiedName());
//System.out.println("Actor is " + headerElement.getActor());
//System.out.println("mustUnderstand is " +
// headerElement.getMustUnderstand());