camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1475679 - in /camel/branches/camel-2.10.x: ./ camel-core/src/main/java/org/apache/camel/impl/ components/camel-spring/src/test/resources/org/apache/camel/component/properties/
Date Thu, 25 Apr 2013 08:58:42 GMT
Author: davsclaus
Date: Thu Apr 25 08:58:42 2013
New Revision: 1475679

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

Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml
    camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1475677
  Merged /camel/branches/camel-2.11.x:r1475678

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1475679&r1=1475678&r2=1475679&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Thu Apr 25 08:58:42 2013
@@ -1030,13 +1030,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())) {
@@ -1560,14 +1579,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().lookup("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;
@@ -2440,6 +2453,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().lookup("properties", PropertiesComponent.class);
+            if (answer != null) {
+                addComponent("properties", answer);
+            }
+        }
+        return answer;
+    }
+
     public ShutdownStrategy getShutdownStrategy() {
         return shutdownStrategy;
     }

Modified: camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml?rev=1475679&r1=1475678&r2=1475679&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml
(original)
+++ camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentTest.xml
Thu Apr 25 08:58:42 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/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties?rev=1475679&r1=1475678&r2=1475679&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties
(original)
+++ camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties
Thu Apr 25 08:58:42 2013
@@ -24,4 +24,6 @@ slipDelimiter=##
 delay=25
 max=3
 
-hi=Bonjour
\ No newline at end of file
+hi=Bonjour
+
+autoStartup=true



Mime
View raw message