use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.
the class TestDataHandlerSerializationWithoutMTOM method runTest.
@Override
protected void runTest() throws Throwable {
SOAPFactory factory = metaFactory.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"));
}
use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.
the class TestExceptionDuringSerialization method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory omFactory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
DocumentBean object = new DocumentBean();
object.setId("test");
OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, object));
XMLStreamException exception = new XMLStreamException("TEST");
try {
element.serialize(new ExceptionXMLStreamWriterWrapper(StAX.createNullXMLStreamWriter(), exception));
fail("Expected XMLStreamException");
} catch (XMLStreamException ex) {
assertSame(exception, ex);
}
}
use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.
the class TestGetNameFromPlainObject method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory omFactory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, new DocumentBean()));
assertEquals("http://ws.apache.org/axiom/test/jaxb", element.getNamespaceURI());
assertEquals("document", element.getLocalName());
assertFalse(element.isExpanded());
// Force expansion so that OMSourcedElement compares the namespace URI and local name
// provided by JAXBOMDataSource with the actual name of the element
element.getFirstOMChild();
}
Aggregations