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 2021/03/24 17:44:05 UTC

[camel] branch master updated (701fa4a -> 1fbf7d9)

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 701fa4a  CAMEL-16368: Add support for salesforce Composite SObject Collections API (#5259)
     new e9e8ed2  CAMEL-16397: camel-jsonpath - Evaluate jsonpath result using the practice that the jsonpath project itself suggests. This allows to use their JSonPath cache for thread safety.
     new 1fbf7d9  CAMEL-16393: Add WARN to json-path documentation about concat function has a bug and does not work.

The 2 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:
 .../camel/catalog/docs/jsonpath-language.adoc      |  9 +++--
 .../src/main/docs/jsonpath-language.adoc           |  9 +++--
 .../org/apache/camel/jsonpath/JsonPathEngine.java  | 43 ++++++++++------------
 .../modules/languages/pages/jsonpath-language.adoc |  9 +++--
 4 files changed, 37 insertions(+), 33 deletions(-)

[camel] 02/02: CAMEL-16393: Add WARN to json-path documentation about concat function has a bug and does not work.

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 1fbf7d9f452a6c2ace07f13d94ab89acbcea374a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 24 18:43:30 2021 +0100

    CAMEL-16393: Add WARN to json-path documentation about concat function has a bug and does not work.
---
 .../org/apache/camel/catalog/docs/jsonpath-language.adoc         | 9 ++++++---
 components/camel-jsonpath/src/main/docs/jsonpath-language.adoc   | 9 ++++++---
 docs/components/modules/languages/pages/jsonpath-language.adoc   | 9 ++++++---
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jsonpath-language.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jsonpath-language.adoc
index 6744e62..77d521d 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jsonpath-language.adoc
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jsonpath-language.adoc
@@ -80,9 +80,12 @@ follows
 
 == Syntax
 
-See the https://code.google.com/p/json-path/[JSonPath] project page for
+See the https://github.com/json-path/JsonPath[JSonPath] project page for
 further examples.
 
+WARNING: The `concat` function in https://github.com/json-path/JsonPath[JSonPath] has a https://issues.apache.org/jira/browse/CAMEL-16393[bug] and does not work. Do not use this function.
+You can instead store information in Camel exchange properties or headers and then concat those together afterwards using Camel's simple language.
+
 == Easy Syntax
 
 *Since Camel 2.19*
@@ -134,8 +137,8 @@ Camel JSonPath supports message body using the following types:
 | List | Message bodies as `java.util.List` types
 | POJO | *Optional* If Jackson is on the classpath, then camel-jsonpath
   is able to use Jackson to read the message body as POJO and convert to `java.util.Map`
-  which is supported by JSonPath. For example you can add `camel-jackson` as dependency to include Jackson.
-| InputStream | If none of the above types matches, then Camel will attempt to read the message body as an `java.io.InputStream`.
+  which is supported by JSonPath. For example, you can add `camel-jackson` as dependency to include Jackson.
+| InputStream | If none of the above types matches, then Camel will attempt to read the message body as a `java.io.InputStream`.
 |===
 
 If a message body is of unsupported type then an exception is thrown by default, however you
diff --git a/components/camel-jsonpath/src/main/docs/jsonpath-language.adoc b/components/camel-jsonpath/src/main/docs/jsonpath-language.adoc
index 6744e62..77d521d 100644
--- a/components/camel-jsonpath/src/main/docs/jsonpath-language.adoc
+++ b/components/camel-jsonpath/src/main/docs/jsonpath-language.adoc
@@ -80,9 +80,12 @@ follows
 
 == Syntax
 
-See the https://code.google.com/p/json-path/[JSonPath] project page for
+See the https://github.com/json-path/JsonPath[JSonPath] project page for
 further examples.
 
+WARNING: The `concat` function in https://github.com/json-path/JsonPath[JSonPath] has a https://issues.apache.org/jira/browse/CAMEL-16393[bug] and does not work. Do not use this function.
+You can instead store information in Camel exchange properties or headers and then concat those together afterwards using Camel's simple language.
+
 == Easy Syntax
 
 *Since Camel 2.19*
@@ -134,8 +137,8 @@ Camel JSonPath supports message body using the following types:
 | List | Message bodies as `java.util.List` types
 | POJO | *Optional* If Jackson is on the classpath, then camel-jsonpath
   is able to use Jackson to read the message body as POJO and convert to `java.util.Map`
-  which is supported by JSonPath. For example you can add `camel-jackson` as dependency to include Jackson.
-| InputStream | If none of the above types matches, then Camel will attempt to read the message body as an `java.io.InputStream`.
+  which is supported by JSonPath. For example, you can add `camel-jackson` as dependency to include Jackson.
+| InputStream | If none of the above types matches, then Camel will attempt to read the message body as a `java.io.InputStream`.
 |===
 
 If a message body is of unsupported type then an exception is thrown by default, however you
diff --git a/docs/components/modules/languages/pages/jsonpath-language.adoc b/docs/components/modules/languages/pages/jsonpath-language.adoc
index 0c26e35..f2f0f17 100644
--- a/docs/components/modules/languages/pages/jsonpath-language.adoc
+++ b/docs/components/modules/languages/pages/jsonpath-language.adoc
@@ -82,9 +82,12 @@ follows
 
 == Syntax
 
-See the https://code.google.com/p/json-path/[JSonPath] project page for
+See the https://github.com/json-path/JsonPath[JSonPath] project page for
 further examples.
 
+WARNING: The `concat` function in https://github.com/json-path/JsonPath[JSonPath] has a https://issues.apache.org/jira/browse/CAMEL-16393[bug] and does not work. Do not use this function.
+You can instead store information in Camel exchange properties or headers and then concat those together afterwards using Camel's simple language.
+
 == Easy Syntax
 
 *Since Camel 2.19*
@@ -136,8 +139,8 @@ Camel JSonPath supports message body using the following types:
 | List | Message bodies as `java.util.List` types
 | POJO | *Optional* If Jackson is on the classpath, then camel-jsonpath
   is able to use Jackson to read the message body as POJO and convert to `java.util.Map`
-  which is supported by JSonPath. For example you can add `camel-jackson` as dependency to include Jackson.
-| InputStream | If none of the above types matches, then Camel will attempt to read the message body as an `java.io.InputStream`.
+  which is supported by JSonPath. For example, you can add `camel-jackson` as dependency to include Jackson.
+| InputStream | If none of the above types matches, then Camel will attempt to read the message body as a `java.io.InputStream`.
 |===
 
 If a message body is of unsupported type then an exception is thrown by default, however you

[camel] 01/02: CAMEL-16397: camel-jsonpath - Evaluate jsonpath result using the practice that the jsonpath project itself suggests. This allows to use their JSonPath cache for thread safety.

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 e9e8ed2057f0122f30664eb123ca00775a69c538
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 24 18:38:35 2021 +0100

    CAMEL-16397: camel-jsonpath - Evaluate jsonpath result using the practice that the jsonpath project itself suggests. This allows to use their JSonPath cache for thread safety.
---
 .../org/apache/camel/jsonpath/JsonPathEngine.java  | 43 ++++++++++------------
 1 file changed, 19 insertions(+), 24 deletions(-)

diff --git a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
index d64eca0f..e62cb7d 100644
--- a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
+++ b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
@@ -54,8 +54,8 @@ public class JsonPathEngine {
     private final String expression;
     private final boolean writeAsString;
     private final String headerName;
-    private final JsonPath path;
     private final Configuration configuration;
+    private final boolean hasSimple;
     private JsonPathAdapter adapter;
     private volatile boolean initJsonAdapter;
 
@@ -81,33 +81,28 @@ public class JsonPathEngine {
         }
         this.configuration = builder.build();
 
-        boolean hasSimple = false;
+        boolean simpleInUse = false;
         if (allowSimple) {
             // is simple language embedded
             Matcher matcher = SIMPLE_PATTERN.matcher(expression);
             if (matcher.find()) {
-                hasSimple = true;
+                simpleInUse = true;
             }
         }
-        if (hasSimple) {
-            this.path = null;
-        } else {
-            this.path = JsonPath.compile(expression);
-            LOG.debug("Compiled static JsonPath: {}", expression);
-        }
+        this.hasSimple = simpleInUse;
     }
 
     @SuppressWarnings("unchecked")
     public Object read(Exchange exchange) throws Exception {
         Object answer;
-        if (path == null) {
+        if (hasSimple) {
+            // need to compile every time
             Expression exp = exchange.getContext().resolveLanguage("simple").createExpression(expression);
             String text = exp.evaluate(exchange, String.class);
-            JsonPath path = JsonPath.compile(text);
-            LOG.debug("Compiled dynamic JsonPath: {}", expression);
-            answer = doRead(path, exchange);
+            LOG.debug("Compiled dynamic JsonPath: {}", text);
+            answer = doRead(text, exchange);
         } else {
-            answer = doRead(path, exchange);
+            answer = doRead(expression, exchange);
         }
 
         if (writeAsString) {
@@ -158,7 +153,7 @@ public class JsonPathEngine {
         return answer;
     }
 
-    private Object doRead(JsonPath path, Exchange exchange) throws IOException, CamelExchangeException {
+    private Object doRead(String path, Exchange exchange) throws IOException, CamelExchangeException {
         Object json = headerName != null ? exchange.getIn().getHeader(headerName) : exchange.getIn().getBody();
 
         if (json instanceof InputStream) {
@@ -169,22 +164,22 @@ public class JsonPathEngine {
             if (genericFile.getCharset() != null) {
                 // special treatment for generic file with charset
                 InputStream inputStream = new FileInputStream((File) genericFile.getFile());
-                return path.read(inputStream, genericFile.getCharset(), configuration);
+                return JsonPath.using(configuration).parse(inputStream, genericFile.getCharset()).read(path);
             }
         }
 
         if (json instanceof String) {
             LOG.trace("JSonPath: {} is read as String: {}", path, json);
             String str = (String) json;
-            return path.read(str, configuration);
+            return JsonPath.using(configuration).parse(str).read(path);
         } else if (json instanceof Map) {
             LOG.trace("JSonPath: {} is read as Map: {}", path, json);
             Map map = (Map) json;
-            return path.read(map, configuration);
+            return JsonPath.using(configuration).parse(map).read(path);
         } else if (json instanceof List) {
             LOG.trace("JSonPath: {} is read as List: {}", path, json);
             List list = (List) json;
-            return path.read(list, configuration);
+            return JsonPath.using(configuration).parse(list).read(path);
         } else {
             // can we find an adapter which can read the message body/header
             Object answer = readWithAdapter(path, exchange);
@@ -214,7 +209,7 @@ public class JsonPathEngine {
         }
     }
 
-    private Object readWithInputStream(JsonPath path, Exchange exchange) throws IOException {
+    private Object readWithInputStream(String path, Exchange exchange) throws IOException {
         Object json = headerName != null ? exchange.getIn().getHeader(headerName) : exchange.getIn().getBody();
         LOG.trace("JSonPath: {} is read as InputStream: {}", path, json);
 
@@ -228,19 +223,19 @@ public class JsonPathEngine {
             String jsonEncoding = exchange.getIn().getHeader(JsonPathConstants.HEADER_JSON_ENCODING, String.class);
             if (jsonEncoding != null) {
                 // json encoding specified in header
-                return path.read(is, jsonEncoding, configuration);
+                return JsonPath.using(configuration).parse(is, jsonEncoding).read(path);
             } else {
                 // No json encoding specified --> assume json encoding is unicode and determine the specific unicode encoding according to RFC-4627.
                 // This is a temporary solution, it can be removed as soon as jsonpath offers the encoding detection
                 JsonStream jsonStream = new JsonStream(is);
-                return path.read(jsonStream, jsonStream.getEncoding().name(), configuration);
+                return JsonPath.using(configuration).parse(jsonStream, jsonStream.getEncoding().name()).read(path);
             }
         }
 
         return null;
     }
 
-    private Object readWithAdapter(JsonPath path, Exchange exchange) {
+    private Object readWithAdapter(String path, Exchange exchange) {
         Object json = headerName != null ? exchange.getIn().getHeader(headerName) : exchange.getIn().getBody();
         LOG.trace("JSonPath: {} is read with adapter: {}", path, json);
 
@@ -259,7 +254,7 @@ public class JsonPathEngine {
                     LOG.debug("JacksonJsonAdapter converted object from: {} to: java.util.Map",
                             ObjectHelper.classCanonicalName(json));
                 }
-                return path.read(map, configuration);
+                return JsonPath.using(configuration).parse(map).read(path);
             }
         }