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

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


The following commit(s) were added to refs/heads/main by this push:
     new 6b414dec4 chore: jolt-transformation-action reads a JsonNode, 
aws-cloudwatch-sink fails on an empty List; fix the two red tests of main 
(#3315)
6b414dec4 is described below

commit 6b414dec4deb86f0e18c859e354834f140876ddb
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 21 12:44:57 2026 +0100

    chore: jolt-transformation-action reads a JsonNode, aws-cloudwatch-sink 
fails on an empty List; fix the two red tests of main (#3315)
    
    * chore: jolt-transformation-action reads a JsonNode, aws-cloudwatch-sink 
fails on an empty List
    
    CAMEL-27306 made camel-jolt convert a Jackson JsonNode body, so the
    json-serialize-action workaround in the description of
    jolt-transformation-action is gone and the test checks that a JsonNode
    is transformed. CAMEL-27307 made camel-aws2-cw fail on an empty
    collection or array, which the Input paragraph of aws-cloudwatch-sink
    now says and its body test checks.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
    
    * ci: google-storage-sink-storage-class-route-test expects the binary 
Content-Type
    
    #3285 added the test when google-storage-sink had no input data type.
    #3307 then made binary the default, which sets Content-Type
    application/octet-stream, so main fails on this test. It now expects
    that, and removes Content-Type before the HTTP call, as the other
    google-storage-sink test does (citrusframework/citrus#2081).
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
    
    ---------
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 kamelets/aws-cloudwatch-sink.kamelet.yaml          |  2 +-
 kamelets/jolt-transformation-action.kamelet.yaml   |  4 +--
 .../main/resources/META-INF/kamelets-index.json    |  4 +--
 .../kamelets/aws-cloudwatch-sink.kamelet.yaml      |  2 +-
 .../jolt-transformation-action.kamelet.yaml        |  4 +--
 .../aws-cloudwatch-sink-body-route.citrus.it.yaml  | 24 ++++++++++++++++-
 .../cloudwatch/aws-cloudwatch-sink-body-route.yaml | 31 ++++++++++++++++++++++
 ...storage-sink-storage-class-route.citrus.it.yaml |  2 +-
 .../google-storage-sink-storage-class-route.yaml   |  3 +++
 ...jolt-transformation-action-route.citrus.it.yaml | 22 +--------------
 .../jolt-transformation-action-route.yaml          | 27 ++-----------------
 11 files changed, 69 insertions(+), 56 deletions(-)

diff --git a/kamelets/aws-cloudwatch-sink.kamelet.yaml 
b/kamelets/aws-cloudwatch-sink.kamelet.yaml
index e7fd86dab..4523b5a31 100644
--- a/kamelets/aws-cloudwatch-sink.kamelet.yaml
+++ b/kamelets/aws-cloudwatch-sink.kamelet.yaml
@@ -37,7 +37,7 @@ spec:
 
       Use it to record business or technical numbers from an integration, such 
as orders processed, items in stock or processing time, and to graph them or 
set alarms on them in CloudWatch.
 
-      Input: the data point comes from the headers and options, and the body, 
such as text or a Map, is not used, unless it is a List, an array or a 
`MetricDatum`. The `metric-name` header (or `ce-metricname`) is the name of the 
metric; it is required unless the `metricName` option is set. The optional 
`metric-value` header (or `ce-metricvalue`) is the value, a number; when it is 
not set, the value is `metricValue`, or 1. The optional `metric-unit` header 
(or `ce-metricunit`) is the unit [...]
+      Input: the data point comes from the headers and options, and the body, 
such as text or a Map, is not used, unless it is a List, an array or a 
`MetricDatum`. The `metric-name` header (or `ce-metricname`) is the name of the 
metric; it is required unless the `metricName` option is set. The optional 
`metric-value` header (or `ce-metricvalue`) is the value, a number; when it is 
not set, the value is `metricValue`, or 1. The optional `metric-unit` header 
(or `ce-metricunit`) is the unit [...]
 
       Output: the message is unchanged.
 
diff --git a/kamelets/jolt-transformation-action.kamelet.yaml 
b/kamelets/jolt-transformation-action.kamelet.yaml
index 1cbb3ed4f..41ef31ae3 100644
--- a/kamelets/jolt-transformation-action.kamelet.yaml
+++ b/kamelets/jolt-transformation-action.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
 
       Use it to map the JSON of one system to the JSON another system expects, 
for example to rename fields or move them into a nested object, when you 
already have Jolt specifications. `jslt-action` does the same with a query 
language, and is often easier to write.
 
-      Input: parsed JSON as a Map (or a List), or a JSON object or array as 
text, bytes or a stream. JSON text, bytes and a stream need Camel 4.24 or 
later; with older versions they do not fail but give an empty body.
+      Input: parsed JSON as a Map (or a List), a Jackson `JsonNode` such as 
the output of `json-deserialize-action`, or a JSON object or array as text, 
bytes or a stream. JSON text, bytes and a stream need Camel 4.24 or later; with 
older versions they do not fail but give an empty body.
 
       Output: the body is the result as parsed JSON, a Map (or a List), not 
JSON text. Add `json-serialize-action` after it to get JSON text. The headers 
are kept.
 
-      Good to know: a Jackson `JsonNode`, such as the output of 
`json-deserialize-action`, is not read: the body becomes empty (null), with no 
error. Put `json-serialize-action` before it to give it JSON text. Text that is 
not a JSON object or array, such as `hello`, also gives an empty body. The 
specification cannot read headers, only the body. It is loaded from a file, the 
classpath or a URL given by the `template` option; it cannot come from the 
message. Headers that start with `Camel [...]
+      Good to know: text that is not a JSON object or array, such as `hello`, 
also gives an empty body. The specification cannot read headers, only the body. 
It is loaded from a file, the classpath or a URL given by the `template` 
option; it cannot come from the message. Headers that start with `CamelJolt` 
are removed from the message first, so they cannot change what the Kamelet does.
     required:
       - template
     type: object
diff --git 
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json 
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 8a17a7dce..a14b30a84 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -65,7 +65,7 @@
     "supportLevel" : "Stable",
     "title" : "AWS CloudWatch Metrics Sink",
     "summary" : "Sends one data point of a custom metric to Amazon CloudWatch 
for each message, with the name, the value and the unit of the metric taken 
from headers or options.",
-    "description" : "Sends one data point of a custom metric to Amazon 
CloudWatch for each message, with the name, the value and the unit of the 
metric taken from headers or options.\n\nUse it to record business or technical 
numbers from an integration, such as orders processed, items in stock or 
processing time, and to graph them or set alarms on them in 
CloudWatch.\n\nInput: the data point comes from the headers and options, and 
the body, such as text or a Map, is not used, unless it i [...]
+    "description" : "Sends one data point of a custom metric to Amazon 
CloudWatch for each message, with the name, the value and the unit of the 
metric taken from headers or options.\n\nUse it to record business or technical 
numbers from an integration, such as orders processed, items in stock or 
processing time, and to graph them or set alarms on them in 
CloudWatch.\n\nInput: the data point comes from the headers and options, and 
the body, such as text or a Map, is not used, unless it i [...]
     "group" : "AWS Cloudwatch",
     "namespace" : "AWS",
     "provider" : "Apache Software Foundation"
@@ -1235,7 +1235,7 @@
     "supportLevel" : "Stable",
     "title" : "Jolt Transformation Action",
     "summary" : "Reshapes each JSON message into other JSON, as a Jolt 
specification describes: moves, renames, removes fields or adds defaults.",
-    "description" : "Reshapes each JSON message into other JSON, as a Jolt 
specification describes: moves, renames, removes fields or adds 
defaults.\n\nUse it to map the JSON of one system to the JSON another system 
expects, for example to rename fields or move them into a nested object, when 
you already have Jolt specifications. `jslt-action` does the same with a query 
language, and is often easier to write.\n\nInput: parsed JSON as a Map (or a 
List), or a JSON object or array as text,  [...]
+    "description" : "Reshapes each JSON message into other JSON, as a Jolt 
specification describes: moves, renames, removes fields or adds 
defaults.\n\nUse it to map the JSON of one system to the JSON another system 
expects, for example to rename fields or move them into a nested object, when 
you already have Jolt specifications. `jslt-action` does the same with a query 
language, and is often easier to write.\n\nInput: parsed JSON as a Map (or a 
List), a Jackson `JsonNode` such as the ou [...]
     "group" : "Actions",
     "namespace" : "Transformation",
     "provider" : "Apache Software Foundation"
diff --git 
a/library/camel-kamelets/src/main/resources/kamelets/aws-cloudwatch-sink.kamelet.yaml
 
b/library/camel-kamelets/src/main/resources/kamelets/aws-cloudwatch-sink.kamelet.yaml
index e7fd86dab..4523b5a31 100644
--- 
a/library/camel-kamelets/src/main/resources/kamelets/aws-cloudwatch-sink.kamelet.yaml
+++ 
b/library/camel-kamelets/src/main/resources/kamelets/aws-cloudwatch-sink.kamelet.yaml
@@ -37,7 +37,7 @@ spec:
 
       Use it to record business or technical numbers from an integration, such 
as orders processed, items in stock or processing time, and to graph them or 
set alarms on them in CloudWatch.
 
-      Input: the data point comes from the headers and options, and the body, 
such as text or a Map, is not used, unless it is a List, an array or a 
`MetricDatum`. The `metric-name` header (or `ce-metricname`) is the name of the 
metric; it is required unless the `metricName` option is set. The optional 
`metric-value` header (or `ce-metricvalue`) is the value, a number; when it is 
not set, the value is `metricValue`, or 1. The optional `metric-unit` header 
(or `ce-metricunit`) is the unit [...]
+      Input: the data point comes from the headers and options, and the body, 
such as text or a Map, is not used, unless it is a List, an array or a 
`MetricDatum`. The `metric-name` header (or `ce-metricname`) is the name of the 
metric; it is required unless the `metricName` option is set. The optional 
`metric-value` header (or `ce-metricvalue`) is the value, a number; when it is 
not set, the value is `metricValue`, or 1. The optional `metric-unit` header 
(or `ce-metricunit`) is the unit [...]
 
       Output: the message is unchanged.
 
diff --git 
a/library/camel-kamelets/src/main/resources/kamelets/jolt-transformation-action.kamelet.yaml
 
b/library/camel-kamelets/src/main/resources/kamelets/jolt-transformation-action.kamelet.yaml
index 1cbb3ed4f..41ef31ae3 100644
--- 
a/library/camel-kamelets/src/main/resources/kamelets/jolt-transformation-action.kamelet.yaml
+++ 
b/library/camel-kamelets/src/main/resources/kamelets/jolt-transformation-action.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
 
       Use it to map the JSON of one system to the JSON another system expects, 
for example to rename fields or move them into a nested object, when you 
already have Jolt specifications. `jslt-action` does the same with a query 
language, and is often easier to write.
 
-      Input: parsed JSON as a Map (or a List), or a JSON object or array as 
text, bytes or a stream. JSON text, bytes and a stream need Camel 4.24 or 
later; with older versions they do not fail but give an empty body.
+      Input: parsed JSON as a Map (or a List), a Jackson `JsonNode` such as 
the output of `json-deserialize-action`, or a JSON object or array as text, 
bytes or a stream. JSON text, bytes and a stream need Camel 4.24 or later; with 
older versions they do not fail but give an empty body.
 
       Output: the body is the result as parsed JSON, a Map (or a List), not 
JSON text. Add `json-serialize-action` after it to get JSON text. The headers 
are kept.
 
-      Good to know: a Jackson `JsonNode`, such as the output of 
`json-deserialize-action`, is not read: the body becomes empty (null), with no 
error. Put `json-serialize-action` before it to give it JSON text. Text that is 
not a JSON object or array, such as `hello`, also gives an empty body. The 
specification cannot read headers, only the body. It is loaded from a file, the 
classpath or a URL given by the `template` option; it cannot come from the 
message. Headers that start with `Camel [...]
+      Good to know: text that is not a JSON object or array, such as `hello`, 
also gives an empty body. The specification cannot read headers, only the body. 
It is loaded from a file, the classpath or a URL given by the `template` 
option; it cannot come from the message. Headers that start with `CamelJolt` 
are removed from the message first, so they cannot change what the Kamelet does.
     required:
       - template
     type: object
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/aws/cloudwatch/aws-cloudwatch-sink-body-route.citrus.it.yaml
 
b/tests/camel-kamelets-itest/src/test/resources/aws/cloudwatch/aws-cloudwatch-sink-body-route.citrus.it.yaml
index 096c40aab..e46a130a2 100644
--- 
a/tests/camel-kamelets-itest/src/test/resources/aws/cloudwatch/aws-cloudwatch-sink-body-route.citrus.it.yaml
+++ 
b/tests/camel-kamelets-itest/src/test/resources/aws/cloudwatch/aws-cloudwatch-sink-body-route.citrus.it.yaml
@@ -17,7 +17,7 @@
 
 
 name: aws-cloudwatch-sink-body-route-test
-# A MetricDatum body, or a List of them, is sent as it is; a List of anything 
else fails the message
+# A MetricDatum body, or a List of them, is sent as it is; a List of anything 
else, or an empty one, fails the message
 variables:
   - name: "cw.start"
     value: 'citrus:currentDate(''yyyy-MM-dd'', ''-1d'')'
@@ -115,6 +115,28 @@ actions:
           body:
             data: "OK"
 
+  # The empty List failed the message, before calling CloudWatch
+  - http:
+      server: "awsSinkServer"
+      receiveRequest:
+        POST:
+          path: "/empty"
+          type: "plaintext"
+          headers:
+            - name: "X-Error"
+              value: 'java.lang.IllegalArgumentException: The body is an empty 
collection: there is no MetricDatum to put'
+          body:
+            data: 'empty'
+  - http:
+      server: "awsSinkServer"
+      sendResponse:
+        response:
+          status: 200
+          reasonPhrase: "OK"
+          version: "HTTP/1.1"
+          body:
+            data: "OK"
+
   # The data point of the MetricDatum is in CloudWatch, with its value and unit
   - http:
       client: "${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}"
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/aws/cloudwatch/aws-cloudwatch-sink-body-route.yaml
 
b/tests/camel-kamelets-itest/src/test/resources/aws/cloudwatch/aws-cloudwatch-sink-body-route.yaml
index 51431646d..176cee141 100644
--- 
a/tests/camel-kamelets-itest/src/test/resources/aws/cloudwatch/aws-cloudwatch-sink-body-route.yaml
+++ 
b/tests/camel-kamelets-itest/src/test/resources/aws/cloudwatch/aws-cloudwatch-sink-body-route.yaml
@@ -94,3 +94,34 @@
             constant: 'failed'
         - to:
             uri: "{{http.sink.url}}/error"
+
+        # An empty List fails the message too, and puts no data point
+        - removeHeaders:
+            pattern: "X-*"
+        - setBody:
+            groovy: '[]'
+        - doTry:
+            steps:
+              - to:
+                  uri: "kamelet:aws-cloudwatch-sink"
+                  parameters:
+                    cwNamespace: "ShopBody"
+                    accessKey: "{{cw.accessKey}}"
+                    secretKey: "{{cw.secretKey}}"
+                    region: "{{cw.awsRegion}}"
+                    overrideEndpoint: "true"
+                    uriEndpointOverride: "{{cw.endpoint}}"
+              - setHeader:
+                  name: X-Error
+                  constant: 'none'
+            doCatch:
+              - exception:
+                  - "java.lang.Exception"
+                steps:
+                  - setHeader:
+                      name: X-Error
+                      simple: "${exception.class.name}: ${exception.message}"
+        - setBody:
+            constant: 'empty'
+        - to:
+            uri: "{{http.sink.url}}/empty"
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/google/google-storage-sink-storage-class-route.citrus.it.yaml
 
b/tests/camel-kamelets-itest/src/test/resources/google/google-storage-sink-storage-class-route.citrus.it.yaml
index 5420e375f..db5130816 100644
--- 
a/tests/camel-kamelets-itest/src/test/resources/google/google-storage-sink-storage-class-route.citrus.it.yaml
+++ 
b/tests/camel-kamelets-itest/src/test/resources/google/google-storage-sink-storage-class-route.citrus.it.yaml
@@ -80,7 +80,7 @@ actions:
             - name: "X-Body-Type"
               value: 'com.google.cloud.storage.Blob'
             - name: "X-Content-Type"
-              value: 'ct='
+              value: 'ct=application/octet-stream'
             - name: "X-Storage-Class"
               value: 'COLDLINE'
             - name: "X-Object-Name"
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/google/google-storage-sink-storage-class-route.yaml
 
b/tests/camel-kamelets-itest/src/test/resources/google/google-storage-sink-storage-class-route.yaml
index 1467bfb2e..c09903900 100644
--- 
a/tests/camel-kamelets-itest/src/test/resources/google/google-storage-sink-storage-class-route.yaml
+++ 
b/tests/camel-kamelets-itest/src/test/resources/google/google-storage-sink-storage-class-route.yaml
@@ -39,6 +39,9 @@
         - setHeader:
             name: X-Content-Type
             simple: "ct=${header.Content-Type}"
+        # the HTTP server reads an application/octet-stream body as bytes: 
send the body as text
+        - removeHeader:
+            name: Content-Type
         - setHeader:
             name: X-Storage-Class
             simple: "${body.getStorageClass()}"
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/transformation/jolt-transformation-action-route.citrus.it.yaml
 
b/tests/camel-kamelets-itest/src/test/resources/transformation/jolt-transformation-action-route.citrus.it.yaml
index 40c4877e2..f845f0c1c 100644
--- 
a/tests/camel-kamelets-itest/src/test/resources/transformation/jolt-transformation-action-route.citrus.it.yaml
+++ 
b/tests/camel-kamelets-itest/src/test/resources/transformation/jolt-transformation-action-route.citrus.it.yaml
@@ -50,32 +50,12 @@ actions:
           reasonPhrase: "OK"
           version: "HTTP/1.1"
 
-  # A JsonNode gives an empty body
+  # A JsonNode is transformed like the same JSON as text
   - http:
       server: "httpServer"
       receiveRequest:
         POST:
           path: "/json-node"
-          type: "plaintext"
-          headers:
-            - name: "X-Body-Null"
-              value: 'true'
-          body:
-            data: ''
-  - http:
-      server: "httpServer"
-      sendResponse:
-        response:
-          status: 200
-          reasonPhrase: "OK"
-          version: "HTTP/1.1"
-
-  # The same JsonNode, turned into JSON text first, is transformed
-  - http:
-      server: "httpServer"
-      receiveRequest:
-        POST:
-          path: "/json-node-serialized"
           headers:
             - name: "X-Body-Type"
               value: 'java.util.LinkedHashMap'
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/transformation/jolt-transformation-action-route.yaml
 
b/tests/camel-kamelets-itest/src/test/resources/transformation/jolt-transformation-action-route.yaml
index 82db865fb..75e001301 100644
--- 
a/tests/camel-kamelets-itest/src/test/resources/transformation/jolt-transformation-action-route.yaml
+++ 
b/tests/camel-kamelets-itest/src/test/resources/transformation/jolt-transformation-action-route.yaml
@@ -40,7 +40,7 @@
         - to:
             uri: "{{http.sink.url}}/result"
 
-        # A Jackson JsonNode is not read: the body becomes empty (null), with 
no error
+        # A Jackson JsonNode, such as the output of json-deserialize-action, 
is transformed too
         - removeHeaders:
             pattern: "*"
         - setBody:
@@ -51,33 +51,10 @@
             uri: "kamelet:jolt-transformation-action"
             parameters:
               template: 'classpath:order-jolt.json'
-        - setHeader:
-            name: X-Body-Null
-            groovy: "body == null"
-        # without a body the HTTP call would be a GET
-        - setHeader:
-            name: CamelHttpMethod
-            constant: POST
-        - to:
-            uri: "{{http.sink.url}}/json-node"
-
-        # With json-serialize-action before it, the JsonNode is read as JSON 
text
-        - removeHeaders:
-            pattern: "*"
-        - setBody:
-            constant: '{"name":"Ann","items":[{"price":2},{"price":3}]}'
-        - to:
-            uri: "kamelet:json-deserialize-action"
-        - to:
-            uri: "kamelet:json-serialize-action"
-        - to:
-            uri: "kamelet:jolt-transformation-action"
-            parameters:
-              template: 'classpath:order-jolt.json'
         - setHeader:
             name: X-Body-Type
             simple: "${body.getClass().getName()}"
         - to:
             uri: "kamelet:json-serialize-action"
         - to:
-            uri: "{{http.sink.url}}/json-node-serialized"
+            uri: "{{http.sink.url}}/json-node"

Reply via email to