You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cd...@apache.org on 2023/09/18 07:35:10 UTC
[camel-kamelets] branch main updated: Enhance insert-field-action.kamelet
This is an automated email from the ASF dual-hosted git repository.
cdeppisch 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 83114632 Enhance insert-field-action.kamelet
83114632 is described below
commit 831146328a3ac5b60a883e730be485c3dbd77a1f
Author: Christoph Deppisch <cd...@redhat.com>
AuthorDate: Fri Sep 15 20:32:44 2023 +0200
Enhance insert-field-action.kamelet
- Support simple language parsed value
- Minor typo fix
---
kamelets/insert-field-action.kamelet.yaml | 2 +-
.../apache/camel/kamelets/utils/transform/InsertField.java | 14 +++++++++++---
.../resources/kamelets/insert-field-action.kamelet.yaml | 2 +-
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/kamelets/insert-field-action.kamelet.yaml b/kamelets/insert-field-action.kamelet.yaml
index 516a7319..8d273014 100644
--- a/kamelets/insert-field-action.kamelet.yaml
+++ b/kamelets/insert-field-action.kamelet.yaml
@@ -33,7 +33,7 @@ spec:
description: |-
Adds a custom field with a simple language parsed value to the message in transit.
- The extract field action expected an application/json content type.
+ The insert field action expected an application/json content type.
If for example you have an array like '{ "foo":"John", "bar":30 }' and your action has been configured with field as 'element' and value as 'hello', you'll get '{ "foo":"John", "bar":30, "element":"hello" }'
required:
diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/InsertField.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/InsertField.java
index 20b25085..f7a491be 100644
--- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/InsertField.java
+++ b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/InsertField.java
@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
import org.apache.camel.Processor;
+import org.apache.camel.support.LanguageSupport;
public class InsertField implements Processor {
@@ -51,15 +52,22 @@ public class InsertField implements Processor {
throw new InvalidPayloadException(ex, JsonNode.class);
}
+ String resolvedValue;
+ if (LanguageSupport.hasSimpleFunction(value)) {
+ resolvedValue = ex.getContext().resolveLanguage("simple").createExpression(value).evaluate(ex, String.class);
+ } else {
+ resolvedValue = value;
+ }
+
switch (body.getNodeType()) {
case ARRAY:
- ((ArrayNode) body).add(value);
+ ((ArrayNode) body).add(resolvedValue);
break;
case OBJECT:
- ((ObjectNode) body).put(field, value);
+ ((ObjectNode) body).put(field, resolvedValue);
break;
default:
- ((ObjectNode) body).put(field, value);
+ ((ObjectNode) body).put(field, resolvedValue);
break;
}
diff --git a/library/camel-kamelets/src/main/resources/kamelets/insert-field-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/insert-field-action.kamelet.yaml
index 516a7319..8d273014 100644
--- a/library/camel-kamelets/src/main/resources/kamelets/insert-field-action.kamelet.yaml
+++ b/library/camel-kamelets/src/main/resources/kamelets/insert-field-action.kamelet.yaml
@@ -33,7 +33,7 @@ spec:
description: |-
Adds a custom field with a simple language parsed value to the message in transit.
- The extract field action expected an application/json content type.
+ The insert field action expected an application/json content type.
If for example you have an array like '{ "foo":"John", "bar":30 }' and your action has been configured with field as 'element' and value as 'hello', you'll get '{ "foo":"John", "bar":30, "element":"hello" }'
required: