Search in sources :

Example 86 with ByteArrayDataSource

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());
}
Also used : ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

Example 87 with ByteArrayDataSource

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;
}
Also used : ArrayList(java.util.ArrayList) AttachmentImpl(org.apache.cxf.attachment.AttachmentImpl) Attachment(org.apache.cxf.message.Attachment) DataHandler(javax.activation.DataHandler) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

Example 88 with ByteArrayDataSource

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());
    }
}
Also used : ReadHeadersInterceptor(org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor) InputStream(java.io.InputStream) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Example 89 with ByteArrayDataSource

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();
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) MimeMessage(javax.mail.internet.MimeMessage) Properties(java.util.Properties) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource) Session(javax.mail.Session)

Example 90 with ByteArrayDataSource

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();
    }
}
Also used : InputStream(java.io.InputStream) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

Aggregations

ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)119 DataHandler (javax.activation.DataHandler)82 MimeMultipart (javax.mail.internet.MimeMultipart)39 InputStream (java.io.InputStream)38 IOException (java.io.IOException)35 MimeBodyPart (javax.mail.internet.MimeBodyPart)35 DataSource (javax.activation.DataSource)32 MimeMessage (javax.mail.internet.MimeMessage)31 ByteArrayOutputStream (java.io.ByteArrayOutputStream)25 Test (org.junit.Test)25 MessagingException (javax.mail.MessagingException)21 ByteArrayInputStream (java.io.ByteArrayInputStream)17 ArrayList (java.util.ArrayList)17 InternetAddress (javax.mail.internet.InternetAddress)16 Session (javax.mail.Session)14 Properties (java.util.Properties)12 Date (java.util.Date)11 List (java.util.List)8 Multipart (javax.mail.Multipart)8 Holder (javax.xml.ws.Holder)8