Examples of OMSourcedElement


Examples of org.apache.axiom.om.OMSourcedElement

        // 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));
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        // 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);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        orgEnvelope.serialize(out, format);
        assertFalse(element.isExpanded());
       
        // Parse the serialized message
        Attachments att = new Attachments(new ByteArrayInputStream(out.toByteArray()), format.getContentType());
        assertEquals(2, att.getAllContentIDs().length);
        SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(att).getSOAPEnvelope();
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

     */
    @Test
    public void testGetNameFromPlainObject() throws Exception {
        OMFactory omFactory = OMAbstractFactory.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();
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

    public void testGetNameFromJAXBElement() throws Exception {
        OMFactory omFactory = OMAbstractFactory.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();
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

    public void testExceptionDuringSerialization() throws Exception {
        OMFactory omFactory = OMAbstractFactory.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(StAXUtils.createXMLStreamWriter(new ByteArrayOutputStream()), exception));
            fail("Expected XMLStreamException");
        } catch (XMLStreamException ex) {
            assertSame(exception, ex);
        }
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

    }

    protected void runTest() throws Throwable {
        SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
        SOAPBody body = envelope.getBody();
        OMSourcedElement element = soapFactory.createOMElement(new ByteArrayDataSource(
                "<ns:root xmlns:ns='urn:ns'/>".getBytes("utf-8"), "utf-8"));
        body.addChild(element);
        assertFalse(body.hasFault());
        assertFalse(element.isExpanded());
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

    }

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMDataSource ds = new ByteArrayDataSource("<root><a/></root>".getBytes("utf-8"), "utf-8");
        OMSourcedElement element = factory.createOMElement(ds);
        // Force expansion
        element.getFirstOMChild();
        OMXMLParserWrapper builder = element.getBuilder();
        try {
            builder.getDocument();
            fail("Expected UnsupportedOperationException");
        } catch (UnsupportedOperationException ex) {
            // Expected
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        InputStreamDataSource isds1 = new InputStreamDataSource(new ByteArrayInputStream(payload1.getBytes(ENCODING)), ENCODING);
        InputStreamDataSource isds2 = new InputStreamDataSource(new ByteArrayInputStream(payload2.getBytes(ENCODING)), ENCODING);
       
        OMFactory factory = metaFactory.getOMFactory();
        OMElement parent = factory.createOMElement("parent", null);
        OMSourcedElement omse = factory.createOMElement(bads1, "myPayload", factory.createOMNamespace("urn://test", "tns"));
        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());
        assertTrue("OMSourcedElement should be backed by a ByteArrayDataSource",
                   child.getDataSource() instanceof ByteArrayDataSource);
       
        // Write out the body
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        parent.serialize(baos);
        String output = baos.toString(ENCODING);
//        System.out.println(output);
        assertTrue("The payload was not present in the output",
                   output.indexOf(payload1) > 0);
        assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
       
        // Replace with payload2. 
        // Important note, it is legal to replace the OMDataSource, but
        // the namespace and local name of the OMSourcedElement cannot be changed.
        child.setDataSource(bads2);
       
        // Write out the body
        baos = new ByteArrayOutputStream();
        parent.serialize(baos);
        output = baos.toString(ENCODING);
//        System.out.println(output);
        assertTrue("The payload was not present in the output",
                   output.indexOf(payload2) > 0);
        assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
       
        // Now Replace with payload1 from an InputStreamDataSource
        child.setDataSource(isds1);
        baos = new ByteArrayOutputStream();
        parent.serialize(baos);
        output = baos.toString(ENCODING);
//        System.out.println(output);
        assertTrue("The payload was not present in the output",
                   output.indexOf(payload1) > 0);
       
        // Now Replace with payload2 from an InputStreamDataSource.
        // Note at this point, the child's tree is expanded.
        child.setDataSource(isds2);
        baos = new ByteArrayOutputStream();
        parent.serialize(baos);
        output = baos.toString(ENCODING);
//        System.out.println(output);
        assertTrue("The payload was not present in the output",
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMDataSource ds = new WrappedTextNodeOMDataSourceFromDataSource(new QName("wrapper"),
                new ByteArrayDataSource("test".getBytes("utf-8")), Charset.forName("utf-8"));
        OMSourcedElement element = factory.createOMElement(ds);
        OMCloneOptions options = new OMCloneOptions();
        options.setCopyOMDataSources(copyOMDataSources);
        OMElement clone = (OMElement)element.clone(options);
        if (copyOMDataSources) {
            assertTrue(clone instanceof OMSourcedElement);
            assertFalse(element.isExpanded());
        } else {
            assertFalse(clone instanceof OMSourcedElement);
            assertTrue(clone.isComplete());
        }
        assertEquals("test", clone.getText());
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        OMNamespace ns = factory.createOMNamespace("urn://test", "tns");
        ByteArrayInputStream bais1 = new ByteArrayInputStream(payload1.getBytes(encoding));
        InputStreamDataSource isds1 = new InputStreamDataSource(bais1, encoding);
       
        OMElement parent = factory.createOMElement("root", null);
        OMSourcedElement omse = factory.createOMElement(isds1, 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());
        assertTrue("OMSourcedElement should be backed by a InputStreamDataSource",
                   child.getDataSource() instanceof InputStreamDataSource);
       
        // A InputStreamDataSource consumes the backing object when read.
        // Thus getting the XMLStreamReader of the ByteArrayDataSource should 
        // cause expansion of the OMSourcedElement.
        XMLStreamReader reader = child.getXMLStreamReader();
        reader.next();
        assertTrue("OMSourcedElement is not expanded.  This is unexpected",
                   child.isExpanded());
       
        child.detach();
       
        // Reset the tree
        isds1 = new InputStreamDataSource(
            new ByteArrayInputStream(payload1.getBytes(encoding)),
            encoding);
        omse = factory.createOMElement(isds1, localName, ns);
        parent.addChild(omse);
        firstChild = parent.getFirstOMChild();
        child = (OMSourcedElement) firstChild;
       
        // Likewise, an InputStreamDataSource consumes the backing object when
        // written.  Thus serializing the OMSourcedElement should cause the expansion
        // of the OMSourcedElement.
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        parent.serialize(baos);
        String output = baos.toString(encoding);
        assertTrue("The payload was not present in the output",
                   output.indexOf(payload1) > 0);
        assertTrue("OMSourcedElement is not expanded.  This is unexpected", child.isExpanded());
       
        // Reset the tree
        child.detach();
        isds1 = new InputStreamDataSource(
            new ByteArrayInputStream(payload1.getBytes(encoding)),
            encoding);
        omse = factory.createOMElement(isds1, localName, ns);
        parent.addChild(omse);
        firstChild = parent.getFirstOMChild();
        child = (OMSourcedElement) firstChild;
       
        // Test getting the raw bytes from the ByteArrayDataSource.
        OMDataSourceExt ds = (OMDataSourceExt) child.getDataSource();
        byte[] bytes = ds.getXMLBytes(encoding)// Get the bytes as UTF-16
        String payload = new String(bytes, encoding);
        assertTrue("The obtained bytes did not match the payload",
                   payload1.equals(payload));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.