Search in sources :

Example 11 with Route

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

the class RouteBuilderTest method testSimpleRouteWithChoice.

public void testSimpleRouteWithChoice() throws Exception {
    List<Route> routes = buildSimpleRouteWithChoice();
    log.debug("Created routes: " + routes);
    assertEquals("Number routes created", 1, routes.size());
    for (Route route : routes) {
        Endpoint key = route.getEndpoint();
        assertEquals("From endpoint", "direct://a", key.getEndpointUri());
        EventDrivenConsumerRoute consumer = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
        Channel channel = unwrapChannel(consumer.getProcessor());
        ChoiceProcessor choiceProcessor = assertIsInstanceOf(ChoiceProcessor.class, channel.getNextProcessor());
        List<FilterProcessor> filters = choiceProcessor.getFilters();
        assertEquals("Should be two when clauses", 2, filters.size());
        Processor filter1 = filters.get(0);
        assertSendTo(unwrapChannel(((FilterProcessor) filter1).getProcessor()).getNextProcessor(), "direct://b");
        Processor filter2 = filters.get(1);
        assertSendTo(unwrapChannel(((FilterProcessor) filter2).getProcessor()).getNextProcessor(), "direct://c");
        assertSendTo(unwrapChannel(choiceProcessor.getOtherwise()).getNextProcessor(), "direct://d");
    }
}
Also used : DelegateProcessor(org.apache.camel.DelegateProcessor) Processor(org.apache.camel.Processor) MulticastProcessor(org.apache.camel.processor.MulticastProcessor) FilterProcessor(org.apache.camel.processor.FilterProcessor) EvaluateExpressionProcessor(org.apache.camel.processor.EvaluateExpressionProcessor) ThreadsProcessor(org.apache.camel.processor.ThreadsProcessor) SendProcessor(org.apache.camel.processor.SendProcessor) ChoiceProcessor(org.apache.camel.processor.ChoiceProcessor) Endpoint(org.apache.camel.Endpoint) FilterProcessor(org.apache.camel.processor.FilterProcessor) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) ChoiceProcessor(org.apache.camel.processor.ChoiceProcessor)

Example 12 with Route

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

the class ErrorHandlerTest method testConfigureDeadLetterChannel.

public void testConfigureDeadLetterChannel() throws Exception {
    // START SNIPPET: e3
    RouteBuilder builder = new RouteBuilder() {

        public void configure() {
            // using dead letter channel with a seda queue for errors
            errorHandler(deadLetterChannel("seda:errors"));
            // here is our route
            from("seda:a").to("seda:b");
        }
    };
    // END SNIPPET: e3
    List<Route> list = getRouteList(builder);
    assertEquals("Number routes created" + list, 1, list.size());
    for (Route route : list) {
        Endpoint key = route.getEndpoint();
        assertEquals("From endpoint", "seda://a", key.getEndpointUri());
        EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
        Channel channel = unwrapChannel(consumerRoute.getProcessor());
        assertIsInstanceOf(SendProcessor.class, channel.getNextProcessor());
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 13 with Route

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

the class ContextErrorHandlerTest method testGetTheDefaultErrorHandlerFromContext.

public void testGetTheDefaultErrorHandlerFromContext() throws Exception {
    RouteBuilder builder = new RouteBuilder() {

        public void configure() {
            from("seda:a").to("seda:b");
            from("direct:c").to("direct:d");
        }
    };
    List<Route> list = getRouteListWithCurrentContext(builder);
    assertEquals("Number routes created" + list, 2, list.size());
    for (Route route : list) {
        EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
        Processor processor = consumerRoute.getProcessor();
        Channel channel = unwrapChannel(processor);
        DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
        RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
        assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries());
        assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
    }
}
Also used : Processor(org.apache.camel.Processor) SendProcessor(org.apache.camel.processor.SendProcessor) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 14 with Route

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

the class RouteSedaSuspendResumeTest method testSuspendResume.

public void testSuspendResume() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("A");
    template.sendBody("seda:foo", "A");
    assertMockEndpointsSatisfied();
    log.info("Suspending");
    // now suspend and dont expect a message to be routed
    resetMocks();
    mock.expectedMessageCount(0);
    context.suspendRoute("foo");
    assertEquals("Suspended", context.getRouteStatus("foo").name());
    Route route = context.getRoute("foo");
    if (route instanceof StatefulService) {
        assertEquals("Suspended", ((StatefulService) route).getStatus().name());
    }
    // need to give seda consumer thread time to idle
    Thread.sleep(500);
    template.sendBody("seda:foo", "B");
    mock.assertIsSatisfied(1000);
    log.info("Resuming");
    // now resume and expect the previous message to be routed
    resetMocks();
    mock.expectedBodiesReceived("B");
    context.resumeRoute("foo");
    assertMockEndpointsSatisfied();
    assertEquals("Started", context.getRouteStatus("foo").name());
    route = context.getRoute("foo");
    if (route instanceof StatefulService) {
        assertEquals("Started", ((StatefulService) route).getStatus().name());
    }
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Route(org.apache.camel.Route) StatefulService(org.apache.camel.StatefulService)

Example 15 with Route

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

the class LoadRouteFromXmlWithNamespaceTest method testLoadRouteWithNamespaceFromXml.

public void testLoadRouteWithNamespaceFromXml() throws Exception {
    InputStream inputStream = getClass().getResourceAsStream("routeWithNamespace.xml");
    RoutesDefinition routes = context.loadRoutesDefinition(inputStream);
    context.addRouteDefinitions(routes.getRoutes());
    context.start();
    Route routeWithNamespace = context.getRoute("routeWithNamespace");
    assertNotNull("Expected to find route with id: routeWithNamespace", routeWithNamespace);
    MockEndpoint bar = context.getEndpoint("mock:bar", MockEndpoint.class);
    bar.expectedBodiesReceived("Hello from foo");
    // Make sure loaded route can process a XML payload with namespaces attached
    context.createProducerTemplate().sendBody("direct:foo", "<?xml version='1.0'?><foo xmlns='http://foo'><bar>cheese</bar></foo>");
    bar.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) Route(org.apache.camel.Route)

Aggregations

Route (org.apache.camel.Route)90 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)27 Endpoint (org.apache.camel.Endpoint)24 Channel (org.apache.camel.Channel)17 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Processor (org.apache.camel.Processor)13 ArrayList (java.util.ArrayList)12 SendProcessor (org.apache.camel.processor.SendProcessor)11 CamelContext (org.apache.camel.CamelContext)10 ShutdownRoute (org.apache.camel.ShutdownRoute)8 FilterProcessor (org.apache.camel.processor.FilterProcessor)7 RoutePolicy (org.apache.camel.spi.RoutePolicy)6 HashMap (java.util.HashMap)5 Service (org.apache.camel.Service)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 DelegateProcessor (org.apache.camel.DelegateProcessor)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4