Search in sources :

Example 21 with OMXMLParserWrapper

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

the class TestGetXMLStreamReader method runTest.

@Override
protected final void runTest() throws Throwable {
    InputStream in = file.getInputStream();
    try {
        XMLStreamReader expected = StAXUtils.createXMLStreamReader(TEST_PARSER_CONFIGURATION, file.getUrl().toString(), in);
        try {
            OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(file.getUrl().toString()));
            try {
                XMLStreamReader actual = containerExtractor.getContainer(builder).getXMLStreamReader(cache);
                XMLStreamReaderComparator comparator = new XMLStreamReaderComparator(containerExtractor.filter(expected), containerExtractor.filter(actual));
                builderFactory.configureXMLStreamReaderComparator(comparator);
                comparator.compare();
            } finally {
                builder.close();
            }
        } finally {
            expected.close();
        }
    } finally {
        in.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamReaderComparator(org.apache.axiom.testutils.stax.XMLStreamReaderComparator) InputStream(java.io.InputStream) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 22 with OMXMLParserWrapper

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

the class TestSerialize method runTest.

@Override
protected void runTest() throws Throwable {
    OMXMLParserWrapper builder = file.getAdapter(XMLSampleAdapter.class).getBuilder(metaFactory);
    try {
        OMContainer container = containerExtractor.getContainer(builder);
        // We need to clone the InputSource objects so that we can dump their contents
        // if the test fails
        InputSource[] control = duplicateInputSource(containerExtractor.getControl(file.getInputStream()));
        XML actual = serializationStrategy.serialize(container);
        try {
            // Configure the InputSources such that external entities can be resolved
            String systemId = new URL(file.getUrl(), "dummy.xml").toString();
            control[0].setSystemId(systemId);
            InputSource actualIS = actual.getInputSource();
            actualIS.setSystemId(systemId);
            assertAbout(xml()).that(actualIS).ignoringElementContentWhitespace().hasSameContentAs(control[0]);
        } catch (Throwable ex) {
            System.out.println("Control:");
            dumpInputSource(control[1]);
            System.out.println("Actual:");
            actual.dump(System.out);
            throw ex;
        }
        if (serializationStrategy.isCaching()) {
            assertTrue(container.isComplete());
        } else {
            // TODO: need to investigate why assertConsumed is not working here
            assertFalse(container.isComplete());
        //                assertConsumed(element);
        }
    } finally {
        builder.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) XML(org.apache.axiom.ts.dimension.serialization.XML) XMLSampleAdapter(org.apache.axiom.ts.om.XMLSampleAdapter) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) OMContainer(org.apache.axiom.om.OMContainer) URL(java.net.URL)

Example 23 with OMXMLParserWrapper

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

the class TestGetDocumentElementWithIllFormedDocument method runTest.

@Override
protected void runTest() throws Throwable {
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<!--comment1-->"));
    try {
        builder.getDocumentElement();
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : StringReader(java.io.StringReader) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) OMException(org.apache.axiom.om.OMException)

Example 24 with OMXMLParserWrapper

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

the class TestReadAttachmentBeforeRootPartComplete method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    // Programmatically create the message
    OMElement orgRoot = factory.createOMElement("root", null);
    OMElement orgChild1 = factory.createOMElement("child1", null, orgRoot);
    DataSource ds = new RandomDataSource(54321, 4096);
    orgChild1.addChild(factory.createOMText(new DataHandler(ds), true));
    // Create a child with a large text content and insert it after the binary node.
    // If we don't do this, then the root part may be buffered entirely by the parser,
    // and the test would not be effective.
    OMElement orgChild2 = factory.createOMElement("child2", null, orgRoot);
    String s = RandomUtils.randomString(128 * 1024);
    orgChild2.setText(s);
    // Serialize the message
    OMOutputFormat format = new OMOutputFormat();
    format.setDoOptimize(true);
    MemoryBlob blob = Blobs.createMemoryBlob();
    OutputStream out = blob.getOutputStream();
    orgRoot.serialize(out, format);
    out.close();
    // Parse the message
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.NON_COALESCING, MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build());
    OMElement root = builder.getDocumentElement();
    OMElement child1 = (OMElement) root.getFirstOMChild();
    OMText text = (OMText) child1.getFirstOMChild();
    assertTrue(text.isBinary());
    // Access the DataHandler
    DataHandler dh = text.getDataHandler();
    IOTestUtils.compareStreams(ds.getInputStream(), dh.getInputStream());
    OMElement child2 = (OMElement) child1.getNextOMSibling();
    assertFalse(child2.isComplete());
    assertEquals(s, child2.getText());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) MemoryBlob(org.apache.axiom.blob.MemoryBlob) OutputStream(java.io.OutputStream) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Example 25 with OMXMLParserWrapper

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

the class TestDetachWithStream method runTest.

@Override
protected final void runTest() throws Throwable {
    InstrumentedStream stream = streamType.instrumentStream(streamType.getStream(XMLSample.LARGE));
    OMXMLParserWrapper builder;
    if (useStreamSource) {
        builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), streamType.createStreamSource(stream));
    } else {
        builder = streamType.getAdapter(StreamTypeAdapter.class).createOMBuilder(metaFactory.getOMFactory(), stream);
    }
    long countBeforeDetach = stream.getCount();
    builder.detach();
    assertThat(stream.getCount()).isGreaterThan(countBeforeDetach);
    assertThat(stream.isClosed()).isFalse();
    stream.close();
    builder.getDocument().build();
}
Also used : InstrumentedStream(org.apache.axiom.testutils.io.InstrumentedStream) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Aggregations

OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)37 OMElement (org.apache.axiom.om.OMElement)21 StringReader (java.io.StringReader)12 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMFactory (org.apache.axiom.om.OMFactory)8 InputSource (org.xml.sax.InputSource)8 OMNode (org.apache.axiom.om.OMNode)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 QName (javax.xml.namespace.QName)3 OMAttribute (org.apache.axiom.om.OMAttribute)3 OMDocument (org.apache.axiom.om.OMDocument)3 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)3 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 DOMSource (javax.xml.transform.dom.DOMSource)2 SAXSource (javax.xml.transform.sax.SAXSource)2 NodeUnavailableException (org.apache.axiom.om.NodeUnavailableException)2 OMException (org.apache.axiom.om.OMException)2 OMNamespace (org.apache.axiom.om.OMNamespace)2