Search in sources :

Example 46 with Exchange

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

the class MinaExchangeTimeOutTest method testUsingTimeoutParameter.

@Test
public void testUsingTimeoutParameter() throws Exception {
    // use a timeout value of 2 seconds (timeout is in millis) so we should actually get a response in this test
    Endpoint endpoint = context.getEndpoint("mina:tcp://localhost:{{port}}?textline=true&sync=true&timeout=2000");
    Producer producer = endpoint.createProducer();
    producer.start();
    Exchange exchange = producer.createExchange();
    exchange.getIn().setBody("Hello World");
    try {
        producer.process(exchange);
        fail("Should have thrown an ExchangeTimedOutException wrapped in a RuntimeCamelException");
    } catch (Exception e) {
        assertTrue("Should have thrown an ExchangeTimedOutException", e instanceof ExchangeTimedOutException);
    }
    producer.stop();
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) Test(org.junit.Test)

Example 47 with Exchange

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

the class MinaFiltersTest method testFilter.

private void testFilter(final String uri) throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from(uri).to("mock:result");
        }
    });
    MockEndpoint mock = this.getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    Endpoint endpoint = context.getEndpoint(uri);
    Exchange exchange = endpoint.createExchange();
    Producer producer = endpoint.createProducer();
    producer.start();
    // set input and execute it
    exchange.getIn().setBody("Hello World");
    producer.process(exchange);
    assertMockEndpointsSatisfied();
    assertEquals("The filter should have been called twice (producer and consumer)", 2, TestFilter.called);
    producer.stop();
}
Also used : Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 48 with Exchange

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

the class MinaLoggerOptionTest method testNoLoggerOption.

@Test
public void testNoLoggerOption() throws Exception {
    final String uri = "mina:tcp://localhost:{{port}}?textline=true&sync=false";
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from(uri).to("mock:result");
        }
    });
    MockEndpoint mock = this.getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    Endpoint endpoint = context.getEndpoint(uri);
    Exchange exchange = endpoint.createExchange();
    Producer producer = endpoint.createProducer();
    producer.start();
    // set input and execute it
    exchange.getIn().setBody("Hello World");
    producer.process(exchange);
    Field field = producer.getClass().getDeclaredField("session");
    field.setAccessible(true);
    IoSession session = (IoSession) field.get(producer);
    assertFalse("There should NOT default be a logger filter", session.getFilterChain().contains("logger"));
    producer.stop();
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Field(java.lang.reflect.Field) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) IoSession(org.apache.mina.common.IoSession) Test(org.junit.Test)

Example 49 with Exchange

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

the class MinaLoggerOptionTest method testLoggerOptionFalse.

@Test
public void testLoggerOptionFalse() throws Exception {
    final String uri = "mina:tcp://localhost:{{port}}?textline=true&minaLogger=false&sync=false";
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from(uri).to("mock:result");
        }
    });
    MockEndpoint mock = this.getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    Endpoint endpoint = context.getEndpoint(uri);
    Exchange exchange = endpoint.createExchange();
    Producer producer = endpoint.createProducer();
    producer.start();
    // set input and execute it
    exchange.getIn().setBody("Hello World");
    producer.process(exchange);
    Field field = producer.getClass().getDeclaredField("session");
    field.setAccessible(true);
    IoSession session = (IoSession) field.get(producer);
    assertFalse("There should NOT be a logger filter", session.getFilterChain().contains("logger"));
    producer.stop();
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Field(java.lang.reflect.Field) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) IoSession(org.apache.mina.common.IoSession) Test(org.junit.Test)

Example 50 with Exchange

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

the class Mina2TcpLineDelimiterUsingPlainSocketTest method createRouteBuilder.

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

        public void configure() {
            // use no delay for fast unit testing
            errorHandler(defaultErrorHandler().maximumRedeliveries(2));
            from(String.format("mina2:tcp://localhost:%1$s?textline=true&minaLogger=true&textlineDelimiter=MAC&sync=true", getPort())).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)

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