Skip to content

Commit

Permalink
Extract Field: Add a property to trim the field
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
  • Loading branch information
oscerd committed Mar 22, 2023
1 parent c1887e3 commit dc5539f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
29 changes: 21 additions & 8 deletions kamelets/extract-field-action.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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:
- "mvn:org.apache.camel.kamelets:camel-kamelets-utils:4.0.0-SNAPSHOT"
Expand All @@ -92,6 +99,8 @@ spec:
value: '{{headerOutputName}}'
- key: strictHeaderCheck
value: '{{strictHeaderCheck}}'
- key: trimField
value: '{{trimField}}'
from:
uri: kamelet:source
steps:
Expand All @@ -110,12 +119,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"
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ExtractField implements Processor {
String headerOutputName;
boolean headerOutput;
boolean strictHeaderCheck;
boolean trimField;

static final String EXTRACTED_FIELD_HEADER = "CamelKameletsExtractFieldName";

Expand Down Expand Up @@ -64,6 +65,11 @@ public void process(Exchange ex) throws InvalidPayloadException {
} else {
extractToHeader(ex, body);
}
if (trimField) {
ex.setProperty("trimField", "true");
} else {
ex.setProperty("trimField", "false");
}
}

private void extractToHeader(Exchange ex, Map<Object, Object> body) {
Expand Down Expand Up @@ -97,4 +103,8 @@ public void setHeaderOutputName(String headerOutputName) {
public void setStrictHeaderCheck(boolean strictHeaderCheck) {
this.strictHeaderCheck = strictHeaderCheck;
}

public void setTrimField(boolean trimField) {
this.trimField = trimField;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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:
- "mvn:org.apache.camel.kamelets:camel-kamelets-utils:4.0.0-SNAPSHOT"
Expand All @@ -92,6 +99,8 @@ spec:
value: '{{headerOutputName}}'
- key: strictHeaderCheck
value: '{{strictHeaderCheck}}'
- key: trimField
value: '{{trimField}}'
from:
uri: kamelet:source
steps:
Expand All @@ -110,12 +119,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"

0 comments on commit dc5539f

Please sign in to comment.