public void testDataHandlerSerializationWithoutMTOM() throws Exception{
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
// Construct the original message
DocumentBean orgObject = new DocumentBean();
orgObject.setId("123456");
orgObject.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, orgObject));
orgEnvelope.getBody().addChild(element);
// Serialize the message
ByteArrayOutputStream out = new ByteArrayOutputStream();
orgEnvelope.serialize(out);
assertFalse(element.isExpanded());
SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(
new ByteArrayInputStream(out.toByteArray()), null).getSOAPEnvelope();
DocumentBean object = (DocumentBean)context.createUnmarshaller().unmarshal(
envelope.getBody().getFirstElement().getXMLStreamReader(false));
assertEquals("some content", IOUtils.toString(object.getContent().getInputStream(), "utf-8"));
}