// Write out the message
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(baos, oof);
XOPAwareStAXOMBuilder builder =
new XOPAwareStAXOMBuilder(attachments.getSOAPPartInputStream(),
attachments);
OMElement om = builder.getDocumentElement();
om.serialize(writer);
om.close(false);
String outNormal = baos.toString();
assertTrue(outNormal.indexOf("base64") == -1);
// Now do it again but use base64 content-type-encoding for
// binary attachments
baos = new ByteArrayOutputStream();
oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS,
Boolean.TRUE);
writer = new MTOMXMLStreamWriter(baos, oof);
builder =
new XOPAwareStAXOMBuilder(attachments.getSOAPPartInputStream(),
attachments);
om = builder.getDocumentElement();
om.serialize(writer);
om.close(false);
String outBase64 = baos.toString();
// Do a quick check to see if the data is base64 and is
// writing base64 compliant code.
assertTrue(outBase64.indexOf("base64") != -1);
assertTrue(outBase64.indexOf("GBgcGBQgHBwcJCQgKDBQNDAsL") != -1);
// Now read the data back in
InputStream is = new ByteArrayInputStream(outBase64.getBytes());
Attachments attachments2 = new Attachments(is, TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
// Now write it back out with binary...
baos = new ByteArrayOutputStream();
oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS,
Boolean.FALSE);
writer = new MTOMXMLStreamWriter(baos, oof);
builder =
new XOPAwareStAXOMBuilder(attachments2.getSOAPPartInputStream(),
attachments2);
om = builder.getDocumentElement();
om.serialize(writer);
om.close(false);
String outBase64ToNormal = baos.toString();
assertTrue(outBase64ToNormal.indexOf("base64") == -1);
// Now do it again but use base64 content-type-encoding for
// binary attachments
baos = new ByteArrayOutputStream();
oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS,
Boolean.TRUE);
writer = new MTOMXMLStreamWriter(baos, oof);
builder =
new XOPAwareStAXOMBuilder(attachments2.getSOAPPartInputStream(),
attachments2);
om = builder.getDocumentElement();
om.serialize(writer);
om.close(false);
String outBase64ToBase64 = baos.toString();
// Do a quick check to see if the data is base64 and is