You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2023/03/22 10:43:52 UTC
[camel-kamelets] 01/01: Extract Field: Add a property to trim the field
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch 0.9.x-trimming-field
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
commit 85eea40e0050a59a3653dbc6a82179c256dd4a22
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 22 11:39:34 2023 +0100
Extract Field: Add a property to trim the field
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
kamelets/extract-field-action.kamelet.yaml | 29 ++++++++++++++++------
.../kamelets/utils/transform/ExtractField.java | 10 ++++++++
.../kamelets/extract-field-action.kamelet.yaml | 29 ++++++++++++++++------
3 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/kamelets/extract-field-action.kamelet.yaml b/kamelets/extract-field-action.kamelet.yaml
index afc71aeb..473474bb 100644
--- a/kamelets/extract-field-action.kamelet.yaml
+++ b/kamelets/extract-field-action.kamelet.yaml
@@ -70,6 +70,13 @@ spec:
default: false
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ trimField:
+ title: Trim Field
+ description: If enabled we return the Raw extracted field
+ type: boolean
+ default: false
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
type: object
dependencies:
- "github:apache.camel-kamelets:camel-kamelets-utils:0.9.5-SNAPSHOT"
@@ -91,6 +98,8 @@ spec:
value: '{{headerOutputName}}'
- key: strictHeaderCheck
value: '{{strictHeaderCheck}}'
+ - key: trimField
+ value: '{{trimField}}'
from:
uri: kamelet:source
steps:
@@ -109,12 +118,16 @@ spec:
ref: "{{extractField}}"
- choice:
when:
- - simple: "${exchangeProperty[deserialized]} == 'true'"
+ - simple: "${exchangeProperty[trimField]} == 'false'"
steps:
- - marshal:
- json:
- library: Jackson
- unmarshalType: com.fasterxml.jackson.databind.JsonNode
- - set-header:
- name: "Content-Type"
- constant: "application/json"
+ - choice:
+ when:
+ - simple: "${exchangeProperty[deserialized]} == 'true'"
+ steps:
+ - marshal:
+ json:
+ library: Jackson
+ unmarshalType: com.fasterxml.jackson.databind.JsonNode
+ - set-header:
+ name: "Content-Type"
+ constant: "application/json"
diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java
index 80ca041c..bdb636b5 100644
--- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java
+++ b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java
@@ -31,6 +31,7 @@ public class ExtractField implements Processor {
String headerOutputName;
boolean headerOutput;
boolean strictHeaderCheck;
+ boolean trimField;
static final String EXTRACTED_FIELD_HEADER = "CamelKameletsExtractFieldName";
@@ -64,6 +65,11 @@ public class ExtractField implements Processor {
} else {
extractToHeader(ex, body);
}
+ if (trimField) {
+ ex.setProperty("trimField", "true");
+ } else {
+ ex.setProperty("trimField", "false");
+ }
}
private void extractToHeader(Exchange ex, Map<Object, Object> body) {
@@ -97,4 +103,8 @@ public class ExtractField implements Processor {
public void setStrictHeaderCheck(boolean strictHeaderCheck) {
this.strictHeaderCheck = strictHeaderCheck;
}
+
+ public void setTrimField(boolean trimField) {
+ this.trimField = trimField;
+ }
}
diff --git a/library/camel-kamelets/src/main/resources/kamelets/extract-field-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/extract-field-action.kamelet.yaml
index afc71aeb..473474bb 100644
--- a/library/camel-kamelets/src/main/resources/kamelets/extract-field-action.kamelet.yaml
+++ b/library/camel-kamelets/src/main/resources/kamelets/extract-field-action.kamelet.yaml
@@ -70,6 +70,13 @@ spec:
default: false
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ trimField:
+ title: Trim Field
+ description: If enabled we return the Raw extracted field
+ type: boolean
+ default: false
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
type: object
dependencies:
- "github:apache.camel-kamelets:camel-kamelets-utils:0.9.5-SNAPSHOT"
@@ -91,6 +98,8 @@ spec:
value: '{{headerOutputName}}'
- key: strictHeaderCheck
value: '{{strictHeaderCheck}}'
+ - key: trimField
+ value: '{{trimField}}'
from:
uri: kamelet:source
steps:
@@ -109,12 +118,16 @@ spec:
ref: "{{extractField}}"
- choice:
when:
- - simple: "${exchangeProperty[deserialized]} == 'true'"
+ - simple: "${exchangeProperty[trimField]} == 'false'"
steps:
- - marshal:
- json:
- library: Jackson
- unmarshalType: com.fasterxml.jackson.databind.JsonNode
- - set-header:
- name: "Content-Type"
- constant: "application/json"
+ - choice:
+ when:
+ - simple: "${exchangeProperty[deserialized]} == 'true'"
+ steps:
+ - marshal:
+ json:
+ library: Jackson
+ unmarshalType: com.fasterxml.jackson.databind.JsonNode
+ - set-header:
+ name: "Content-Type"
+ constant: "application/json"