use of org.apache.axiom.attachments.ByteArrayDataSource in project webservices-axiom by apache.
the class MultipartBodyWriterTest method test.
private void test(String contentTransferEncoding) throws Exception {
Random random = new Random();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MultipartBodyWriter mpw = new MultipartBodyWriter(baos, UIDGenerator.generateMimeBoundary());
byte[] content = new byte[8192];
random.nextBytes(content);
OutputStream partOutputStream = mpw.writePart("application/octet-stream", contentTransferEncoding, UIDGenerator.generateContentId(), null);
partOutputStream.write(content);
partOutputStream.close();
mpw.complete();
MimeMultipart mp = new MimeMultipart(new ByteArrayDataSource(baos.toByteArray()));
assertEquals(1, mp.getCount());
MimeBodyPart bp = (MimeBodyPart) mp.getBodyPart(0);
assertEquals(contentTransferEncoding, bp.getHeader("Content-Transfer-Encoding")[0]);
baos.reset();
bp.getDataHandler().writeTo(baos);
assertTrue(Arrays.equals(content, baos.toByteArray()));
}
use of org.apache.axiom.attachments.ByteArrayDataSource in project webservices-axiom by apache.
the class MIMEOutputUtils method complete.
/**
* @deprecated Use {@link OMMultipartWriter} instead.
*/
public static void complete(OutputStream outStream, byte[] xmlData, LinkedList binaryNodeList, String boundary, String contentId, String charSetEncoding, String SOAPContentType, OMOutputFormat omOutputFormat) {
try {
log.debug("Start: write the SOAPPart and the attachments");
// Write out the mime boundary
startWritingMime(outStream, boundary);
javax.activation.DataHandler dh = new javax.activation.DataHandler(new ByteArrayDataSource(xmlData, "text/xml; charset=" + charSetEncoding));
MimeBodyPart rootMimeBodyPart = new MimeBodyPart();
rootMimeBodyPart.setDataHandler(dh);
rootMimeBodyPart.addHeader("Content-Type", "application/xop+xml; charset=" + charSetEncoding + "; type=\"" + SOAPContentType + "\"");
rootMimeBodyPart.addHeader("Content-Transfer-Encoding", "binary");
rootMimeBodyPart.addHeader("Content-ID", "<" + contentId + ">");
// Write out the SOAPPart
writeBodyPart(outStream, rootMimeBodyPart, boundary);
// Now write out the Attachment parts (which are represented by the
// text nodes int the binary node list)
Iterator binaryNodeIterator = binaryNodeList.iterator();
while (binaryNodeIterator.hasNext()) {
OMText binaryNode = (OMText) binaryNodeIterator.next();
writeBodyPart(outStream, createMimeBodyPart(binaryNode.getContentID(), binaryNode.getDataHandler(), omOutputFormat), boundary);
}
finishWritingMime(outStream);
outStream.flush();
log.debug("End: write the SOAPPart and the attachments");
} catch (IOException e) {
throw new OMException("Error while writing to the OutputStream.", e);
} catch (MessagingException e) {
throw new OMException("Problem writing Mime Parts.", e);
}
}
Aggregations