Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
CaseInsensitiveMap headers = (CaseInsensitiveMap)to_attachment.headers;
Iterator<Object> it = headers.values().iterator();
SoapMessage msg = null;
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof SoapMessage) {
msg = (SoapMessage)obj;
}
}
if (msg != null) {
Collection<Attachment> attachments = (Collection<Attachment>)msg.getAttachments();
if (attachments != null) {
System.out.println("Found Attachments-->");
File dataDir = new File(context.appdir + "/" + to_attachment.flowid);
dataDir.mkdir();
Iterator<Attachment> iter = attachments.iterator();
while (iter.hasNext()) {
Attachment attachment = iter.next();
DataHandler data = attachment.getDataHandler();
InputStream is = data.getInputStream();
File dataFile = new File(dataDir + "/" + data.getName());
System.out.println("Writing data to:\n\t" + dataFile.toString());
FileOutputStream fos = new FileOutputStream(dataFile);
IOUtils.copy(is, fos);
fos.close();
}
} else System.out.println("No Attachment!");
}