camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1441785 - /camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Date Sat, 02 Feb 2013 18:18:37 GMT
Author: davsclaus
Date: Sat Feb  2 18:18:37 2013
New Revision: 1441785

URL: http://svn.apache.org/viewvc?rev=1441785&view=rev
Log:
CAMEL-6031: DefaultCamelContext should by default fallback and use simple registry if JNDI
is not possible. If people explicit configure JNDI then it will still fail as they would expect
to keep using JNDI .

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1441785&r1=1441784&r2=1441785&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Sat
Feb  2 18:18:37 2013
@@ -209,6 +209,12 @@ public class DefaultCamelContext extends
     private final StopWatch stopWatch = new StopWatch(false);
     private Date startDate;
 
+    /**
+     * Creates the {@link CamelContext} using {@link JndiRegistry} as registry,
+     * but will silently fallback and use {@link SimpleRegistry} if JNDI cannot be used.
+     * <p/>
+     * Use one of the other constructors to force use an explicit registry / JNDI.
+     */
     public DefaultCamelContext() {
         this.executorServiceManager = new DefaultExecutorServiceManager(this);
 
@@ -1173,7 +1179,7 @@ public class DefaultCamelContext extends
     }
 
     public void setRegistry(Registry registry) {
-        // wrap the registry so we always do propery placeholder lookups
+        // wrap the registry so we always do property placeholder lookups
         if (!(registry instanceof PropertyPlaceholderDelegateRegistry)) {
             registry = new PropertyPlaceholderDelegateRegistry(this, registry);
         }
@@ -2134,6 +2140,7 @@ public class DefaultCamelContext extends
      * components and create routes
      */
     protected void forceLazyInitialization() {
+        getRegistry();
         getInjector();
         getLanguageResolver();
         getTypeConverterRegistry();
@@ -2195,7 +2202,15 @@ public class DefaultCamelContext extends
      * Lazily create a default implementation
      */
     protected Registry createRegistry() {
-        return new JndiRegistry();
+        JndiRegistry jndi = new JndiRegistry();
+        try {
+            // getContext() will force setting up JNDI
+            jndi.getContext();
+            return jndi;
+        } catch (Throwable e) {
+            log.debug("Cannot create javax.naming.InitialContext due " + e.getMessage() +
". Will fallback and use SimpleRegistry instead. This exception is ignored.", e);
+            return new SimpleRegistry();
+        }
     }
 
     /**



Mime
View raw message