use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TextHelperTest method test_fromOMText.
/**
* Test the OMText -> StringBuffer code
* @throws Exception
*/
public void test_fromOMText() throws Exception {
OMFactory factory = OMAbstractFactory.getOMFactory();
FileDataSource fds = new FileDataSource(file);
DataHandler dh = new DataHandler(fds);
OMText omText = factory.createOMText(dh, true);
StringBuffer buffer = new StringBuffer();
TextHelper.toStringBuffer(omText, buffer);
assertTrue(buffer.length() > SIZE);
String text = buffer.toString();
assertTrue(text.length() == EXPECTED_BASE64_SIZE);
assertTrue(text.startsWith(EXPECTED_STARTS_WITH));
}
use of org.apache.axiom.om.OMText 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