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 2020/11/15 16:54:54 UTC

[camel] branch master updated (9064457 -> ba72a95)

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

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


    from 9064457  regen allcomponents. We need a different solution for assembly.
     new a421bf8  CAMEL-15852: PropertyBindingSupport should support dots in map keys
     new 8d53b37  Fixed camel-log autowired exchange formatter tests
     new ba72a95  CAMEL-15852: PropertyBindingSupport should support dots in map keys

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../component/log/LogComponentOptionsTest.java     |  4 ++
 .../component/log/LogCustomFormatterTest.java      |  2 +
 .../PropertyBindingSupportMapDotKeyTest.java       | 76 ++++++++++++++++++++++
 .../camel/support/PropertyBindingSupport.java      | 56 ++++++++++++++--
 4 files changed, 134 insertions(+), 4 deletions(-)
 create mode 100644 core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportMapDotKeyTest.java


[camel] 03/03: CAMEL-15852: PropertyBindingSupport should support dots in map keys

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ba72a95907a359c8434963ca4fca835e8f147550
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Nov 15 16:07:24 2020 +0100

    CAMEL-15852: PropertyBindingSupport should support dots in map keys
---
 .../camel/support/PropertyBindingSupport.java      | 98 +++++++++++-----------
 1 file changed, 48 insertions(+), 50 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index bec7363..0755855 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -217,56 +217,6 @@ public final class PropertyBindingSupport {
         return answer;
     }
 
