use of org.apache.cxf.message.Attachment in project cxf by apache.
the class AttachmentDeserializerTest method testDeserializerSwA.
@Test
public void testDeserializerSwA() throws Exception {
InputStream is = getClass().getResourceAsStream("swadata");
String ct = "multipart/related; type=\"text/xml\"; " + "start=\"<86048FF3556694F7DA1918466DDF8143>\"; " + "boundary=\"----=_Part_0_14158819.1167275505862\"";
msg.put(Message.CONTENT_TYPE, ct);
msg.setContent(InputStream.class, is);
AttachmentDeserializer deserializer = new AttachmentDeserializer(msg);
deserializer.initializeAttachments();
InputStream attBody = msg.getContent(InputStream.class);
assertTrue(attBody != is);
assertTrue(attBody instanceof DelegatingInputStream);
Collection<Attachment> atts = msg.getAttachments();
assertNotNull(atts);
Iterator<Attachment> itr = atts.iterator();
assertTrue(itr.hasNext());
Attachment a = itr.next();
assertNotNull(a);
InputStream attIs = a.getDataHandler().getInputStream();
// check the cached output stream
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
IOUtils.copy(attBody, out);
assertTrue(out.toString().startsWith("<?xml"));
}
// try streaming a character off the wire
assertTrue(attIs.read() == 'f');
assertTrue(attIs.read() == 'o');
assertTrue(attIs.read() == 'o');
assertTrue(attIs.read() == 'b');
assertTrue(attIs.read() == 'a');
assertTrue(attIs.read() == 'r');
assertTrue(attIs.read() == -1);
is.close();
}
use of org.apache.cxf.message.Attachment in project cxf by apache.
the class AttachmentDeserializerTest method testDeserializerMtom.
@Test
public void testDeserializerMtom() throws Exception {
InputStream is = getClass().getResourceAsStream("mimedata");
String ct = "multipart/related; type=\"application/xop+xml\"; " + "start=\"<soap.xml@xfire.codehaus.org>\"; " + "start-info=\"text/xml; charset=utf-8\"; " + "boundary=\"----=_Part_4_701508.1145579811786\"";
msg.put(Message.CONTENT_TYPE, ct);
msg.setContent(InputStream.class, is);
AttachmentDeserializer deserializer = new AttachmentDeserializer(msg);
deserializer.initializeAttachments();
InputStream attBody = msg.getContent(InputStream.class);
assertTrue(attBody != is);
assertTrue(attBody instanceof DelegatingInputStream);
Collection<Attachment> atts = msg.getAttachments();
assertNotNull(atts);
Iterator<Attachment> itr = atts.iterator();
assertTrue(itr.hasNext());
Attachment a = itr.next();
assertNotNull(a);
InputStream attIs = a.getDataHandler().getInputStream();
// check the cached output stream
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
IOUtils.copy(attBody, out);
assertTrue(out.toString().startsWith("<env:Envelope"));
}
// try streaming a character off the wire
assertEquals(255, attIs.read());
assertEquals(216, (char) attIs.read());
// Attachment invalid = atts.get("INVALID");
// assertNull(invalid.getDataHandler().getInputStream());
//
// assertTrue(attIs instanceof ByteArrayInputStream);
is.close();
}
use of org.apache.cxf.message.Attachment in project cxf by apache.
the class AttachmentDeserializerTest method testDeserializerWithCachedFile.
@Test
public void testDeserializerWithCachedFile() throws Exception {
InputStream is = getClass().getResourceAsStream("mimedata");
String ct = "multipart/related; type=\"application/xop+xml\"; " + "start=\"<soap.xml@xfire.codehaus.org>\"; " + "start-info=\"text/xml; charset=utf-8\"; " + "boundary=\"----=_Part_4_701508.1145579811786\"";
msg.put(Message.CONTENT_TYPE, ct);
msg.setContent(InputStream.class, is);
msg.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, "10");
AttachmentDeserializer deserializer = new AttachmentDeserializer(msg);
deserializer.initializeAttachments();
InputStream attBody = msg.getContent(InputStream.class);
assertTrue(attBody != is);
assertTrue(attBody instanceof DelegatingInputStream);
Collection<Attachment> atts = msg.getAttachments();
assertNotNull(atts);
Iterator<Attachment> itr = atts.iterator();
assertTrue(itr.hasNext());
Attachment a = itr.next();
assertNotNull(a);
InputStream attIs = a.getDataHandler().getInputStream();
assertFalse(itr.hasNext());
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
IOUtils.copy(attIs, out);
assertTrue(out.size() > 1000);
}
is.close();
}
use of org.apache.cxf.message.Attachment in project cxf by apache.
the class AttachmentDeserializerTest method testLazyAttachmentCollection.
@Test
public void testLazyAttachmentCollection() throws Exception {
InputStream is = getClass().getResourceAsStream("mimedata2");
String ct = "multipart/related; type=\"application/xop+xml\"; " + "start=\"<soap.xml@xfire.codehaus.org>\"; " + "start-info=\"text/xml; charset=utf-8\"; " + "boundary=\"----=_Part_4_701508.1145579811786\"";
msg.put(Message.CONTENT_TYPE, ct);
msg.setContent(InputStream.class, is);
AttachmentDeserializer deserializer = new AttachmentDeserializer(msg);
deserializer.initializeAttachments();
InputStream attBody = msg.getContent(InputStream.class);
assertTrue(attBody != is);
assertTrue(attBody instanceof DelegatingInputStream);
attBody.close();
assertEquals(2, msg.getAttachments().size());
List<String> cidlist = new ArrayList<>();
cidlist.add("xfire_logo.jpg");
cidlist.add("xfire_logo2.jpg");
for (Iterator<Attachment> it = msg.getAttachments().iterator(); it.hasNext(); ) {
Attachment a = it.next();
assertTrue(cidlist.remove(a.getId()));
it.remove();
}
assertEquals(0, cidlist.size());
assertEquals(0, msg.getAttachments().size());
is.close();
}
use of org.apache.cxf.message.Attachment in project cxf by apache.
the class JAXBAttachmentMarshaller method addMtomAttachment.
public String addMtomAttachment(DataHandler handler, String elementNS, String elementLocalName) {
Attachment att = AttachmentUtil.createMtomAttachmentFromDH(isXop, handler, elementNS, threshold);
if (att != null) {
atts.add(att);
lastElementName = new QName(elementNS, elementLocalName);
return "cid:" + att.getId();
}
return null;
}
Aggregations