Search in sources :

Example 36 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class MimeMultipartDataFormatTest method roundtripWithoutAttachments.

@Test
public void roundtripWithoutAttachments() throws IOException {
    in.setBody("Body text");
    Exchange result = template.send("direct:roundtrip", exchange);
    Message out = result.getOut();
    assertEquals("Body text", out.getBody(String.class));
    assertFalse(out.hasAttachments());
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.camel.Message) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 37 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class MimeMultipartDataFormatTest method roundtripWithTextAttachmentsAndSpecialCharacters.

@Test
@Ignore("Fails on CI servers and some platforms - maybe due locale or something")
public void roundtripWithTextAttachmentsAndSpecialCharacters() throws IOException {
    String attContentType = "text/plain";
    String attText = "Attachment Text with special characters: ©";
    String attFileName = "Attachment File Name with special characters: ©";
    in.setBody("Body text with special characters: ©");
    in.setHeader(Exchange.CONTENT_TYPE, "text/plain");
    in.setHeader(Exchange.CONTENT_ENCODING, "UTF8");
    addAttachment(attContentType, attText, attFileName);
    Exchange result = template.send("direct:roundtrip", exchange);
    Message out = result.getOut();
    assertEquals("Body text with special characters: ©", out.getBody(String.class));
    assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
    assertEquals("UTF8", out.getHeader(Exchange.CONTENT_ENCODING));
    assertTrue(out.hasAttachments());
    assertEquals(1, out.getAttachmentNames().size());
    assertThat(out.getAttachmentNames(), hasItem(attFileName));
    DataHandler dh = out.getAttachment(attFileName);
    assertNotNull(dh);
    assertEquals(attContentType, dh.getContentType());
    InputStream is = dh.getInputStream();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    IOHelper.copyAndCloseInput(is, os);
    assertEquals(attText, new String(os.toByteArray()));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.camel.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StringContains.containsString(org.hamcrest.core.StringContains.containsString) DataHandler(javax.activation.DataHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 38 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class MimeMultipartDataFormatTest method roundtripWithTextAttachmentsAndBinaryContent.

@Test
public void roundtripWithTextAttachmentsAndBinaryContent() throws IOException {
    String attContentType = "text/plain";
    String attText = "Attachment Text";
    String attFileName = "Attachment File Name";
    in.setBody("Body text");
    in.setHeader(Exchange.CONTENT_TYPE, "text/plain;charset=iso8859-1;other-parameter=true");
    addAttachment(attContentType, attText, attFileName);
    Exchange result = template.send("direct:roundtripbinarycontent", exchange);
    Message out = result.getOut();
    assertEquals("Body text", out.getBody(String.class));
    assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
    assertEquals("iso8859-1", out.getHeader(Exchange.CONTENT_ENCODING));
    assertTrue(out.hasAttachments());
    assertEquals(1, out.getAttachmentNames().size());
    assertThat(out.getAttachmentNames(), hasItem(attFileName));
    DataHandler dh = out.getAttachment(attFileName);
    assertNotNull(dh);
    assertEquals(attContentType, dh.getContentType());
    InputStream is = dh.getInputStream();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    IOHelper.copyAndCloseInput(is, os);
    assertEquals(attText, new String(os.toByteArray()));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.camel.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StringContains.containsString(org.hamcrest.core.StringContains.containsString) DataHandler(javax.activation.DataHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 39 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class MimeMultipartDataFormatTest method unmarshalInlineHeadersNonMimeBody.

@Test
public void unmarshalInlineHeadersNonMimeBody() {
    in.setBody("This is not a MIME-Multipart");
    Exchange out = template.send("direct:unmarshalonlyinlineheaders", exchange);
    assertNotNull(out.getOut());
    String bodyStr = out.getOut().getBody(String.class);
    assertEquals("This is not a MIME-Multipart", bodyStr);
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 40 with Exchange

use of org.apache.camel.Exchange in project camel by apache.

the class MimeMultipartDataFormatTest method roundtripWithTextAttachmentsHeadersInline.

@Test
public void roundtripWithTextAttachmentsHeadersInline() throws IOException {
    String attContentType = "text/plain";
    String attText = "Attachment Text";
    String attFileName = "Attachment File Name";
    in.setBody("Body text");
    in.setHeader(Exchange.CONTENT_TYPE, "text/plain;charset=iso8859-1;other-parameter=true");
    in.setHeader(Exchange.CONTENT_ENCODING, "UTF8");
    addAttachment(attContentType, attText, attFileName);
    Exchange result = template.send("direct:roundtripinlineheaders", exchange);
    Message out = result.getOut();
    assertEquals("Body text", out.getBody(String.class));
    assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
    assertEquals("UTF8", out.getHeader(Exchange.CONTENT_ENCODING));
    assertTrue(out.hasAttachments());
    assertEquals(1, out.getAttachmentNames().size());
    assertThat(out.getAttachmentNames(), hasItem(attFileName));
    DataHandler dh = out.getAttachment(attFileName);
    assertNotNull(dh);
    assertEquals(attContentType, dh.getContentType());
    InputStream is = dh.getInputStream();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    IOHelper.copyAndCloseInput(is, os);
    assertEquals(attText, new String(os.toByteArray()));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.camel.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StringContains.containsString(org.hamcrest.core.StringContains.containsString) DataHandler(javax.activation.DataHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)3446 Test (org.junit.Test)1735 Processor (org.apache.camel.Processor)1405 RouteBuilder (org.apache.camel.builder.RouteBuilder)666 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)640 DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Message (org.apache.camel.Message)379 Endpoint (org.apache.camel.Endpoint)235 HashMap (java.util.HashMap)190 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)155 Producer (org.apache.camel.Producer)150 File (java.io.File)120 ArrayList (java.util.ArrayList)117 CamelContext (org.apache.camel.CamelContext)117 List (java.util.List)99 Map (java.util.Map)96 ProducerTemplate (org.apache.camel.ProducerTemplate)94 IOException (java.io.IOException)92 Tx (org.nhindirect.common.tx.model.Tx)83 Predicate (org.apache.camel.Predicate)78