// 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));
AttachmentPart ap5 = msg.createAttachmentPart(new DataHandler(url5));
ap1.setContentType("text/xml");
ap1.setContentId("<THEXML>");
ap1.setContentLocation(url1.toString());
ap2.setContentType("image/gif");
ap2.setContentId("<THEGIF>");
ap2.setContentLocation(url2.toString());
ap3.setContentType("text/plain");
ap3.setContentId("<THEPLAIN>");
ap3.setContentLocation(url3.toString());
ap4.setContentType("text/html");
ap4.setContentId("<THEHTML>");
ap4.setContentLocation(url4.toString());
ap5.setContentType("image/jpeg");
ap5.setContentId("<THEJPEG>");
ap5.setContentLocation(url5.toString());
// Add the attachments to the message.
msg.addAttachmentPart(ap1);
msg.addAttachmentPart(ap2);
msg.addAttachmentPart(ap3);
msg.addAttachmentPart(ap4);
msg.addAttachmentPart(ap5);
msg.saveChanges();
//Retrieve attachment with href=THEGIF
AttachmentPart myap = msg.getAttachment(sbe1);
if (myap == null) {
fail("Returned null (unexpected)");
} else if (!myap.getContentType().equals("image/gif")) {
fail("Wrong attachment was returned: Got Content-Type of "
+ myap.getContentType() + ", Expected Content-Type of image/gif");
}
//Retrieve attachment with href=THEXML
myap = msg.getAttachment(sbe2);
if (myap == null) {
fail("Returned null (unexpected)");
} else if (!myap.getContentType().equals("text/xml")) {
fail("Wrong attachment was returned: Got Content-Type of "
+ myap.getContentType() + ", Expected Content-Type of text/xml");
}
//Retrieve attachment with href=boo-hoo (expect null)
QName myqname = new QName("boo-hoo");
SOAPElement myse = SOAPFactory.newInstance().createElement(myqname);