Search in sources :

Example 1 with OMSerializable

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

the class MTOMStAXSOAPModelBuilderTest method testDeferredLoadingOfAttachments.

/**
     * Test that MIME parts are not loaded before requesting the DataHandlers from the corresponding
     * OMText nodes.
     *  
     * @throws Exception
     */
public void testDeferredLoadingOfAttachments() throws Exception {
    Attachments attachments = createAttachmentsForTestMTOMMessage();
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments);
    OMDocument doc = builder.getDocument();
    // Find all the binary nodes
    List<OMText> binaryNodes = new ArrayList<>();
    for (Iterator<OMSerializable> it = doc.getDescendants(false); it.hasNext(); ) {
        OMSerializable node = it.next();
        if (node instanceof OMText) {
            OMText text = (OMText) node;
            if (text.isBinary()) {
                binaryNodes.add(text);
            }
        }
    }
    assertFalse(binaryNodes.isEmpty());
    // At this moment only the SOAP part should have been loaded
    assertEquals(1, attachments.getContentIDList().size());
    for (OMText node : binaryNodes) {
        // Request the DataHandler and do something with it to make sure
        // the part is loaded
        node.getDataHandler().getInputStream().close();
    }
    assertEquals(binaryNodes.size() + 1, attachments.getContentIDList().size());
}
Also used : ArrayList(java.util.ArrayList) OMText(org.apache.axiom.om.OMText) OMSerializable(org.apache.axiom.om.OMSerializable) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) Attachments(org.apache.axiom.attachments.Attachments) OMDocument(org.apache.axiom.om.OMDocument)

Example 2 with OMSerializable

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

the class TestCreateOMAttributeInterfaces method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("urn:test", "p");
    OMAttribute attr = factory.createOMAttribute("attr", ns, "value");
    assertFalse(attr instanceof OMSerializable);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMSerializable(org.apache.axiom.om.OMSerializable) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 3 with OMSerializable

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

the class TestSetOptimize method runTest.

@Override
protected void runTest() throws Throwable {
    InputStream in = XOP_SPEC_SAMPLE.getInputStream();
    try {
        OMDocument document = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, MultipartBody.builder().setInputStream(in).setContentType(XOP_SPEC_SAMPLE.getContentType()).build()).getDocument();
        for (Iterator<OMSerializable> it = document.getDescendants(false); it.hasNext(); ) {
            OMSerializable node = it.next();
            if (node instanceof OMText) {
                OMText text = (OMText) node;
                if (text.isBinary()) {
                    text.setOptimize(optimize);
                }
            }
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        OMOutputFormat format = new OMOutputFormat();
        format.setDoOptimize(true);
        document.serialize(out, format);
        Multipart mp = new MimeMultipart(new ByteArrayDataSource(out.toByteArray(), format.getContentType()));
        assertThat(mp.getCount()).isEqualTo(optimize ? 3 : 1);
    } finally {
        in.close();
    }
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) Multipart(javax.mail.Multipart) MimeMultipart(javax.mail.internet.MimeMultipart) InputStream(java.io.InputStream) OMText(org.apache.axiom.om.OMText) OMSerializable(org.apache.axiom.om.OMSerializable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMSerializable (org.apache.axiom.om.OMSerializable)3 OMDocument (org.apache.axiom.om.OMDocument)2 OMText (org.apache.axiom.om.OMText)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Multipart (javax.mail.Multipart)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)1 Attachments (org.apache.axiom.attachments.Attachments)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMFactory (org.apache.axiom.om.OMFactory)1 OMNamespace (org.apache.axiom.om.OMNamespace)1 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)1 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)1