-    // TODO: Move these methods to other location
-    private static String[] splitKey(String key) {
-        List<String> parts = new ArrayList<>();
-
-        boolean mapKey = false;
-        StringBuilder sb = new StringBuilder();
-        for (int i = 0; i < key.length(); i++) {
-            char ch = key.charAt(i);
-            if (ch == '[') {
-                mapKey = true;
-            } else if (ch == ']') {
-                mapKey = false;
-            }
-            if (ch == '.' && !mapKey) {
-                // dont include the separator dot
-                parts.add(sb.toString());
-                sb.setLength(0);
-            } else {
-                sb.append(ch);
-            }
-        }
-        if (sb.length() > 0) {
-            parts.add(sb.toString());
-        }
-
-        return parts.toArray(new String[parts.size()]);
-    }
-
-    private static boolean isDotKey(String key) {
-        // we only want to know if there is a dot in OGNL path, so any map keys [iso.code] is accepted
-
-        if (key.indexOf('[') == -1 && key.indexOf('.') != -1) {
-            return true;
-        }
-
-        boolean mapKey = false;
-        for (int i = 0; i < key.length(); i++) {
-            char ch = key.charAt(i);
-            if (ch == '[') {
-                mapKey = true;
-            } else if (ch == ']') {
-                mapKey = false;
-            }
-            if (ch == '.' && !mapKey) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     private static boolean doBuildPropertyOgnlPath(
             final CamelContext camelContext, final Object originalTarget, String name, final Object value,
             boolean deepNesting, boolean fluentBuilder, boolean allowPrivateSetter,
@@ -1539,6 +1489,54 @@ public final class PropertyBindingSupport {
         return key;
     }
 
+    private static boolean isDotKey(String key) {
+        // we only want to know if there is a dot in OGNL path, so any map keys [iso.code] is accepted
+
+        if (key.indexOf('[') == -1 && key.indexOf('.') != -1) {
+            return true;
+        }
+
+        boolean mapKey = false;
+        for (char ch : key.toCharArray()) {
+            if (ch == '[') {
+                mapKey = true;
+            } else if (ch == ']') {
+                mapKey = false;
+            }
+            if (ch == '.' && !mapKey) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static String[] splitKey(String key) {
+        // split the key into parts separated by dot (but handle map keys [iso.code] etc.
+        List<String> parts = new ArrayList<>();
+
+        boolean mapKey = false;
+        StringBuilder sb = new StringBuilder();
+        for (char ch : key.toCharArray()) {
+            if (ch == '[') {
+                mapKey = true;
+            } else if (ch == ']') {
+                mapKey = false;
+            }
+            if (ch == '.' && !mapKey) {
+                // dont include the separator dot
+                parts.add(sb.toString());
+                sb.setLength(0);
+            } else {
+                sb.append(ch);
+            }
+        }
+        if (sb.length() > 0) {
+            parts.add(sb.toString());
+        }
+
+        return parts.toArray(new String[parts.size()]);
+    }
+
     @FunctionalInterface
     public interface OnAutowiring {
 


[camel] 02/03: Fixed camel-log autowired exchange formatter tests

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8d53b377213741a1474d4adec43123bfb419294b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Nov 15 16:05:59 2020 +0100

    Fixed camel-log autowired exchange formatter tests
---
 .../java/org/apache/camel/component/log/LogComponentOptionsTest.java  | 4 ++++
 .../java/org/apache/camel/component/log/LogCustomFormatterTest.java   | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/log/LogComponentOptionsTest.java b/core/camel-core/src/test/java/org/apache/camel/component/log/LogComponentOptionsTest.java
index 33603fd..d0ca9ca 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/log/LogComponentOptionsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/log/LogComponentOptionsTest.java
@@ -84,6 +84,8 @@ public class LogComponentOptionsTest extends ContextTestSupport {
 
         DefaultExchangeFormatter myFormatter = new DefaultExchangeFormatter();
         context.getRegistry().bind("myGreatFormatter", myFormatter);
+        DefaultExchangeFormatter mySecondFormatter = new DefaultExchangeFormatter();
+        context.getRegistry().bind("mySecondFormatter", mySecondFormatter);
 
         LogComponent log = context.getComponent("log", LogComponent.class);
         assertNull(log.getExchangeFormatter());
@@ -130,6 +132,8 @@ public class LogComponentOptionsTest extends ContextTestSupport {
 
         DefaultExchangeFormatter myFormatter = new DefaultExchangeFormatter();
         context.getRegistry().bind("myGreatFormatter", myFormatter);
+        DefaultExchangeFormatter mySecondFormatter = new DefaultExchangeFormatter();
+        context.getRegistry().bind("mySecondFormatter", mySecondFormatter);
 
         LogComponent log = context.getComponent("log", LogComponent.class);
         assertNull(log.getExchangeFormatter());
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/log/LogCustomFormatterTest.java b/core/camel-core/src/test/java/org/apache/camel/component/log/LogCustomFormatterTest.java
index 5b5bf7a..d8ebdc7 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/log/LogCustomFormatterTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/log/LogCustomFormatterTest.java
@@ -20,6 +20,7 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.spi.ExchangeFormatter;
+import org.apache.camel.support.processor.DefaultExchangeFormatter;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -121,6 +122,7 @@ public class LogCustomFormatterTest extends ContextTestSupport {
 
         exchangeFormatter = new TestExchangeFormatter();
         context.getRegistry().bind("anotherFormatter", exchangeFormatter);
+        context.getRegistry().bind("yetAnotherFormatter", new DefaultExchangeFormatter());
 
         context.start();
 


[camel] 01/03: CAMEL-15852: PropertyBindingSupport should support dots in map keys

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a421bf83c9fc5628731db50da81d7b9372c15ad7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Nov 15 16:05:43 2020 +0100

    CAMEL-15852: PropertyBindingSupport should support dots in map keys
---
 .../PropertyBindingSupportMapDotKeyTest.java       | 76 ++++++++++++++++++++++
 .../camel/support/PropertyBindingSupport.java      | 58 +++++++++++++++--
 2 files changed, 130 insertions(+), 4 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportMapDotKeyTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportMapDotKeyTest.java
new file mode 100644
index 0000000..c3bf109
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportMapDotKeyTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.support;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.camel.ContextTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Unit test for PropertyBindingSupport
+ */
+public class PropertyBindingSupportMapDotKeyTest extends ContextTestSupport {
+
+    @Test
+    public void testPropertiesMapDotKey() throws Exception {
+        Foo foo = new Foo();
+
+        Map<String, Object> prop = new LinkedHashMap<>();
+        prop.put("name", "James");
+        prop.put("data[age]", "33");
+        prop.put("data[zip.code]", "90210");
+        prop.put("data[ISO.CODE]", "USA");
+        prop.put("data[with-dash]", "123");
+        prop.put("data[with_underscore]", "456");
+
+        PropertyBindingSupport.build().bind(context, foo, prop);
+
+        assertEquals("James", foo.getName());
+        assertEquals("33", foo.getData().get("age"));
+        assertEquals("90210", foo.getData().get("zip.code"));
+        assertEquals("USA", foo.getData().get("ISO.CODE"));
+        assertEquals("123", foo.getData().get("with-dash"));
+        assertEquals("456", foo.getData().get("with_underscore"));
+    }
+
+    public static class Foo {
+        private String name;
+        private Map<String, String> data = new HashMap<>();
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public Map<String, String> getData() {
+            return data;
+        }
+
+        public void setData(Map<String, String> data) {
+            this.data = data;
+        }
+    }
+
+}
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 342bf29..bec7363 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -201,7 +201,7 @@ public final class PropertyBindingSupport {
             Object value = entry.getValue();
 
             // if nesting is not allowed, then only bind properties without dots (OGNL graph)
-            if (!nesting && key.indexOf('.') != -1) {
+            if (!nesting && isDotKey(key)) {
                 continue;
             }
 
@@ -217,6 +217,56 @@ public final class PropertyBindingSupport {
         return answer;
     }
 
+    // TODO: Move these methods to other location
+    private static String[] splitKey(String key) {
+        List<String> parts = new ArrayList<>();
+
+        boolean mapKey = false;
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < key.length(); i++) {
+            char ch = key.charAt(i);
+            if (ch == '[') {
+                mapKey = true;
+            } else if (ch == ']') {
+                mapKey = false;
+            }
+            if (ch == '.' && !mapKey) {
+                // dont include the separator dot
+                parts.add(sb.toString());
+                sb.setLength(0);
+            } else {
+                sb.append(ch);
+            }
+        }
+        if (sb.length() > 0) {
+            parts.add(sb.toString());
+        }
+
+        return parts.toArray(new String[parts.size()]);
+    }
+
+    private static boolean isDotKey(String key) {
+        // we only want to know if there is a dot in OGNL path, so any map keys [iso.code] is accepted
+
+        if (key.indexOf('[') == -1 && key.indexOf('.') != -1) {
+            return true;
+        }
+
+        boolean mapKey = false;
+        for (int i = 0; i < key.length(); i++) {
+            char ch = key.charAt(i);
+            if (ch == '[') {
+                mapKey = true;
+            } else if (ch == ']') {
+                mapKey = false;
+            }
+            if (ch == '.' && !mapKey) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private static boolean doBuildPropertyOgnlPath(
             final CamelContext camelContext, final Object originalTarget, String name, final Object value,
             boolean deepNesting, boolean fluentBuilder, boolean allowPrivateSetter,
@@ -239,8 +289,8 @@ public final class PropertyBindingSupport {
 
         // we should only walk and create OGNL path for the middle graph
         String[] parts;
-        if (name.contains(".")) {
-            parts = name.split("\\.");
+        if (isDotKey(name)) {
+            parts = splitKey(name);
         } else {
             parts = new String[] { name };
         }
@@ -1808,7 +1858,7 @@ public final class PropertyBindingSupport {
             // so we can remove the corresponding key from the original map
 
             // walk key with dots to remove right node
-            String[] parts = key.toString().split("\\.");
+            String[] parts = splitKey(key.toString());
             Map map = originalMap;
             for (int i = 0; i < parts.length; i++) {
                 String part = parts[i];