You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2020/02/12 02:45:17 UTC

[camel] 07/18: Fix support for extra properties on dataformat

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ab60f402cb35f4d0c9ce7c986e7a099857ea54b4
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Feb 11 06:34:21 2020 +0100

    Fix support for extra properties on dataformat
---
 .../org/apache/camel/reifier/AbstractReifier.java  | 34 ++++++++++++++++++++++
 .../reifier/dataformat/DataFormatReifier.java      |  9 +-----
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/AbstractReifier.java b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/AbstractReifier.java
index 17eac69..b10c685 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/AbstractReifier.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/AbstractReifier.java
@@ -16,17 +16,24 @@
  */
 package org.apache.camel.reifier;
 
+import java.util.Map;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Expression;
 import org.apache.camel.Predicate;
+import org.apache.camel.model.Constants;
 import org.apache.camel.model.ExpressionSubElementDefinition;
+import org.apache.camel.model.OtherAttributesAware;
 import org.apache.camel.model.language.ExpressionDefinition;
 import org.apache.camel.reifier.language.ExpressionReifier;
+import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.support.CamelContextHelper;
 
 public abstract class AbstractReifier {
 
+    private static final String PREFIX = "{" + Constants.PLACEHOLDER_QNAME + "}";
+
     protected final RouteContext routeContext;
     protected final CamelContext camelContext;
 
@@ -77,4 +84,31 @@ public abstract class AbstractReifier {
         return ExpressionReifier.reifier(camelContext, expression).createPredicate();
     }
 
+    @SuppressWarnings("unchecked")
+    protected void addOtherAttributes(Object definition, Map<String, Object> properties) {
+        if (definition instanceof OtherAttributesAware) {
+            Map<Object, Object> others = ((OtherAttributesAware) definition).getOtherAttributes();
+            others.forEach((k, v) -> {
+                String ks = k.toString();
+                if (ks.startsWith(PREFIX) && v instanceof String) {
+                    // value must be enclosed with placeholder tokens
+                    String s = (String) v;
+                    if (!s.startsWith(PropertiesComponent.PREFIX_TOKEN) && !s.endsWith(PropertiesComponent.SUFFIX_TOKEN)) {
+                        s = PropertiesComponent.PREFIX_TOKEN + s + PropertiesComponent.SUFFIX_TOKEN;
+                    }
+                    String kk = ks.substring(PREFIX.length());
+                    properties.put(kk, s);
+                }
+            });
+        }
+    }
+
+    protected Object or(Object a, Object b) {
+        return a != null ? a : b;
+    }
+
+    protected Object asRef(String s) {
+        return s != null ? s.startsWith("#") ? s : "#" + s : null;
+    }
+
 }
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java
index 053ac11..f9c8c23 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java
@@ -235,6 +235,7 @@ public abstract class DataFormatReifier<T extends DataFormatDefinition> extends
         Map<String, Object> properties = new LinkedHashMap<>();
         prepareDataFormatConfig(properties);
         properties.entrySet().removeIf(e -> e.getValue() == null);
+        addOtherAttributes(definition, properties);
 
         PropertyConfigurer configurer = findPropertyConfigurer(dataFormat, camelContext);
 
@@ -285,12 +286,4 @@ public abstract class DataFormatReifier<T extends DataFormatDefinition> extends
 
     protected abstract void prepareDataFormatConfig(Map<String, Object> properties);
 
-    protected Object or(Object a, Object b) {
-        return a != null ? a : b;
-    }
-
-    protected Object asRef(String s) {
-        return s != null ? s.startsWith("#") ? s : "#" + s : null;
-    }
-
 }