use of org.nhindirect.schema.edge.ws.AttachmentType in project nhin-d by DirectProject.
the class MessageServiceImplService method copyAttachments.
/**
* @param body - The incoming unmarshalled SOAP message
* @param mailBody - The mail message that we're constructing
* @throws IOException
* @throws MessagingException
*/
private void copyAttachments(EmailType body, Multipart mailBody) throws IOException, MessagingException {
if (log.isDebugEnabled())
log.debug("Enter");
if (body.getBody().getAttachment().size() > 0) {
for (AttachmentType document : body.getBody().getAttachment()) {
try {
MimeBodyPart mailAttachment = new MimeBodyPart();
if (log.isDebugEnabled()) {
DataHandler dh = document.getContent();
log.debug("Attachment: " + document.getFilename() + "\r\n Type: " + dh.getContentType());
DataFlavor[] flavors = dh.getTransferDataFlavors();
for (DataFlavor flavor : flavors) {
log.debug("Flavor: " + flavor.getMimeType());
}
try {
InputStream is = dh.getInputStream();
log.debug("Size: " + is.available());
log.debug("Content class is: " + dh.getContent().getClass().getName());
} catch (Exception e) {
log.error("Could not get an InputStream for Attachment DataHandler object", e);
}
}
mailAttachment.setDataHandler(document.getContent());
mailAttachment.setFileName(document.getFilename());
mailBody.addBodyPart(mailAttachment);
} catch (MessagingException e) {
log.error(e);
throw new MessagingException("Unable to process attachment", e);
}
}
}
if (log.isDebugEnabled())
log.debug("Exit");
}
Aggregations