javax.xml.soap


1. Creating a SOAP Message

import javax.xml.soap.*;
import javax.xml.parsers.*;

public class CreateSoapMessage {

    public static void main(String[] args) throws Exception {
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        SOAPMessage soapMessage = soapFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
        soapEnvelope.addNamespaceDeclaration("soap", "http://schemas.xmlsoap.org/soap/envelope/");

        SOAPHeader soapHeader = soapEnvelope.getHeader();
        SOAPElement soapHeaderElement = soapHeader.addHeaderElement(soapFactory.createName("To", "soap", "http://schemas.xmlsoap.org/soap/envelope/"));
        soapHeaderElement.addTextNode("receiver@example.com");

        SOAPBody soapBody = soapEnvelope.getBody();
        SOAPElement soapBodyElement = soapBody.addBodyElement(soapFactory.createName("Body", "soap", "http://schemas.xmlsoap.org/soap/envelope/"));
        soapBodyElement.addTextNode("This is the body of the SOAP message.");

        soapMessage.saveChanges();
    }
}

2. Parsing a SOAP Message

3. Sending a SOAP Message

4. Receiving a SOAP Message

5. Handling SOAP Faults

6. Using SOAP Headers

7. Using SOAP Attachments

8. Using SOAP Callbacks