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);
}
}
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());
}
}
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());
}
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);
}
}
}
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");
}
}
Aggregations