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 2015/11/15 09:04:18 UTC
[3/3] camel git commit: CAMEL-9326: JndiRegistry should default to
use CamelInitialContextFactory if no env factory specified
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/decca4ce
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/decca4ce
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/decca4ce
Branch: refs/heads/camel-2.16.x
Commit: decca4ce5d1fb65c32e68c3e21fbb4ca4fba6e50
Parents: b140458
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Nov 15 09:06:26 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Nov 15 09:07:50 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/decca4ce/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/decca4ce/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"));
+ }
+
}