use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class SAAJInInterceptorTest method prepareSoapMessage.
private void prepareSoapMessage(String message) throws IOException {
soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
ByteArrayDataSource bads = new ByteArrayDataSource(this.getClass().getResourceAsStream(message), "text/xml");
soapMessage.setContent(InputStream.class, bads.getInputStream());
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class TestUtil method createSoapMessage.
public static SoapMessage createSoapMessage(SoapVersion soapVersion, InterceptorChain chain, Class<?> clazz) throws IOException {
SoapMessage soapMessage = createEmptySoapMessage(soapVersion, chain);
// setup the message result with attachment.class
ByteArrayDataSource bads = new ByteArrayDataSource(clazz.getResourceAsStream("primarySoapPart.xml"), "Application/xop+xml");
String cid = AttachmentUtil.createContentID("http://cxf.apache.org");
soapMessage.setContent(Attachment.class, new AttachmentImpl(cid, new DataHandler(bads)));
// setup the message attachments
Collection<Attachment> attachments = new ArrayList<>();
soapMessage.setAttachments(attachments);
// String cidAtt1 = "cid:http://cxf.apache.org/me.bmp";
// bads = new ByteArrayDataSource(clazz.getResourceAsStream("me.bmp"), "image/bmp");
// AttachmentImpl att1 = new AttachmentImpl(cidAtt1, new DataHandler(bads));
// att1.setXOP(true);
// attachments.add(att1);
String cidAtt2 = "cid:http://cxf.apache.org/my.wav";
bads = new ByteArrayDataSource(clazz.getResourceAsStream("my.wav"), "Application/octet-stream");
AttachmentImpl att2 = new AttachmentImpl(cidAtt2, new DataHandler(bads));
att2.setXOP(true);
attachments.add(att2);
return soapMessage;
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class ReadHeaderInterceptorTest method testBadSOAPEnvelopeNamespace.
@Test
public void testBadSOAPEnvelopeNamespace() throws Exception {
soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
InputStream in = getClass().getResourceAsStream("test-bad-env.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().getVersionMismatch(), f.getFaultCode());
}
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class DataSourceProviderTest method readAttachmentParts.
public static MimeMultipart readAttachmentParts(String contentType, InputStream bais) throws MessagingException, IOException {
DataSource source = new ByteArrayDataSource(bais, contentType);
MimeMultipart mpart = new MimeMultipart(source);
Session session = Session.getDefaultInstance(new Properties());
MimeMessage mm = new MimeMessage(session);
mm.setContent(mpart);
mm.addHeaderLine("Content-Type:" + contentType);
return (MimeMultipart) mm.getContent();
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class SwAServiceImpl method echoDataRef.
public void echoDataRef(Holder<DataStruct> data) {
try {
InputStream bis = null;
bis = data.value.getDataRef().getDataSource().getInputStream();
byte[] b = new byte[6];
bis.read(b, 0, 6);
String string = IOUtils.newStringFromBytes(b);
ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream");
data.value.setDataRef(new DataHandler(source));
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations