This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch var in repository https://gitbox.apache.org/repos/asf/camel.git
commit cee13b54b0a7e71dc74d21a9305c58c4fc6da954 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Dec 29 18:59:28 2023 +0100 CAMEL-19749: Add variables as concept to Camel --- .../main/java/org/apache/camel/spi/VariableRepositoryFactory.java | 5 +++++ .../apache/camel/impl/engine/DefaultVariableRepositoryFactory.java | 2 +- .../java/org/apache/camel/processor/CustomGlobalVariableTest.java | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/VariableRepositoryFactory.java b/core/camel-api/src/main/java/org/apache/camel/spi/VariableRepositoryFactory.java index ba7aefeb473..6928e343f84 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/VariableRepositoryFactory.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/VariableRepositoryFactory.java @@ -21,6 +21,11 @@ package org.apache.camel.spi; */ public interface VariableRepositoryFactory { + /** + * ID for custom global {@link VariableRepository}. + */ + String GLOBAL_VARIABLE_FACTORY_ID = "global-variable-repository"; + /** * Gets the {@link VariableRepository} for the given id * diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultVariableRepositoryFactory.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultVariableRepositoryFactory.java index 524192b909f..5161c43976e 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultVariableRepositoryFactory.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultVariableRepositoryFactory.java @@ -59,7 +59,7 @@ public class DefaultVariableRepositoryFactory extends ServiceSupport implements protected void doStart() throws Exception { super.doStart(); - VariableRepository repo = CamelContextHelper.findSingleByType(camelContext, VariableRepository.class); + VariableRepository repo = CamelContextHelper.lookup(camelContext, GLOBAL_VARIABLE_FACTORY_ID, VariableRepository.class); if (repo != null) { LOG.info("Using VariableRepository: {} as global repository", repo.getId()); global = repo; diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/CustomGlobalVariableTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/CustomGlobalVariableTest.java index 82192e1efbf..ad5b4a0a8d4 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/CustomGlobalVariableTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/CustomGlobalVariableTest.java @@ -28,6 +28,7 @@ import org.apache.camel.support.service.ServiceSupport; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.camel.spi.VariableRepositoryFactory.GLOBAL_VARIABLE_FACTORY_ID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -39,7 +40,7 @@ public class CustomGlobalVariableTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - context.getRegistry().bind("myGlobal", new MyGlobalRepo()); + context.getRegistry().bind(GLOBAL_VARIABLE_FACTORY_ID, new MyGlobalRepo()); return context; }