You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/04/13 12:57:02 UTC

[GitHub] [camel-k-runtime] squakez commented on a change in pull request #648: feat(core): default error handler

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



##########
File path: camel-k-core/support/src/main/java/org/apache/camel/k/listener/SourcesConfigurer.java
##########
@@ -64,14 +68,47 @@ protected void accept(Runtime runtime) {
         // property that can't be bound to this configurer.
         //
         PropertiesSupport.bindProperties(
-            runtime.getCamelContext(),
-            this,
-            k -> k.startsWith(CAMEL_K_SOURCES_PREFIX),
-            CAMEL_K_PREFIX);
+                runtime.getCamelContext(),
+                this,
+                k -> k.startsWith(CAMEL_K_SOURCES_PREFIX),
+                CAMEL_K_PREFIX);
+
+        checkUniqueErrorHandler();
+        sortSources();
 
         if (ObjectHelper.isNotEmpty(this.getSources())) {
             SourcesSupport.loadSources(runtime, this.getSources());
         }
     }
 
+    private void checkUniqueErrorHandler() {
+        checkUniqueErrorHandler(this.sources);
+    }
+
+    static void checkUniqueErrorHandler(SourceDefinition[] sources) {
+        long errorHandlers = sources == null ? 0 : Arrays.stream(sources).filter(s -> s.getType() == SourceType.errorHandler).count();
+        if (errorHandlers > 1) {
+            throw new IllegalArgumentException("Expected only one error handler source type, got " + errorHandlers);
+        }
+    }
+
+    private void sortSources() {
+        sortSources(this.getSources());
+    }
+
+    static void sortSources(SourceDefinition[] sources) {
+        if (sources == null) {
+            return;
+        }
+        // We must ensure the following source type order: errorHandler, source, template

Review comment:
       Fixed, thanks!




-- 
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:
users@infra.apache.org