use of org.apache.axiom.attachments.Attachments 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.attachments.Attachments in project webservices-axiom by apache.
the class XOPEncodingStreamReaderTest method test.
public void test() throws Exception {
Attachments[] attachments = new Attachments[2];
XMLStreamReader[] soapPartReader = new XMLStreamReader[2];
for (int i = 0; i < 2; i++) {
attachments[i] = new Attachments(MTOMSample.SAMPLE1.getInputStream(), MTOMSample.SAMPLE1.getContentType());
soapPartReader[i] = StAXUtils.createXMLStreamReader(attachments[i].getRootPartInputStream());
}
XMLStreamReader actual = new XOPEncodingStreamReader(new XOPDecodingStreamReader(soapPartReader[1], new AttachmentsMimePartProvider(attachments[1])), contentIDGenerator, OptimizationPolicy.DEFAULT);
new XMLStreamReaderComparator(soapPartReader[0], actual).compare();
for (int i = 0; i < 2; i++) {
soapPartReader[i].close();
}
}
use of org.apache.axiom.attachments.Attachments in project webservices-axiom by apache.
the class MTOMStAXSOAPModelBuilderTest method testUTF16MTOMMessage.
public void testUTF16MTOMMessage() throws Exception {
String contentTypeString = "multipart/Related; charset=\"UTF-8\"; type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"SOAPPart\"";
String cid = "1.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org";
String xmlPlusMime1 = "------=_AxIs2_Def_boundary_=42214532\r\n" + "Content-Type: application/xop+xml; charset=UTF-16; type=\"application/soap+xml\"\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "Content-ID: SOAPPart\r\n" + "\r\n";
String xmlPlusMime2 = "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"><soapenv:Body><m:data xmlns:m=\"http://www.example.org/stuff\"><m:name m:contentType=\"text/plain\"><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"cid:" + cid + "\"></xop:Include></m:name></m:data></soapenv:Body></soapenv:Envelope>\r\n";
String xmlPlusMime3 = "\r\n------=_AxIs2_Def_boundary_=42214532\r\n" + "Content-Transfer-Encoding: binary\r\n" + "Content-ID: " + cid + "\r\n" + "\r\n" + "Foo Bar\r\n" + "------=_AxIs2_Def_boundary_=42214532--\r\n";
byte[] bytes1 = xmlPlusMime1.getBytes();
byte[] bytes2 = xmlPlusMime2.getBytes("UTF-16");
byte[] bytes3 = xmlPlusMime3.getBytes();
byte[] full = append(bytes1, bytes2);
full = append(full, bytes3);
InputStream inStream = new BufferedInputStream(new ByteArrayInputStream(full));
Attachments attachments = new Attachments(inStream, contentTypeString);
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments);
OMElement root = builder.getDocumentElement();
root.build();
}
Aggregations