Create SOAP message : SOAP « Web Services SOA « Java Tutorial

import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;

public class MainClass {

  public static void main(String[] args) throws Exception {
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

    SOAPHeader soapHeader = soapEnvelope.getHeader();
    SOAPHeaderElement headerElement = soapHeader.addHeaderElement(soapEnvelope.createName(
        "Signature", "SOAP-SEC", ""));

    SOAPBody soapBody = soapEnvelope.getBody();
    soapBody.addAttribute(soapEnvelope.createName("id", "SOAP-SEC",
        ""), "Body");
    Name bodyName = soapEnvelope.createName("FooBar", "z", "");
    SOAPBodyElement gltp = soapBody.addBodyElement(bodyName);

    Source source = soapPart.getContent();


26.2.1.Create SOAP message
26.2.2.Generate DOM with SOAP message
26.2.3.Output SOAP message with XML transformer
26.2.4.Generate DSA key pair
26.2.5.Use DSA key pair to generate XML Signature
26.2.6.Sign SOAP message
26.2.7.Call google web service and deal with the return with SOAPMessage
26.2.8.Sending a SOAP Message
26.2.9.Processing a SOAP Message