use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class ElementSerializerTest method testDualNamespaces2.
public void testDualNamespaces2() throws Exception {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace ns1 = factory.createOMNamespace("bar", "x");
OMElement root = factory.createOMElement("root", ns1);
OMNamespace ns2 = root.declareNamespace("bar", "y");
OMElement elt1 = factory.createOMElement("foo", ns1);
OMElement elt2 = factory.createOMElement("yuck", ns2);
OMText txt1 = factory.createOMText(elt2, "blah");
elt2.addChild(txt1);
elt1.addChild(elt2);
root.addChild(elt1);
root.serialize(writer);
}
use of org.apache.axiom.om.OMText 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.OMText in project webservices-axiom by apache.
the class WriteCDataScenario method validate.
@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
OMNode child = element.getFirstOMChild();
Assert.assertTrue(child instanceof OMText);
OMText text = (OMText) child;
Assert.assertEquals(OMNode.CDATA_SECTION_NODE, text.getType());
Assert.assertEquals("content", text.getText());
}
use of org.apache.axiom.om.OMText 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());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestGetTextCharactersFromDataHandler method runTest.
@Override
protected void runTest() throws Throwable {
DataHandler dh = new DataHandler("test content", "text/plain; charset=utf-8");
OMText text = metaFactory.getOMFactory().createOMText(dh, true);
char[] chars = text.getTextCharacters();
byte[] decoded = Base64.decodeBase64(new String(chars));
assertEquals("test content", new String(decoded, "utf-8"));
}
Aggregations