Search in sources :

Example 11 with DefaultAttachment

use of org.apache.camel.impl.DefaultAttachment in project camel by apache.

the class MimeMultipartDataFormatTest method addAttachment.

private void addAttachment(String attContentType, String attText, String attFileName, Map<String, String> headers) throws IOException {
    DataSource ds = new ByteArrayDataSource(attText, attContentType);
    DefaultAttachment attachment = new DefaultAttachment(ds);
    if (headers != null) {
        for (String headerName : headers.keySet()) {
            attachment.addHeader(headerName, headers.get(headerName));
        }
    }
    in.addAttachmentObject(attFileName, attachment);
}
Also used : DefaultAttachment(org.apache.camel.impl.DefaultAttachment) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource)

Example 12 with DefaultAttachment

use of org.apache.camel.impl.DefaultAttachment in project camel by apache.

the class DefaultCxfBinding method createCamelAttachment.

private DefaultAttachment createCamelAttachment(Attachment attachment) {
    DefaultAttachment camelAttachment = new DefaultAttachment(attachment.getDataHandler());
    Iterator<String> headers = attachment.getHeaderNames();
    while (headers.hasNext()) {
        String name = headers.next();
        camelAttachment.addHeader(name, attachment.getHeader(name));
    }
    return camelAttachment;
}
Also used : DefaultAttachment(org.apache.camel.impl.DefaultAttachment)

Example 13 with DefaultAttachment

use of org.apache.camel.impl.DefaultAttachment in project camel by apache.

the class BeanWithAttachmentAnnotationTest method testBeanWithAnnotationAndExchangeTest.

public void testBeanWithAnnotationAndExchangeTest() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("attachment");
    template.send("direct:in", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.setPattern(ExchangePattern.InOut);
            Message m = exchange.getIn();
            m.addAttachmentObject("attachment", new DefaultAttachment(new FileDataSource("src/test/org/apache/camel/component/bean/BeanWithAttachmentAnnotationTest.java")));
        }
    });
    mock.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) FileDataSource(javax.activation.FileDataSource) DefaultAttachment(org.apache.camel.impl.DefaultAttachment)

Aggregations

DefaultAttachment (org.apache.camel.impl.DefaultAttachment)13 Message (org.apache.camel.Message)7 FileDataSource (javax.activation.FileDataSource)5 Exchange (org.apache.camel.Exchange)5 DataHandler (javax.activation.DataHandler)4 Attachment (org.apache.camel.Attachment)4 Processor (org.apache.camel.Processor)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 DataSource (javax.activation.DataSource)3 IOException (java.io.IOException)2 BodyPart (javax.mail.BodyPart)2 Header (javax.mail.Header)2 MimeBodyPart (javax.mail.internet.MimeBodyPart)2 Part (javax.servlet.http.Part)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2 FormData (io.undertow.server.handlers.form.FormData)1 HttpString (io.undertow.util.HttpString)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 URL (java.net.URL)1