Search in sources :

Example 41 with Exchange

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

the class MailMessageTest method testMailMessageHandlesSingleHeader.

@Test
public void testMailMessageHandlesSingleHeader() throws Exception {
    mimeMessage.setRecipients(Message.RecipientType.TO, new Address[] { new InternetAddress("frank@localhost") });
    Exchange exchange = endpoint.createExchange(mimeMessage);
    MailMessage in = (MailMessage) exchange.getIn();
    assertNotNull(in);
    Object header = in.getHeader("TO");
    String value = assertIsInstanceOf(String.class, header);
    assertEquals("value", "frank@localhost", value);
    assertEquals("body", body, in.getBody());
}
Also used : Exchange(org.apache.camel.Exchange) InternetAddress(javax.mail.internet.InternetAddress) Test(org.junit.Test)

Example 42 with Exchange

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

the class MinaEndpoint method createExchange.

public Exchange createExchange(IoSession session, Object payload) {
    Exchange exchange = createExchange();
    exchange.getIn().setHeader(MinaConstants.MINA_IOSESSION, session);
    exchange.getIn().setHeader(MinaConstants.MINA_LOCAL_ADDRESS, session.getLocalAddress());
    exchange.getIn().setHeader(MinaConstants.MINA_REMOTE_ADDRESS, session.getRemoteAddress());
    MinaPayloadHelper.setIn(exchange, payload);
    return exchange;
}
Also used : Exchange(org.apache.camel.Exchange)

Example 43 with Exchange

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

the class MinaTcpLineDelimiterUsingPlainSocketTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            // use no delay for fast unit testing
            errorHandler(defaultErrorHandler().maximumRedeliveries(2));
            from("mina:tcp://localhost:{{port}}?textline=true&textlineDelimiter=MAC&sync=true").process(new Processor() {

                public void process(Exchange e) {
                    String in = e.getIn().getBody(String.class);
                    if ("force-null-out-body".equals(in)) {
                        // forcing a null out body
                        e.getOut().setBody(null);
                    } else if ("force-exception".equals(in)) {
                        // clear out before throwing exception
                        e.getOut().setBody(null);
                        throw new IllegalArgumentException("Forced exception");
                    } else {
                        e.getOut().setBody("Hello " + in);
                    }
                }
            });
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 44 with Exchange

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

the class MinaConverterTest method testToStringTwoTimes.

public void testToStringTwoTimes() throws UnsupportedEncodingException {
    String in = "Hello World 你好";
    ByteBuffer bb = ByteBuffer.wrap(in.getBytes("UTF-8"));
    Exchange exchange = new DefaultExchange(new DefaultCamelContext());
    exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
    String out = MinaConverter.toString(bb, exchange);
    assertEquals("Hello World 你好", out);
    // should be possible to convert to string without affecting the ByteBuffer
    out = MinaConverter.toString(bb, exchange);
    assertEquals("Hello World 你好", out);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) ByteBuffer(org.apache.mina.common.ByteBuffer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 45 with Exchange

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

the class MinaEncodingTest method testUDPEncodeUTF8InputIsStringNoMock.

@Test
public void testUDPEncodeUTF8InputIsStringNoMock() throws Exception {
    // this unit test covers for testUDPEncodeUTF8InputIsString until the encoding is fixed
    // include a UTF-8 char in the text จ is a Thai elephant
    final String hello = "Hello Thai Elephant จ";
    final String bye = "Hello Thai Elephant จ";
    final String uri = "mina:udp://localhost:{{port}}?sync=true&encoding=UTF-8";
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from(uri).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    String s = exchange.getIn().getBody(String.class);
                    assertEquals(hello, s);
                    exchange.getOut().setBody(bye);
                }
            });
        }
    });
    Endpoint endpoint = context.getEndpoint(uri);
    Producer producer = endpoint.createProducer();
    Exchange exchange = producer.createExchange();
    exchange.getIn().setBody(hello);
    producer.start();
    producer.process(exchange);
    producer.stop();
    String s = exchange.getOut().getBody(String.class);
    assertEquals(bye, s);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) 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