You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/09/09 18:33:21 UTC

[camel] 01/02: CAMEL-15518: CamelContext configurer should be handled specially and be loadable.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-15518
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 22a5cbb6e9c804840125804b02cd032ef2f1fa8c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Sep 9 19:58:29 2020 +0200

    CAMEL-15518: CamelContext configurer should be handled specially and be loadable.
---
 .../impl/engine/DefaultConfigurerResolver.java     | 10 ++++--
 .../apache/camel/impl/ConfigurerResolverTest.java  | 36 ++++++++++++++++++++++
 .../org/apache/camel/main/BaseMainSupport.java     | 13 --------
 .../camel/support/PropertyConfigurerHelper.java    | 10 ------
 4 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultConfigurerResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultConfigurerResolver.java
index d4a9ebf..bd8bb03 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultConfigurerResolver.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultConfigurerResolver.java
@@ -62,8 +62,14 @@ public class DefaultConfigurerResolver implements ConfigurerResolver {
         try {
             type = findConfigurer(name, context);
             if (type == null) {
-                // not found
-                return null;
+                if (name.endsWith("CamelContext")) {
+                    // fallback special for camel context itself as we have an extended configurer
+                    type = findConfigurer("org.apache.camel.impl.ExtendedCamelContext", context);
+                }
+                if (type == null) {
+                    // not found
+                    return null;
+                }
             }
         } catch (NoFactoryAvailableException e) {
             return null;
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/ConfigurerResolverTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/ConfigurerResolverTest.java
new file mode 100644
index 0000000..dd20ff6
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/ConfigurerResolverTest.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ConfigurerResolverTest extends ContextTestSupport {
+
+    @Test
+    public void testConfigurerResolver() throws Exception {
+        GeneratedPropertyConfigurer resolver = context.adapt(ExtendedCamelContext.class).getConfigurerResolver()
+                .resolvePropertyConfigurer(context.getClass().getName(), context);
+        Assertions.assertNotNull(resolver);
+
+        resolver.configure(context, context, "name", "foobar", true);
+        Assertions.assertEquals("foobar", context.getName());
+    }
+}
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 04625ef..3c0fea9 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -130,10 +130,6 @@ public abstract class BaseMainSupport extends BaseService {
         }
         if (targetConfigurer == null) {
             String name = target.getClass().getName();
-            if (target instanceof ExtendedCamelContext) {
-                // special for camel context itself as we have an extended configurer
-                name = ExtendedCamelContext.class.getName();
-            }
             // see if there is a configurer for it
             targetConfigurer = context.adapt(ExtendedCamelContext.class)
                     .getConfigurerResolver().resolvePropertyConfigurer(name, context);
@@ -147,10 +143,6 @@ public abstract class BaseMainSupport extends BaseService {
         }
         if (sourceConfigurer == null) {
             String name = source.getClass().getName();
-            if (source instanceof ExtendedCamelContext) {
-                // special for camel context itself as we have an extended configurer
-                name = ExtendedCamelContext.class.getName();
-            }
             // see if there is a configurer for it
             sourceConfigurer = context.adapt(ExtendedCamelContext.class)
                     .getConfigurerResolver().resolvePropertyConfigurer(name, context);
@@ -187,11 +179,6 @@ public abstract class BaseMainSupport extends BaseService {
 
         if (configurer == null) {
             String name = target.getClass().getName();
-            if (target instanceof ExtendedCamelContext) {
-                // special for camel context itself as we have an extended configurer
-                name = ExtendedCamelContext.class.getName();
-            }
-
             // see if there is a configurer for it
             configurer = context.adapt(ExtendedCamelContext.class)
                     .getConfigurerResolver().resolvePropertyConfigurer(name, context);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
index b04397c..f1b5959 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
@@ -55,11 +55,6 @@ public final class PropertyConfigurerHelper {
 
         if (configurer == null) {
             String name = target.getClass().getName();
-            if (target instanceof ExtendedCamelContext) {
-                // special for camel context itself as we have an extended configurer
-                name = ExtendedCamelContext.class.getName();
-            }
-
             // see if there is a configurer for it
             configurer = context.adapt(ExtendedCamelContext.class)
                     .getConfigurerResolver()
@@ -81,11 +76,6 @@ public final class PropertyConfigurerHelper {
         ObjectHelper.notNull(context, "context");
 
         String name = targetType.getName();
-        if (ExtendedCamelContext.class.isAssignableFrom(targetType)) {
-            // special for camel context itself as we have an extended configurer
-            name = ExtendedCamelContext.class.getName();
-        }
-
         // see if there is a configurer for it
         return context.adapt(ExtendedCamelContext.class)
                 .getConfigurerResolver()