Repository: camel Updated Branches: refs/heads/camel-2.16.x b1404582b -> decca4ce5 refs/heads/master ce1973f61 -> 5feae578f
CAMEL-9326: JndiRegistry should default to use CamelInitialContextFactory if no env factory specified Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/02b562aa Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/02b562aa Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/02b562aa Branch: refs/heads/master Commit: 02b562aa858d1a4ff5aaec099306adc2777651d2 Parents: ce1973f Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Nov 15 09:06:26 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Nov 15 09:06:26 2015 +0100 ---------------------------------------------------------------------- .../java/org/apache/camel/impl/JndiRegistry.java | 14 +++++++++++++- .../org/apache/camel/impl/JndiRegistryTest.java | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/02b562aa/camel-core/src/main/java/org/apache/camel/impl/JndiRegistry.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/JndiRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/JndiRegistry.java index 8a077b3..21fc178 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/JndiRegistry.java +++ b/camel-core/src/main/java/org/apache/camel/impl/JndiRegistry.java @@ -37,10 +37,15 @@ import org.apache.camel.spi.Registry; */ public class JndiRegistry implements Registry { private Context context; + private Map environment; public JndiRegistry() { } + public JndiRegistry(Map environment) { + this.environment = environment; + } + public JndiRegistry(Context context) { this.context = context; } @@ -145,7 +150,14 @@ public class JndiRegistry implements Registry { } protected Context createContext() throws NamingException { - Hashtable<?, ?> properties = new Hashtable<Object, Object>(System.getProperties()); + Hashtable<Object, Object> properties = new Hashtable<Object, Object>(System.getProperties()); + if (environment != null) { + properties.putAll(environment); + } + // must include a factory if none provided + if (!properties.containsKey("java.naming.factory.initial")) { + properties.put("java.naming.factory.initial", "org.apache.camel.util.jndi.CamelInitialContextFactory"); + } return new InitialContext(properties); } } http://git-wip-us.apache.org/repos/asf/camel/blob/02b562aa/camel-core/src/test/java/org/apache/camel/impl/JndiRegistryTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/impl/JndiRegistryTest.java b/camel-core/src/test/java/org/apache/camel/impl/JndiRegistryTest.java index 0111f8c..a46b219 100644 --- a/camel-core/src/test/java/org/apache/camel/impl/JndiRegistryTest.java +++ b/camel-core/src/test/java/org/apache/camel/impl/JndiRegistryTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.impl; +import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; @@ -56,4 +57,20 @@ public class JndiRegistryTest extends TestCase { assertEquals("foo", key); assertSame(jndi.lookupByName("foo"), set.values().iterator().next()); } + + public void testDefault() throws Exception { + JndiRegistry jndi = new JndiRegistry(); + jndi.bind("bar", "Hello bar"); + assertEquals("Hello bar", jndi.lookup("bar")); + } + + public void testMap() throws Exception { + Map<Object, Object> env = new HashMap<Object, Object>(); + env.put("java.naming.factory.initial", "org.apache.camel.util.jndi.CamelInitialContextFactory"); + + JndiRegistry jndi = new JndiRegistry(env); + jndi.bind("bar", "Hello bar"); + assertEquals("Hello bar", jndi.lookup("bar")); + } + }