Search in sources :

Example 1 with StringOMDataSource

use of org.apache.axiom.om.ds.StringOMDataSource in project webservices-axiom by apache.

the class TestCloneWithSourcedElement1 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope sourceEnv = soapFactory.getDefaultEnvelope();
    SOAPBody body = sourceEnv.getBody();
    // Create a payload
    OMDataSource bads = new StringOMDataSource("<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>");
    OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
    OMSourcedElement omse = body.getOMFactory().createOMElement(bads, "payload", ns);
    body.addChild(omse);
    copyAndCheck(sourceEnv);
    assertFalse(omse.isExpanded());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMNamespace(org.apache.axiom.om.OMNamespace) OMDataSource(org.apache.axiom.om.OMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 2 with StringOMDataSource

use of org.apache.axiom.om.ds.StringOMDataSource in project webservices-axiom by apache.

the class TestHasFaultWithOMSEUnknownName method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
    SOAPBody body = envelope.getBody();
    OMSourcedElement element = soapFactory.createOMElement(new StringOMDataSource("<ns:root xmlns:ns='urn:ns'/>"));
    body.addChild(element);
    assertFalse(body.hasFault());
    assertFalse(element.isExpanded());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 3 with StringOMDataSource

use of org.apache.axiom.om.ds.StringOMDataSource in project webservices-axiom by apache.

the class TestSerializeModifiedOMSEWithNonDestructiveDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMDataSourceExt ds = new StringOMDataSource("<element><child/></element>");
    assertFalse(ds.isDestructiveWrite());
    OMFactory f = metaFactory.getOMFactory();
    OMElement element = f.createOMElement(ds, "element", null);
    element.getFirstElement().setText("TEST");
    StringWriter sw = new StringWriter();
    element.serialize(sw);
    assertTrue(sw.toString().indexOf("TEST") != -1);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    element.serialize(baos);
    assertTrue(new String(baos.toByteArray(), "UTF-8").indexOf("TEST") != -1);
    assertTrue(element.toString().indexOf("TEST") != -1);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringWriter(java.io.StringWriter) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) OMElement(org.apache.axiom.om.OMElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMDataSourceExt(org.apache.axiom.om.OMDataSourceExt)

Example 4 with StringOMDataSource

use of org.apache.axiom.om.ds.StringOMDataSource in project webservices-axiom by apache.

the class TestStringOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    String localName = "myPayload";
    String payload1 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
    OMNamespace ns = factory.createOMNamespace("urn://test", "tns");
    StringOMDataSource somds = new StringOMDataSource(payload1);
    OMElement parent = factory.createOMElement("root", null);
    OMSourcedElement omse = factory.createOMElement(somds, localName, ns);
    parent.addChild(omse);
    OMNode firstChild = parent.getFirstOMChild();
    assertTrue("Expected OMSourcedElement child", firstChild instanceof OMSourcedElement);
    OMSourcedElement child = (OMSourcedElement) firstChild;
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    assertThat(child.getDataSource()).isInstanceOf(StringOMDataSource.class);
    // A StringOMDataSource does not consume the backing object when read.
    // Thus getting the XMLStreamReader of the StringOMDataSource should not 
    // cause expansion of the OMSourcedElement.
    XMLStreamReader reader = child.getXMLStreamReader();
    reader.next();
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    // Likewise, a StringOMDataSource does not consume the backing object when 
    // written.  Thus serializing the OMSourcedElement should not cause the expansion
    // of the OMSourcedElement.
    StringWriter out = new StringWriter();
    parent.serialize(out);
    //        System.out.println(output);
    assertTrue("The payload was not present in the output", out.toString().indexOf(payload1) > 0);
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    // Test getting the raw content from the StringOMDataSource.
    StringOMDataSource ds = (StringOMDataSource) child.getDataSource();
    assertThat(ds.getObject()).isEqualTo(payload1);
    // Validate close
    ds.close();
    assertTrue("Close should free the resource", ds.getObject() == null);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMNamespace(org.apache.axiom.om.OMNamespace) XMLStreamReader(javax.xml.stream.XMLStreamReader) StringWriter(java.io.StringWriter) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 5 with StringOMDataSource

use of org.apache.axiom.om.ds.StringOMDataSource in project webservices-axiom by apache.

the class TestCloneUnknownName method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDataSource ds = new StringOMDataSource("<p:element xmlns:p='urn:ns'>test</p:element>");
    OMSourcedElement element = factory.createOMElement(ds);
    OMCloneOptions options = new OMCloneOptions();
    options.setCopyOMDataSources(true);
    OMElement clone = (OMElement) element.clone(options);
    assertTrue(clone instanceof OMSourcedElement);
    assertFalse(element.isExpanded());
    OMNamespace expectedNS = factory.createOMNamespace("urn:ns", "p");
    assertEquals("element", element.getLocalName());
    assertEquals("element", clone.getLocalName());
    assertEquals(expectedNS, element.getNamespace());
    assertEquals(expectedNS, clone.getNamespace());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMDataSource(org.apache.axiom.om.OMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Aggregations

StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)11 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)10 OMFactory (org.apache.axiom.om.OMFactory)8 OMNamespace (org.apache.axiom.om.OMNamespace)5 OMDataSource (org.apache.axiom.om.OMDataSource)4 OMElement (org.apache.axiom.om.OMElement)4 SOAPBody (org.apache.axiom.soap.SOAPBody)3 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 StringWriter (java.io.StringWriter)2 QName (javax.xml.namespace.QName)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMCloneOptions (org.apache.axiom.om.OMCloneOptions)1 OMDataSourceExt (org.apache.axiom.om.OMDataSourceExt)1 OMNode (org.apache.axiom.om.OMNode)1 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)1 SOAPFactory (org.apache.axiom.soap.SOAPFactory)1 SOAPHeader (org.apache.axiom.soap.SOAPHeader)1 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)1