CAMEL-9223 - fix IllegalArgumentException when reverting fields using property 
placeholders


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b09b1a61
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b09b1a61
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b09b1a61

Branch: refs/heads/camel-2.16.x
Commit: b09b1a6121d8ab6e607112f6c54e1bb157252c9d
Parents: d444e86
Author: Jonathan Anstey <jans...@gmail.com>
Authored: Wed Oct 14 13:16:18 2015 -0230
Committer: Jonathan Anstey <jans...@gmail.com>
Committed: Wed Oct 14 13:16:46 2015 -0230

----------------------------------------------------------------------
 .../camel/model/ProcessorDefinitionHelper.java  |  8 +++--
 .../apache/camel/util/IntrospectionSupport.java | 36 ++++++++++++++++++--
 2 files changed, 39 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b09b1a61/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
 
b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 9eea4a8..50b777c 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -613,6 +613,10 @@ public final class ProcessorDefinitionHelper {
     }
 
     private static void addRestoreAction(final Object target, final 
Map<String, Object> properties) {
+        addRestoreAction(null, target, properties);
+    }
+    
+    private static void addRestoreAction(final CamelContext context, final 
Object target, final Map<String, Object> properties) {
         if (properties.isEmpty()) {
             return;
         }
@@ -626,7 +630,7 @@ public final class ProcessorDefinitionHelper {
             @Override
             public void run() {
                 try {
-                    IntrospectionSupport.setProperties(null, target, 
properties);
+                    IntrospectionSupport.setProperties(context, null, target, 
properties);
                 } catch (Exception e) {
                     LOG.warn("Could not restore definition properties", e);
                 }
@@ -742,7 +746,7 @@ public final class ProcessorDefinitionHelper {
                 }
             }
         }
-        addRestoreAction(definition, changedProperties);
+        addRestoreAction(camelContext, definition, changedProperties);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/b09b1a61/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java 
b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
index 13ceba9..f34ce11 100755
--- a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
@@ -38,8 +38,11 @@ import java.util.Set;
 import java.util.regex.Pattern;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
 import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.TypeConversionException;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.component.properties.PropertiesComponent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -446,14 +449,14 @@ public final class IntrospectionSupport {
         return rc;
     }
 
-    public static boolean setProperties(TypeConverter typeConverter, Object 
target, Map<String, Object> properties) throws Exception {
+    public static boolean setProperties(CamelContext context, TypeConverter 
typeConverter, Object target, Map<String, Object> properties) throws Exception {
         ObjectHelper.notNull(target, "target");
         ObjectHelper.notNull(properties, "properties");
         boolean rc = false;
 
         for (Iterator<Map.Entry<String, Object>> iter = 
properties.entrySet().iterator(); iter.hasNext();) {
             Map.Entry<String, Object> entry = iter.next();
-            if (setProperty(typeConverter, target, entry.getKey(), 
entry.getValue())) {
+            if (setProperty(context, typeConverter, target, entry.getKey(), 
entry.getValue())) {
                 iter.remove();
                 rc = true;
             }
@@ -461,6 +464,10 @@ public final class IntrospectionSupport {
 
         return rc;
     }
+    
+    public static boolean setProperties(TypeConverter typeConverter, Object 
target, Map<String, Object> properties) throws Exception {
+        return setProperties(null, typeConverter, target, properties);
+    }
 
     public static boolean setProperties(Object target, Map<String, Object> 
properties) throws Exception {
         return setProperties(null, target, properties);
@@ -561,7 +568,7 @@ public final class IntrospectionSupport {
             }
         }
 
-        if (typeConversionFailed != null) {
+        if (typeConversionFailed != null && !isPropertyPlaceholder(context, 
value)) {
             // we did not find a setter method to use, and if we did try to 
use a type converter then throw
             // this kind of exception as the caused by will hint this error
             throw new IllegalArgumentException("Could not find a suitable 
setter for property: " + name
@@ -572,6 +579,29 @@ public final class IntrospectionSupport {
         }
     }
 
+    private static boolean isPropertyPlaceholder(CamelContext context, Object 
value) {
+        if (context != null) {
+            Component component = context.hasComponent("properties");
+            if (component != null) {
+                PropertiesComponent pc;
+                try {
+                    pc = 
context.getTypeConverter().mandatoryConvertTo(PropertiesComponent.class, 
component);
+                } catch (Exception e) {
+                    return false;
+                }
+                if (value.toString().contains(pc.getPrefixToken()) && 
value.toString().contains(pc.getSuffixToken())) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    public static boolean setProperty(CamelContext context, TypeConverter 
typeConverter, Object target, String name, Object value) throws Exception {
+        // allow build pattern as a setter as well
+        return setProperty(context, typeConverter, target, name, value, null, 
true);
+    }
+    
     public static boolean setProperty(TypeConverter typeConverter, Object 
target, String name, Object value) throws Exception {
         // allow build pattern as a setter as well
         return setProperty(null, typeConverter, target, name, value, null, 
true);

Reply via email to