I need to send SOAP message with mime-attachment into my web-service. I wrote this code for it:
File file = new File(fileName);
DataSource ds = new FileDataSource(file) {
public String getContentType() {
return "application/zip";// "application/binary";
}
};
UUID ref = UUID.randomUUID();
SOAPElement refBody = refNode.addChildElement("PackageBody");
refBody.removeContents();
packBody.setAttribute("href", "cid:" + ref.toString());
AttachmentPart attachment = soapMessage.createAttachmentPart(new DataHandler(ds));
attachment.setContentId(ref.toString());
soapMessage.addAttachmentPart(attachment);
//
Iterator iterator = soapMessage.getAttachments();
while (iterator.hasNext()) {
AttachmentPart attached = (AttachmentPart) iterator.next();
//
String id = attached.getContentId();
String type = attached.getContentType();
System.out.println("Attachment " + id + " has content type " + type);
if (type.equals("text/xml")) {
Object content = attached.getContent();
System.out.println("Attachment contains:\n" + content);
}
}
It work for my project, but not correct. If I send sopa request with this attach, I have this:
in the soap request found reference to non-existent mime-attachment
If it false way, please, tell me how to correct create this mime-attachment for soap in java. Thanks