SOAPPart sp = msg.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPHeader hdr = envelope.getHeader();
SOAPBody bdy = envelope.getBody();
SOAPBodyElement sbe1 = bdy.addBodyElement(
envelope.createName("Body1", NS_PREFIX, NS_URI));
sbe1.addChildElement(envelope.createName(
"TheGifAttachment", NS_PREFIX, NS_URI));
SOAPBodyElement sbe2 = bdy.addBodyElement(
envelope.createName("Body2", NS_PREFIX, NS_URI));
sbe2.addChildElement(envelope.createName(
"TheXmlAttachment", NS_PREFIX, NS_URI));
URL url1 = new URL("http://localhost:8080/SOAPMessage/attach.xml");
URL url2 = new URL("http://localhost:8080/SOAPMessage/attach.gif");
URL url3 = new URL("http://localhost:8080/SOAPMessage/attach.txt");
URL url4 = new URL("http://localhost:8080/SOAPMessage/attach.html");
URL url5 = new URL("http://localhost:8080/SOAPMessage/attach.jpeg");
// Set href on body elements using Content-Location headers and relative URI's
sbe1.setAttribute("href", url2.toString());
sbe2.setAttribute("href", url1.toString());
AttachmentPart ap1 = msg.createAttachmentPart(new DataHandler(url1));
AttachmentPart ap2 = msg.createAttachmentPart(new DataHandler(url2));
AttachmentPart ap3 = msg.createAttachmentPart(new DataHandler(url3));
AttachmentPart ap4 = msg.createAttachmentPart(new DataHandler(url4));