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());
}
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);
}
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();
}
}
Aggregations