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/16 14:21:25 UTC
[2/2] camel git commit: CAMEL-9326: JndiRegistry should default to
use CamelInitialContextFactory if no env factory specified in standalone mode
to be backwards compatible.
CAMEL-9326: JndiRegistry should default to use CamelInitialContextFactory if no env factory specified in standalone mode to be backwards compatible.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4ac1aed0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4ac1aed0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4ac1aed0
Branch: refs/heads/camel-2.16.x
Commit: 4ac1aed0059ff16b9f3441a5132b9d72f95a996f
Parents: 22fa248
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Nov 16 14:24:00 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 16 14:24:36 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/camel/impl/JndiRegistry.java | 17 +++++++++++++++--
.../org/apache/camel/impl/JndiRegistryTest.java | 6 +++---
2 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4ac1aed0/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 21fc178..cc39b21 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
@@ -31,6 +31,7 @@ import javax.naming.NamingException;
import org.apache.camel.NoSuchBeanException;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.Registry;
+import org.apache.camel.util.jndi.CamelInitialContextFactory;
/**
* A {@link Registry} implementation which looks up the objects in JNDI
@@ -38,16 +39,28 @@ import org.apache.camel.spi.Registry;
public class JndiRegistry implements Registry {
private Context context;
private Map environment;
+ private final boolean standalone;
public JndiRegistry() {
+ this.standalone = false;
}
public JndiRegistry(Map environment) {
this.environment = environment;
+ this.standalone = false;
}
public JndiRegistry(Context context) {
this.context = context;
+ this.standalone = false;
+ }
+
+ /**
+ * Whether to use standalone mode, where the JNDI initial context factory is using
+ * {@link CamelInitialContextFactory}.
+ */
+ public JndiRegistry(boolean standalone) {
+ this.standalone = true;
}
public <T> T lookupByNameAndType(String name, Class<T> type) {
@@ -154,8 +167,8 @@ public class JndiRegistry implements Registry {
if (environment != null) {
properties.putAll(environment);
}
- // must include a factory if none provided
- if (!properties.containsKey("java.naming.factory.initial")) {
+ // must include a factory if none provided in standalone mode
+ if (standalone && !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/4ac1aed0/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 a46b219..21e0eef 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
@@ -58,13 +58,13 @@ public class JndiRegistryTest extends TestCase {
assertSame(jndi.lookupByName("foo"), set.values().iterator().next());
}
- public void testDefault() throws Exception {
- JndiRegistry jndi = new JndiRegistry();
+ public void testStandalone() throws Exception {
+ JndiRegistry jndi = new JndiRegistry(true);
jndi.bind("bar", "Hello bar");
assertEquals("Hello bar", jndi.lookup("bar"));
}
- public void testMap() throws Exception {
+ public void testCamelContextFactory() throws Exception {
Map<Object, Object> env = new HashMap<Object, Object>();
env.put("java.naming.factory.initial", "org.apache.camel.util.jndi.CamelInitialContextFactory");