Search in sources :

Example 1 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource 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());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) SAXSource(javax.xml.transform.sax.SAXSource) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) XMLReader(org.xml.sax.XMLReader) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Example 2 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.

the class TestRegisterCustomBuilderForPayloadJAXBPlain method runTest.

@Override
protected void runTest() throws Throwable {
    DataHandler dh = new DataHandler(new RandomDataSource(10000));
    MemoryBlob blob = Blobs.createMemoryBlob();
    OutputStream out = blob.getOutputStream();
    createTestDocument(dh).serialize(out);
    out.close();
    test(dh, OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), blob.getInputStream()), false);
}
Also used : RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) MemoryBlob(org.apache.axiom.blob.MemoryBlob) OutputStream(java.io.OutputStream) DataHandler(javax.activation.DataHandler)

Example 3 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.

the class TestRegisterCustomBuilderForPayloadJAXBWithXOP method runTest.

@Override
protected void runTest() throws Throwable {
    DataHandler dh = new DataHandler(new RandomDataSource(10000));
    MemoryBlob blob = Blobs.createMemoryBlob();
    OutputStream out = blob.getOutputStream();
    OMOutputFormat format = new OMOutputFormat();
    format.setDoOptimize(true);
    createTestDocument(dh).serialize(out, format);
    out.close();
    MultipartBody mb = MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build();
    test(dh, OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, mb), false);
}
Also used : RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) MemoryBlob(org.apache.axiom.blob.MemoryBlob) MultipartBody(org.apache.axiom.mime.MultipartBody) OutputStream(java.io.OutputStream) DataHandler(javax.activation.DataHandler) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 4 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.

the class TestGetDataHandlerFromElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    RandomDataSource orgDS = new RandomDataSource(64 * 1024);
    OMElement orgRoot = factory.createOMElement(new QName("root"));
    OMElement orgChild = factory.createOMElement(new QName("child"), orgRoot);
    orgChild.addChild(factory.createOMText(new DataHandler(orgDS), false));
    OMElement root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(orgRoot.toString())).getDocumentElement();
    XMLStreamReader reader = root.getXMLStreamReader(cache);
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    DataSource ds = XMLStreamReaderUtils.getDataHandlerFromElement(reader).getDataSource();
    IOTestUtils.compareStreams(orgDS.getInputStream(), ds.getInputStream());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Example 5 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource 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)

Aggregations

RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)14 DataHandler (javax.activation.DataHandler)10 DataSource (javax.activation.DataSource)10 OMFactory (org.apache.axiom.om.OMFactory)9 OMElement (org.apache.axiom.om.OMElement)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStreamReader (java.io.InputStreamReader)3 OutputStream (java.io.OutputStream)3 Reader (java.io.Reader)3 StringReader (java.io.StringReader)3 QName (javax.xml.namespace.QName)3 MemoryBlob (org.apache.axiom.blob.MemoryBlob)3 OMText (org.apache.axiom.om.OMText)3 Charset (java.nio.charset.Charset)2 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)2 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 WrappedTextNodeOMDataSourceFromDataSource (org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource)2 Text (org.w3c.dom.Text)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1