lburgazzoli commented on a change in pull request #648:
URL: https://github.com/apache/camel-k-runtime/pull/648#discussion_r612475288



##########
File path: 
camel-k-core/support/src/main/java/org/apache/camel/k/support/SourcesSupport.java
##########
@@ -128,21 +130,64 @@ public void afterConfigure(RouteBuilder builder) {
                     }
                 });
                 break;
+            case errorHandler:
+                if (!source.getInterceptors().isEmpty()) {
+                    LOGGER.warn("Interceptors associated to the route template 
{} will be ignored", source.getName());
+                }
+
+                interceptors = List.of(new RouteBuilderLifecycleStrategy() {
+                    @Override
+                    public void afterConfigure(RouteBuilder builder) {
+                        List<RouteDefinition> routes = 
builder.getRouteCollection().getRoutes();
+                        List<RouteTemplateDefinition> templates = 
builder.getRouteTemplateCollection().getRouteTemplates();
+
+                        if (routes.size() > 0) {
+                            throw new IllegalArgumentException("There should 
be no route definition, got " + routes.size());
+                        }
+                        if (!templates.isEmpty()) {
+                            throw new IllegalArgumentException("There should 
not be any template, got " + templates.size());
+                        }
+
+                        if (existErrorHandler(builder)) {
+                            LOGGER.debug("Setting default error handler 
builder factory as {}", builder.getErrorHandlerBuilder());
+                            
runtime.getCamelContext().adapt(ExtendedCamelContext.class).setErrorHandlerFactory(builder.getErrorHandlerBuilder());
+                        }
+                    }
+                });
+                break;
             default:
                 throw new IllegalArgumentException("Unknown source type: " + 
source.getType());
         }
 
         try {
             final Resource resource = 
Sources.asResource(runtime.getCamelContext(), source);
-            final ExtendedCamelContext ecc =  
runtime.getCamelContext(ExtendedCamelContext.class);
+            final ExtendedCamelContext ecc = 
runtime.getCamelContext(ExtendedCamelContext.class);
             final Collection<RoutesBuilder> builders = 
ecc.getRoutesLoader().findRoutesBuilders(resource);
 
             builders.stream()
-                .map(RouteBuilder.class::cast)
-                .peek(b -> interceptors.forEach(b::addLifecycleInterceptor))
-                .forEach(runtime::addRoutes);
+                    .map(RouteBuilder.class::cast)
+                    .peek(b -> 
interceptors.forEach(b::addLifecycleInterceptor))
+                    .forEach(runtime::addRoutes);
         } catch (Exception e) {
             throw RuntimeCamelException.wrapRuntimeCamelException(e);
         }
     }
+
+    static boolean existErrorHandler(RouteBuilder builder) {

Review comment:
       Maybe let use the same name as the method you have introduced to the 
RouteBuilder 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to