Java Reference
In-Depth Information
supply a password in the header, so you need to account for those in your message creation.
The SAAJ client that fulfills your requirements is shown in Example 5-10 .
Example5-10.SAAJ client that passes headers
package createHeader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
/**
* Invokes the SAAJ header service.
*/
public class SAAJCreateHeader {
private static final String NS = "urn:soacookbook.saaj";
public static void main(String...arg) {
new SAAJCreateHeader().invoke();
System.out.println("\nAll done.");
}
public SAAJCreateHeader() { }
private void invoke(){
try {
//Prepare service to call
Service service = createService();
QName portQName = new QName(NS, "CalculatorWSPort");
Dispatch<SOAPMessage> dispatch =
service.createDispatch(portQName,
SOAPMessage.class, Service.Mode.MESSAGE);
//Prepare Request
SOAPMessage request = createMessage();
Search WWH ::




Custom Search