Search in sources :

Example 1 with TestDataSource

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

the class DataHandlerTest method test.

private void test(String feature) {
    DataHandler dh = new DataHandler(new TestDataSource('x', 1000));
    SOAPEnvelope envelope = OMAbstractFactory.getMetaFactory(feature).getSOAP11Factory().createDefaultSOAPMessage().getSOAPEnvelope();
    PayloadHelper.setBinaryPayload(envelope, dh);
    assertThat(PayloadHelper.getBinaryPayload(envelope)).isSameAs(dh);
}
Also used : TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 2 with TestDataSource

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

the class TestMTOMForwardStreaming method runTest.

@Override
protected void runTest() throws Throwable {
    DataSource ds1 = new TestDataSource('A', Runtime.getRuntime().maxMemory());
    DataSource ds2 = new TestDataSource('B', Runtime.getRuntime().maxMemory());
    // Programmatically create the original message
    SOAPFactory factory = metaFactory.getSOAP12Factory();
    final SOAPEnvelope orgEnvelope = factory.createSOAPEnvelope();
    SOAPBody orgBody = factory.createSOAPBody(orgEnvelope);
    OMElement orgBodyElement = factory.createOMElement("test", factory.createOMNamespace("urn:test", "p"), orgBody);
    OMElement orgData1 = factory.createOMElement("data", null, orgBodyElement);
    orgData1.addChild(factory.createOMText(new DataHandler(ds1), true));
    OMElement orgData2 = factory.createOMElement("data", null, orgBodyElement);
    orgData2.addChild(factory.createOMText(new DataHandler(ds2), true));
    final OMOutputFormat format = new OMOutputFormat();
    format.setDoOptimize(true);
    format.setSOAP11(false);
    final String contentType = format.getContentType();
    final PipedOutputStream pipe1Out = new PipedOutputStream();
    final PipedInputStream pipe1In = new PipedInputStream(pipe1Out);
    // Create the producer thread (simulating the client sending the MTOM message)
    Thread producerThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                try {
                    orgEnvelope.serialize(pipe1Out, format);
                } finally {
                    pipe1Out.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    producerThread.start();
    final PipedOutputStream pipe2Out = new PipedOutputStream();
    PipedInputStream pipe2In = new PipedInputStream(pipe2Out);
    // Create the forwarder thread (simulating the mediation engine that forwards the message)
    Thread forwarderThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                try {
                    MultipartBody mb = MultipartBody.builder().setInputStream(pipe1In).setContentType(contentType).build();
                    SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).getSOAPEnvelope();
                    // the element is built. Therefore we need two different test executions.
                    if (buildSOAPPart) {
                        envelope.build();
                    }
                    // Usage of serializeAndConsume should enable streaming
                    envelope.serializeAndConsume(pipe2Out, format);
                } finally {
                    pipe2Out.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    forwarderThread.start();
    try {
        MultipartBody mb = MultipartBody.builder().setInputStream(pipe2In).setContentType(contentType).build();
        SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).getSOAPEnvelope();
        OMElement bodyElement = envelope.getBody().getFirstElement();
        Iterator<OMElement> it = bodyElement.getChildElements();
        OMElement data1 = it.next();
        OMElement data2 = it.next();
        IOTestUtils.compareStreams(ds1.getInputStream(), ((PartDataHandler) ((OMText) data1.getFirstOMChild()).getDataHandler()).getPart().getInputStream(false));
        IOTestUtils.compareStreams(ds2.getInputStream(), ((PartDataHandler) ((OMText) data2.getFirstOMChild()).getDataHandler()).getPart().getInputStream(false));
    } finally {
        pipe2In.close();
    }
}
Also used : TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) OMElement(org.apache.axiom.om.OMElement) PipedOutputStream(java.io.PipedOutputStream) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) DataHandler(javax.activation.DataHandler) PartDataHandler(org.apache.axiom.mime.PartDataHandler) PipedInputStream(java.io.PipedInputStream) SOAPFactory(org.apache.axiom.soap.SOAPFactory) DataSource(javax.activation.DataSource) TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) SOAPBody(org.apache.axiom.soap.SOAPBody) PartDataHandler(org.apache.axiom.mime.PartDataHandler) MultipartBody(org.apache.axiom.mime.MultipartBody) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 3 with TestDataSource

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

the class TestRegisterCustomBuilderForPayloadJAXBWithDataHandlerReaderExtension method runTest.

@Override
protected void runTest() throws Throwable {
    DataHandler dh = new DataHandler(new TestDataSource('X', Integer.MAX_VALUE));
    OMElement document = createTestDocument(dh);
    test(dh, OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), document.getXMLStreamReader()), true);
}
Also used : TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler)

Example 4 with TestDataSource

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

the class TestBase64StreamingWithSerialize 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 TestDataSource('A', Runtime.getRuntime().maxMemory());
    OMText text = factory.createOMText(new DataHandler(ds), false);
    elem.addChild(text);
    elem.serialize(new NullOutputStream());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) DataSource(javax.activation.DataSource) TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Example 5 with TestDataSource

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

the class XOPRoundtripTest method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    DataHandler dh = new DataHandler(new TestDataSource('x', Runtime.getRuntime().maxMemory()));
    OMElement element1 = factory.createOMElement(new QName("test"));
    element1.addChild(factory.createOMText(dh, true));
    XOPEncoded<XMLStreamReader> xopEncodedStream = element1.getXOPEncodedStreamReader(true);
    OMElement element2 = OMXMLBuilderFactory.createOMBuilder(factory, new StAXSource(xopEncodedStream.getRootPart()), xopEncodedStream.getAttachmentAccessor()).getDocumentElement();
    OMText child = (OMText) element2.getFirstOMChild();
    assertNotNull(child);
    assertTrue(child.isBinary());
    assertTrue(child.isOptimized());
    assertSame(dh, child.getDataHandler());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) StAXSource(javax.xml.transform.stax.StAXSource)

Aggregations

DataHandler (javax.activation.DataHandler)5 TestDataSource (org.apache.axiom.testutils.activation.TestDataSource)5 OMElement (org.apache.axiom.om.OMElement)4 DataSource (javax.activation.DataSource)2 OMFactory (org.apache.axiom.om.OMFactory)2 OMText (org.apache.axiom.om.OMText)2 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)2 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 QName (javax.xml.namespace.QName)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 StAXSource (javax.xml.transform.stax.StAXSource)1 MultipartBody (org.apache.axiom.mime.MultipartBody)1 PartDataHandler (org.apache.axiom.mime.PartDataHandler)1 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)1 SOAPBody (org.apache.axiom.soap.SOAPBody)1 SOAPFactory (org.apache.axiom.soap.SOAPFactory)1 NullOutputStream (org.apache.commons.io.output.NullOutputStream)1