Search in sources :

Example 1 with MTOMSample

use of org.apache.axiom.ts.soap.MTOMSample in project webservices-axiom by apache.

the class TestBuildWithAttachments method runTest.

@Override
protected void runTest() throws Throwable {
    MTOMSample sample = MTOMSample.SAMPLE1;
    InputStream in = sample.getInputStream();
    MultipartBody mb = MultipartBody.builder().setInputStream(in).setContentType(sample.getContentType()).build();
    SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).getSOAPEnvelope();
    envelope.buildWithAttachments();
    in.close();
    Iterator<OMElement> it = envelope.getBody().getFirstElement().getChildElements();
    OMElement image1 = it.next();
    OMElement image2 = it.next();
    IOTestUtils.compareStreams(((OMText) image1.getFirstOMChild()).getDataHandler().getInputStream(), sample.getPart(1));
    IOTestUtils.compareStreams(((OMText) image2.getFirstOMChild()).getDataHandler().getInputStream(), sample.getPart(2));
}
Also used : InputStream(java.io.InputStream) MultipartBody(org.apache.axiom.mime.MultipartBody) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) MTOMSample(org.apache.axiom.ts.soap.MTOMSample) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 2 with MTOMSample

use of org.apache.axiom.ts.soap.MTOMSample in project webservices-axiom by apache.

the class TestBuilderDetach method runTest.

@Override
protected void runTest() throws Throwable {
    MTOMSample sample = MTOMSample.SAMPLE1;
    InstrumentedInputStream in = new InstrumentedInputStream(sample.getInputStream());
    MultipartBody mb = MultipartBody.builder().setInputStream(in).setContentType(sample.getContentType()).build();
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb);
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    long countBeforeDetach = in.getCount();
    builder.detach();
    assertThat(in.getCount()).isGreaterThan(countBeforeDetach);
    assertThat(in.isClosed()).isFalse();
    int binaryCount = 0;
    for (Iterator<OMNode> it = envelope.getDescendants(false); it.hasNext(); ) {
        OMNode node = it.next();
        if (node instanceof OMText) {
            OMText text = (OMText) node;
            if (text.isBinary()) {
                IOTestUtils.compareStreams(sample.getPart(text.getContentID()), text.getDataHandler().getInputStream());
                binaryCount++;
            }
        }
    }
    assertThat(binaryCount).isGreaterThan(0);
    in.close();
}
Also used : OMNode(org.apache.axiom.om.OMNode) MultipartBody(org.apache.axiom.mime.MultipartBody) InstrumentedInputStream(org.apache.axiom.testutils.io.InstrumentedInputStream) OMText(org.apache.axiom.om.OMText) MTOMSample(org.apache.axiom.ts.soap.MTOMSample) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 3 with MTOMSample

use of org.apache.axiom.ts.soap.MTOMSample in project webservices-axiom by apache.

the class AttachmentsTest method testGetIncomingAttachmentStreams2.

public void testGetIncomingAttachmentStreams2() throws Exception {
    MTOMSample sample = MTOMSample.SAMPLE1;
    IncomingAttachmentInputStream dataIs;
    InputStream expectedDataIs;
    InputStream inStream = sample.getInputStream();
    Attachments attachments = new Attachments(inStream, sample.getContentType());
    // Since SOAP part operated independently of other streams, access it
    // directly, and then get to the streams. If this sequence throws an
    // error, something is wrong with the stream handling code.
    InputStream is = attachments.getRootPartInputStream();
    while (is.read() != -1) ;
    // Get the inputstream container
    IncomingAttachmentStreams ias = attachments.getIncomingAttachmentStreams();
    dataIs = ias.getNextStream();
    expectedDataIs = sample.getPart(1);
    IOTestUtils.compareStreams(dataIs, expectedDataIs);
    dataIs = ias.getNextStream();
    expectedDataIs = sample.getPart(2);
    IOTestUtils.compareStreams(dataIs, expectedDataIs);
    // Confirm that no more streams are left
    assertNull(ias.getNextStream());
    // After all is done, we should *still* be able to access and
    // re-consume the SOAP part stream, as it should be cached.. can we?
    is = attachments.getRootPartInputStream();
    while (is.read() != -1) ;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) InputStream(java.io.InputStream) MTOMSample(org.apache.axiom.ts.soap.MTOMSample)

Example 4 with MTOMSample

use of org.apache.axiom.ts.soap.MTOMSample in project webservices-axiom by apache.

the class TestSerialize method runTest.

@Override
protected void runTest() throws Throwable {
    MTOMSample testMessage = MTOMSample.SAMPLE1;
    // Read in message: SOAPPart and 2 image attachments
    InputStream inStream = testMessage.getInputStream();
    MultipartBody mb = MultipartBody.builder().setInputStream(inStream).setContentType(testMessage.getContentType()).build();
    OMOutputFormat oof = new OMOutputFormat();
    oof.setDoOptimize(true);
    oof.setMimeBoundary(testMessage.getBoundary());
    oof.setRootContentId(testMessage.getStart());
    if (base64) {
        oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS, Boolean.TRUE);
    }
    // Write out the message
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, mb);
    OMElement om = builder.getDocumentElement();
    om.serialize(baos, oof);
    om.close(false);
    String out = baos.toString();
    if (base64) {
        // Do a quick check to see if the data is base64 and is
        // writing base64 compliant code.
        assertTrue(out.indexOf("base64") != -1);
        assertTrue(out.indexOf("GBgcGBQgHBwcJCQgKDBQNDAsL") != -1);
    } else {
        assertTrue(out.indexOf("base64") == -1);
    }
}
Also used : InputStream(java.io.InputStream) MultipartBody(org.apache.axiom.mime.MultipartBody) OMElement(org.apache.axiom.om.OMElement) MTOMSample(org.apache.axiom.ts.soap.MTOMSample) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Aggregations

MTOMSample (org.apache.axiom.ts.soap.MTOMSample)4 InputStream (java.io.InputStream)3 MultipartBody (org.apache.axiom.mime.MultipartBody)3 OMElement (org.apache.axiom.om.OMElement)2 OMText (org.apache.axiom.om.OMText)2 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PipedInputStream (java.io.PipedInputStream)1 OMNode (org.apache.axiom.om.OMNode)1 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)1 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)1 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)1 ExceptionInputStream (org.apache.axiom.testutils.io.ExceptionInputStream)1 InstrumentedInputStream (org.apache.axiom.testutils.io.InstrumentedInputStream)1