Search in sources :

Example 1 with Channel

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

the class RouteService method doGetRouteScopedErrorHandler.

/**
     * Gather the route scoped error handler from the given route
     */
private void doGetRouteScopedErrorHandler(Set<Service> services, Route route) {
    // only include error handlers if they are route scoped
    boolean includeErrorHandler = !routeDefinition.isContextScopedErrorHandler(route.getRouteContext().getCamelContext());
    List<Service> extra = new ArrayList<Service>();
    if (includeErrorHandler) {
        for (Service service : services) {
            if (service instanceof Channel) {
                Processor eh = ((Channel) service).getErrorHandler();
                if (eh != null && eh instanceof Service) {
                    extra.add((Service) eh);
                }
            }
        }
    }
    if (!extra.isEmpty()) {
        services.addAll(extra);
    }
}
Also used : Processor(org.apache.camel.Processor) Channel(org.apache.camel.Channel) ArrayList(java.util.ArrayList) Service(org.apache.camel.Service)

Example 2 with Channel

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

the class DefaultErrorHandlerTest method testRoute.

public void testRoute() {
    Route route = context.getRoutes().get(0);
    EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
    Processor processor = unwrap(consumerRoute.getProcessor());
    Pipeline pipeline = assertIsInstanceOf(Pipeline.class, processor);
    // there should be a default error handler in front of each processor in this pipeline
    for (Processor child : pipeline.getProcessors()) {
        Channel channel = assertIsInstanceOf(Channel.class, child);
        assertNotNull("There should be an error handler", channel.getErrorHandler());
        assertIsInstanceOf(DefaultErrorHandler.class, channel.getErrorHandler());
    }
}
Also used : Processor(org.apache.camel.Processor) Channel(org.apache.camel.Channel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 3 with Channel

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

the class StreamResequencerTest method doTestStreamResequencerType.

protected void doTestStreamResequencerType() throws Exception {
    List<Route> list = getRouteList(createRouteBuilder());
    assertEquals("Number of routes created: " + list, 1, list.size());
    Route route = list.get(0);
    EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
    Channel channel = unwrapChannel(consumerRoute.getProcessor());
    assertIsInstanceOf(DefaultErrorHandler.class, channel.getErrorHandler());
    assertIsInstanceOf(StreamResequencer.class, channel.getNextProcessor());
}
Also used : Channel(org.apache.camel.Channel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 4 with Channel

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

the class ProcessorDefinition method addRoutes.

public void addRoutes(RouteContext routeContext, Collection<Route> routes) throws Exception {
    Processor processor = makeProcessor(routeContext);
    if (processor == null) {
        // no processor to add
        return;
    }
    if (!routeContext.isRouteAdded()) {
        boolean endpointInterceptor = false;
        // processor as we use the producer to trigger the interceptor
        if (processor instanceof Channel) {
            Channel channel = (Channel) processor;
            Processor next = channel.getNextProcessor();
            if (next instanceof InterceptEndpointProcessor) {
                endpointInterceptor = true;
            }
        }
        // only add regular processors as event driven
        if (endpointInterceptor) {
            log.debug("Endpoint interceptor should not be added as an event driven consumer route: {}", processor);
        } else {
            log.trace("Adding event driven processor: {}", processor);
            routeContext.addEventDrivenProcessor(processor);
        }
    }
}
Also used : InterceptEndpointProcessor(org.apache.camel.processor.InterceptEndpointProcessor) Processor(org.apache.camel.Processor) Channel(org.apache.camel.Channel) DefaultChannel(org.apache.camel.processor.interceptor.DefaultChannel) InterceptEndpointProcessor(org.apache.camel.processor.InterceptEndpointProcessor)

Example 5 with Channel

use of org.apache.camel.Channel 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)

Aggregations

Channel (org.apache.camel.Channel)21 Route (org.apache.camel.Route)17 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)17 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Endpoint (org.apache.camel.Endpoint)13 Processor (org.apache.camel.Processor)12 SendProcessor (org.apache.camel.processor.SendProcessor)10 FilterProcessor (org.apache.camel.processor.FilterProcessor)6 ArrayList (java.util.ArrayList)3 DelegateProcessor (org.apache.camel.DelegateProcessor)3 ChoiceProcessor (org.apache.camel.processor.ChoiceProcessor)3 EvaluateExpressionProcessor (org.apache.camel.processor.EvaluateExpressionProcessor)3 MulticastProcessor (org.apache.camel.processor.MulticastProcessor)3 RedeliveryPolicy (org.apache.camel.processor.RedeliveryPolicy)3 ThreadsProcessor (org.apache.camel.processor.ThreadsProcessor)3 Pipeline (org.apache.camel.processor.Pipeline)2 Consumer (org.apache.camel.Consumer)1 NonManagedService (org.apache.camel.NonManagedService)1 Producer (org.apache.camel.Producer)1 Service (org.apache.camel.Service)1