}
}
@SuppressWarnings("unchecked")
private void writeMultipartMessage(Message message, OutputStream out, byte[] data) throws MessagingException, IOException {
MimeMultipart parts = new MimeMultipart("related; type=\"text/xml\"; start=\"<" + SOAP_PART_ID + ">\"");
Session session = Session.getDefaultInstance(new Properties(), null);
MimeMessage mime = new MimeMessage(session);
// Add soap part
MimeBodyPart soapPart = new MimeBodyPart();
soapPart.setContentID("<" + SOAP_PART_ID + ">");
soapPart.addHeader("Content-Transfer-Encoding", "8bit");
soapPart.setDataHandler(new DataHandler(new ByteArrayDataSource(data, "text/xml")));
parts.addBodyPart(soapPart);
// Add attachments
for (Iterator itr = message.getAttachments().entrySet().iterator(); itr.hasNext();) {
Map.Entry entry = (Map.Entry) itr.next();
String id = (String) entry.getKey();
DataHandler dh = (DataHandler) entry.getValue();
MimeBodyPart part = new MimeBodyPart();
part.setDataHandler(dh);
part.setContentID("<" + id + ">");
part.addHeader("Content-Transfer-Encoding", "binary");
parts.addBodyPart(part);
}
mime.setContent(parts);
mime.setHeader(Message.CONTENT_TYPE, parts.getContentType());
// We do not want headers, so
// * retrieve all headers
// * skip first 2 bytes (CRLF)
mime.saveChanges();
Enumeration<Header> headersEnum = mime.getAllHeaders();