use of org.apache.axiom.om.OMElement 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.OMElement in project webservices-axiom by apache.
the class TestAddChildFromForeignDocument method runTest.
@Override
protected void runTest() throws Throwable {
DocumentBuilder db = ((DOMMetaFactory) metaFactory).newDocumentBuilderFactory().newDocumentBuilder();
Document document1 = db.newDocument();
Element element1 = document1.createElementNS(null, "element1");
Document document2 = db.newDocument();
Element element2 = document2.createElementNS(null, "element2");
((OMElement) element1).addChild((OMElement) element2);
// Assert that the new child is not a copy, but the original element
assertSame(element2, element1.getFirstChild());
// Assert that the owner document of element2 was changed
assertSame(document1, element2.getOwnerDocument());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestAddAttributeReplace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
Document ownerDocument = ((Element) element).getOwnerDocument();
assertNotNull(ownerDocument);
OMAttribute attr1 = element.addAttribute("attr", "value1", null);
assertSame(ownerDocument, ((Attr) attr1).getOwnerDocument());
OMAttribute attr2 = factory.createOMAttribute("attr", null, "value2");
element.addAttribute(attr2);
Document newOwnerDocument = ((Attr) attr1).getOwnerDocument();
assertNotNull(ownerDocument);
assertNotSame(ownerDocument, newOwnerDocument);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetName method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement root = factory.createOMElement("root", null);
OMSourcedElement el = factory.createOMElement(new PullOMDataSource("<p:el xmlns:p='urn:ns'>content</p:el>"), "el", factory.createOMNamespace("urn:ns", null));
root.addChild(el);
XMLStreamReader reader = root.getXMLStreamReader();
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
QName name = reader.getName();
assertEquals("p", name.getPrefix());
assertEquals("urn:ns", name.getNamespaceURI());
assertEquals("el", name.getLocalPart());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestBase64StreamingWithGetSAXSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement elem = factory.createOMElement("test", null);
// Create a data source that would eat up all memory when loaded. If the test
// doesn't fail with an OutOfMemoryError, we know that the OMText implementation
// supports streaming.
DataSource ds = new RandomDataSource(654321L, Runtime.getRuntime().maxMemory());
OMText text = factory.createOMText(new DataHandler(ds), false);
elem.addChild(text);
SAXSource saxSource = elem.getSAXSource(true);
XMLReader xmlReader = saxSource.getXMLReader();
xmlReader.setContentHandler(new Base64Comparator(ds.getInputStream()));
xmlReader.parse(saxSource.getInputSource());
}
Aggregations