use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class ReadHeaderInterceptorTest method testBadSOAPEnvelopeName.
@Test
public void testBadSOAPEnvelopeName() throws Exception {
soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
InputStream in = getClass().getResourceAsStream("test-bad-envname.xml");
assertNotNull(in);
ByteArrayDataSource bads = new ByteArrayDataSource(in, "test/xml");
soapMessage.setContent(InputStream.class, bads.getInputStream());
ReadHeadersInterceptor r = new ReadHeadersInterceptor(BusFactory.getDefaultBus());
try {
r.handleMessage(soapMessage);
fail("Did not throw exception");
} catch (SoapFault f) {
assertEquals(Soap11.getInstance().getSender(), f.getFaultCode());
}
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class ReadHeaderInterceptorTest method prepareSoapMessage.
private void prepareSoapMessage(String message) throws IOException {
soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
ByteArrayDataSource bads = new ByteArrayDataSource(this.getClass().getResourceAsStream(message), "Application/xop+xml");
String cid = AttachmentUtil.createContentID("http://cxf.apache.org");
soapMessage.setContent(Attachment.class, new AttachmentImpl(cid, new DataHandler(bads)));
soapMessage.setContent(InputStream.class, bads.getInputStream());
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class WrappedMessageContextTest method testPutAndGetJaxwsAttachments.
@Test
public void testPutAndGetJaxwsAttachments() throws Exception {
WrappedMessageContext context = new WrappedMessageContext(new HashMap<String, Object>(), null, Scope.APPLICATION);
DataHandler dh1 = new DataHandler(new ByteArrayDataSource("Hello world!".getBytes(), "text/plain"));
DataHandler dh2 = new DataHandler(new ByteArrayDataSource("Hola mundo!".getBytes(), "text/plain"));
DataHandler dh3 = new DataHandler(new ByteArrayDataSource("Bonjour tout le monde!".getBytes(), "text/plain"));
Map<String, DataHandler> jattachments = new HashMap<>();
context.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, jattachments);
jattachments.put("attachment-1", dh1);
Set<Attachment> cattachments = CastUtils.cast((Set<?>) context.get(Message.ATTACHMENTS));
assertNotNull(cattachments);
assertEquals(1, cattachments.size());
jattachments.put("attachment-2", dh2);
assertEquals(2, cattachments.size());
AttachmentImpl ca = new AttachmentImpl("attachment-3", dh3);
ca.setHeader("X-test", "true");
cattachments.add(ca);
assertEquals(3, jattachments.size());
assertEquals(3, cattachments.size());
for (Attachment a : cattachments) {
if ("attachment-1".equals(a.getId())) {
assertEquals("Hello world!", a.getDataHandler().getContent());
} else if ("attachment-2".equals(a.getId())) {
assertEquals("Hola mundo!", a.getDataHandler().getContent());
} else if ("attachment-3".equals(a.getId())) {
assertEquals("Bonjour tout le monde!", a.getDataHandler().getContent());
assertEquals("true", a.getHeader("X-test"));
} else {
fail("unknown attachment");
}
}
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class AttachmentTest method createAttachment.
private Attachment createAttachment(String id) {
MetadataMap<String, String> map = new MetadataMap<String, String>();
map.add("foo", "bar");
return new Attachment(id, new DataHandler(new ByteArrayDataSource(new byte[] { 1 }, "application/octet-stream")), map);
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class MultipartStore method addBookXop.
@POST
@Path("/xop")
@Consumes("multipart/related")
@Produces("multipart/related;type=text/xml")
@Multipart("xop")
public XopType addBookXop(@Multipart XopType type) throws Exception {
if (!"xopName".equals(type.getName())) {
throw new RuntimeException("Wrong name property");
}
String bookXsd = IOUtils.readStringFromStream(type.getAttachinfo().getInputStream());
String bookXsd2 = IOUtils.readStringFromStream(getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/book.xsd"));
if (!bookXsd.equals(bookXsd2)) {
throw new RuntimeException("Wrong attachinfo property");
}
String bookXsdRef = IOUtils.readStringFromStream(type.getAttachInfoRef().getInputStream());
if (!bookXsdRef.equals(bookXsd2)) {
throw new RuntimeException("Wrong attachinforef property");
}
if (!Boolean.getBoolean("java.awt.headless") && type.getImage() == null) {
throw new RuntimeException("Wrong image property");
}
context.put(org.apache.cxf.message.Message.MTOM_ENABLED, "true");
XopType xop = new XopType();
xop.setName("xopName");
InputStream is = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/book.xsd");
byte[] data = IOUtils.readBytesFromStream(is);
xop.setAttachinfo(new DataHandler(new ByteArrayDataSource(data, "application/octet-stream")));
xop.setAttachInfoRef(new DataHandler(new ByteArrayDataSource(data, "application/octet-stream")));
xop.setAttachinfo2(bookXsd.getBytes());
xop.setImage(ImageIO.read(getClass().getResource("/org/apache/cxf/systest/jaxrs/resources/java.jpg")));
return xop;
}
Aggregations