Search in sources :

Example 96 with Processor

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

the class SetHeaderInDoCatchIssueTest method createRegistry.

protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = new JndiRegistry(createJndiContext());
    registry.bind("A", new Processor() {

        public void process(Exchange exchange) throws Exception {
            log.info("A headers " + exchange.getIn().getHeaders());
        }
    });
    registry.bind("B", new Processor() {

        public void process(Exchange exchange) throws Exception {
            log.info("B headers " + exchange.getIn().getHeaders());
            if ("ExchangeTimedOutException".equals(exchange.getIn().getBody(String.class))) {
                throw new ExchangeTimedOutException(exchange, 1);
            } else if ("Exception".equals(exchange.getIn().getBody(String.class))) {
                throw new Exception();
            }
        }
    });
    registry.bind("C", new Processor() {

        public void process(Exchange exchange) throws Exception {
            log.info("C headers " + exchange.getIn().getHeaders());
        }
    });
    return registry;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException)

Example 97 with Processor

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

the class SetHeaderInDoCatchIssueTest method testExchangeTimedOutException.

public void testExchangeTimedOutException() {
    Exchange exchange = template.request("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("ExchangeTimedOutException");
        }
    });
    assertEquals("TimeOut", exchange.getOut().getHeader("Status"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ExchangeTimedOutException(org.apache.camel.ExchangeTimedOutException)

Example 98 with Processor

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

the class SplitStopOnExceptionIssueTest method testSplit.

public void testSplit() throws Exception {
    getMockEndpoint("mock:line").expectedBodiesReceived("Hello", "World", "Kaboom");
    getMockEndpoint("mock:line").allMessages().exchangeProperty("foo").isEqualTo("changed");
    getMockEndpoint("mock:result").expectedMessageCount(0);
    Exchange out = template.request("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("Hello,World,Kaboom");
        }
    });
    assertNotNull(out);
    assertTrue(out.isFailed());
    assertFalse(out.hasOut());
    // when we use stopOnException the exchange should not be affected during the splitter
    // eg the foo property should have the before value
    assertEquals("before", out.getProperty("foo"));
    assertEquals("Hello,World,Kaboom", out.getIn().getBody());
    IllegalArgumentException iae = out.getException(IllegalArgumentException.class);
    assertNotNull(iae);
    assertEquals("Forced exception", iae.getMessage());
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor)

Example 99 with Processor

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

the class MulticastWithOnExceptionIssueTest method testEnd1FailureTest.

public void testEnd1FailureTest() throws Exception {
    MockEndpoint end1 = getMockEndpoint("mock:end1");
    end1.whenAnyExchangeReceived(new Processor() {

        public void process(Exchange exchange) throws Exception {
            throw new RuntimeException("Simulated Exception");
        }
    });
    getMockEndpoint("mock:end2").expectedMessageCount(1);
    getMockEndpoint("mock:end3").expectedMessageCount(0);
    getMockEndpoint("mock:end4").expectedMessageCount(1);
    String result = template.requestBody("direct:start", "Hello World!", String.class);
    assertEquals("Stop!", result);
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 100 with Processor

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

the class OnExceptionContinuedIssueTest method testOnExceptionWrappedMatch.

@Test
public void testOnExceptionWrappedMatch() throws Exception {
    final DefaultErrorHandlerBuilder defaultErrorHandlerBuilder = new DeadLetterChannelBuilder("direct:dead");
    // run fast
    defaultErrorHandlerBuilder.redeliveryDelay(0);
    defaultErrorHandlerBuilder.maximumRedeliveries(2);
    context.setErrorHandlerBuilder(defaultErrorHandlerBuilder);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            context.setTracing(false);
            onException(OrderFailedException.class).maximumRedeliveries(0).continued(true);
            from("direct:dead").to("log:dead", "mock:dead");
            from("direct:order").to("mock:one").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    log.info("First Processor Invoked");
                    throw new OrderFailedException("First Processor Failure");
                }
            }).to("mock:two").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    log.info("Second Processor Invoked");
                }
            }).to("mock:three").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    log.info("Third Processor Invoked");
                    throw new RuntimeException("Some Runtime Exception");
                }
            }).to("mock:four").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    log.info("Fourth Processor Invoked");
                }
            });
        }
    });
    context.start();
    // we should only get 1 to the DLC when we hit the 3rd route that
    // throws the runtime exception
    getMockEndpoint("mock:dead").expectedMessageCount(1);
    getMockEndpoint("mock:one").expectedMessageCount(1);
    getMockEndpoint("mock:two").expectedMessageCount(1);
    getMockEndpoint("mock:three").expectedMessageCount(1);
    getMockEndpoint("mock:four").expectedMessageCount(0);
    template.requestBody("direct:order", "Camel in Action");
    assertMockEndpointsSatisfied();
}
Also used : DefaultErrorHandlerBuilder(org.apache.camel.builder.DefaultErrorHandlerBuilder) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) DeadLetterChannelBuilder(org.apache.camel.builder.DeadLetterChannelBuilder) Test(org.junit.Test)

Aggregations

Processor (org.apache.camel.Processor)1467 Exchange (org.apache.camel.Exchange)1368 Test (org.junit.Test)634 RouteBuilder (org.apache.camel.builder.RouteBuilder)543 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)164 Message (org.apache.camel.Message)119 ArrayList (java.util.ArrayList)65 HashMap (java.util.HashMap)64 IOException (java.io.IOException)55 CamelExecutionException (org.apache.camel.CamelExecutionException)52 Endpoint (org.apache.camel.Endpoint)46 Map (java.util.Map)45 File (java.io.File)38 List (java.util.List)34 Producer (org.apache.camel.Producer)33 DefaultExchange (org.apache.camel.impl.DefaultExchange)29 SendProcessor (org.apache.camel.processor.SendProcessor)26 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)26 CountDownLatch (java.util.concurrent.CountDownLatch)24 Expression (org.apache.camel.Expression)24