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 2013/04/25 10:53:27 UTC

svn commit: r1475677 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ components/camel-spring/src/test/resources/org/apache/camel/component/properties/

Author: davsclaus
Date: Thu Apr 25 08:53:27 2013
New Revision: 1475677

URL: http://svn.apache.org/r1475677
Log:
CAMEL-6313: Fixed using property placeholders on <camelContext> attributes.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties

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=1475677&r1=1475676&r2=1475677&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 Thu Apr 25 08:53:27 2013
@@ -1055,13 +1055,32 @@ public class DefaultCamelContext extends
         // with custom tokens, we cannot know if the URI contains a property or not without having
         // the component.  We also lose fail-fast behavior for the missing component with this change.
         PropertiesComponent pc = getPropertiesComponent();
-        
+
         // Do not parse uris that are designated for the properties component as it will handle that itself
         if (text != null && !text.startsWith("properties:")) {
             // No component, assume default tokens.
             if (pc == null && text.contains(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) {
-                throw new IllegalArgumentException("PropertiesComponent with name properties must be defined"
-                        + " in CamelContext to support property placeholders.");
+
+                // try to lookup component, as we may be initializing CamelContext itself
+                Component existing = lookupPropertiesComponent();
+                if (existing != null) {
+                    if (existing instanceof PropertiesComponent) {
+                        pc = (PropertiesComponent) existing;
+                    } else {
+                        // properties component must be expected type
+                        throw new IllegalArgumentException("Found properties component of type: " + existing.getClass() + " instead of expected: " + PropertiesComponent.class);
+                    }
+                }
+
+                if (pc != null) {
+                    // the parser will throw exception if property key was not found
+                    String answer = pc.parseUri(text);
+                    log.debug("Resolved text: {} -> {}", text, answer);
+                    return answer;
+                } else {
+                    throw new IllegalArgumentException("PropertiesComponent with name properties must be defined"
+                            + " in CamelContext to support property placeholders.");
+                }
                 
             // Component available, use actual tokens
             } else if (pc != null && text.contains(pc.getPrefixToken())) {
@@ -1585,14 +1604,8 @@ public class DefaultCamelContext extends
 
         // eager lookup any configured properties component to avoid subsequent lookup attempts which may impact performance
         // due we use properties component for property placeholder resolution at runtime
-        Component existing = hasComponent("properties");
-        if (existing == null) {
-            // no existing properties component so lookup and add as component if possible
-            propertiesComponent = getRegistry().lookupByNameAndType("properties", PropertiesComponent.class);
-            if (propertiesComponent != null) {
-                addComponent("properties", propertiesComponent);
-            }
-        } else {
+        Component existing = lookupPropertiesComponent();
+        if (existing != null) {
             // store reference to the existing properties component
             if (existing instanceof PropertiesComponent) {
                 propertiesComponent = (PropertiesComponent) existing;
@@ -2496,6 +2509,18 @@ public class DefaultCamelContext extends
         }
     }
 
+    protected Component lookupPropertiesComponent() {
+        // no existing properties component so lookup and add as component if possible
+        PropertiesComponent answer = (PropertiesComponent) hasComponent("properties");
+        if (answer == null) {
+            answer = getRegistry().lookupByNameAndType("properties", PropertiesComponent.class);
+            if (answer != null) {
+                addComponent("properties", answer);
+            }
+        }
+        return answer;
+    }
+
     public ShutdownStrategy getShutdownStrategy() {
         return shutdownStrategy;
     }

Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml?rev=1475677&r1=1475676&r2=1475677&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml Thu Apr 25 08:53:27 2013
@@ -26,7 +26,7 @@
         <property name="location" value="classpath:org/apache/camel/component/properties/cheese.properties"/>
     </bean>
 
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <camelContext autoStartup="{{autoStartup}}" xmlns="http://camel.apache.org/schema/spring">
 
         <route>
             <from uri="direct:start"/>

Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties?rev=1475677&r1=1475676&r2=1475677&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties Thu Apr 25 08:53:27 2013
@@ -24,4 +24,6 @@ slipDelimiter=##
 delay=25
 max=3
 
-hi=Bonjour
\ No newline at end of file
+hi=Bonjour
+
+autoStartup=true