use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.
the class TestDataHandlerSerializationWithMTOM method runTest.
@Override
protected void runTest() throws Throwable {
SOAPFactory factory = metaFactory.getSOAP11Factory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
// Construct the original message
DocumentBean object = new DocumentBean();
object.setId("123456");
object.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
orgEnvelope.getBody().addChild(element);
// Serialize the message
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
orgEnvelope.serialize(out, format);
out.close();
assertFalse(element.isExpanded());
// Parse the serialized message
MultipartBody mb = MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build();
assertEquals(2, mb.getPartCount());
SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).getSOAPEnvelope();
OMElement contentElement = envelope.getBody().getFirstElement().getFirstChildWithName(new QName("http://ws.apache.org/axiom/test/jaxb", "content"));
OMText content = (OMText) contentElement.getFirstOMChild();
assertTrue(content.isBinary());
assertTrue(content.isOptimized());
DataHandler dh = content.getDataHandler();
assertEquals("some content", dh.getContent());
}
use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.
the class TestGetNameFromJAXBElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory omFactory = metaFactory.getOMFactory();
ObjectFactory objectFactory = new ObjectFactory();
JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
JAXBElement<LinkIdentitiesType> jaxbElement = objectFactory.createLinkIdentities(new LinkIdentitiesType());
OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, jaxbElement));
assertEquals("http://www.example.org/identity", element.getNamespaceURI());
assertEquals("LinkIdentities", 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();
}
use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.
the class JAXBTest method test.
@Test
public void test() throws Exception {
OMFactory factory = OMAbstractFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DummyBean.class);
OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, new DummyBean()));
element.serialize(new ByteArrayOutputStream());
}
use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.
the class TestUnmarshalWithDataHandler method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
DocumentBean orgBean = new DocumentBean();
orgBean.setId("AB23498");
orgBean.setContent(new DataHandler("test content", "text/plain"));
OMElement element = factory.createOMElement(new JAXBOMDataSource(context, orgBean));
DocumentBean bean = (DocumentBean) element.unmarshal(context, null, true);
assertEquals(orgBean.getId(), bean.getId());
assertEquals(orgBean.getContent(), bean.getContent());
}
use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.
the class TestDataHandlerExpansion method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
DataHandler dh = new DataHandler("some content", "text/plain");
DocumentBean object = new DocumentBean();
object.setId("123456");
object.setContent(dh);
OMElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
OMElement child = (OMElement) element.getFirstOMChild();
assertEquals("id", child.getLocalName());
assertEquals("123456", child.getText());
child = (OMElement) child.getNextOMSibling();
assertEquals("content", child.getLocalName());
OMText content = (OMText) child.getFirstOMChild();
assertTrue(content.isBinary());
assertTrue(content.isOptimized());
assertSame(dh, content.getDataHandler());
}
Aggregations