ReggieCarey commented on a change in pull request #681:
URL: https://github.com/apache/camel-kamelets/pull/681#discussion_r780363207



##########
File path: kamelets/extract-field-action.kamelet.yaml
##########
@@ -29,14 +29,30 @@ metadata:
 spec:
   definition:
     title: "Extract Field Action"
-    description: "Extract a field from the body"
+    description: |-
+      Extract a field from the message body.
+
+      The extract field action expected an application/json content type. 

Review comment:
       The extract field action expects an application/json content type.

##########
File path: kamelets/extract-field-action.kamelet.yaml
##########
@@ -29,14 +29,30 @@ metadata:
 spec:
   definition:
     title: "Extract Field Action"
-    description: "Extract a field from the body"
+    description: |-
+      Extract a field from the message body.
+
+      The extract field action expected an application/json content type. 
+
+      The field parameter allows to specify which field of the json the user 
wants to extract. By default the message body will be overriden with the 
extracted field.

Review comment:
       The field parameter allows you to ...

##########
File path: 
library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java
##########
@@ -27,11 +27,16 @@
 
 public class ExtractField {
 
-    public void process(@ExchangeProperty("field") String field, Exchange ex) {
+    public void process(@ExchangeProperty("field") String field, 
@ExchangeProperty("headerOutput") boolean headerOutput, Exchange ex) {
+        final String EXTRACTED_FIELD_HEADER = "CamelKameletsExtractFieldName";
         ObjectMapper mapper = new ObjectMapper();
         JsonNode jsonNodeBody = ex.getMessage().getBody(JsonNode.class);
         Map<Object, Object> body = mapper.convertValue(jsonNodeBody, new 
TypeReference<Map<Object, Object>>(){});
-        ex.getMessage().setBody(body.get(field));
+        if (!headerOutput) {
+            ex.getMessage().setBody(body.get(field));
+        } else {
+            ex.getMessage().setHeader(EXTRACTED_FIELD_HEADER, body.get(field));

Review comment:
       As per my comments in the issue, maybe this is better in line 38?
   
   ex.getMessage.setHeader(sanitized(headerOutput), body.get(field));
   
   Where ```String sanitized(String headerOutput)``` does its best to ensure a 
valid headerName that does not collide with existing headers.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to