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.git


The following commit(s) were added to refs/heads/main by this push:
     new c15cdbd6f4c Add cloud event 1.0.2 spec
c15cdbd6f4c is described below

commit c15cdbd6f4c2cd9b5658eb78ccb72acb7ec6ac03
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Feb 23 20:00:40 2024 +0100

    Add cloud event 1.0.2 spec
---
 .../apache/camel/component/knative/knative.json    |  4 +--
 .../component/knative/KnativeConfiguration.java    |  2 +-
 .../component/knative/ce/CloudEventProcessors.java | 29 +++++++++++++++++++++-
 .../component/knative/http/KnativeHttpTest.java    |  3 ++-
 4 files changed, 33 insertions(+), 5 deletions(-)

diff --git 
a/components/camel-knative/camel-knative-component/src/generated/resources/org/apache/camel/component/knative/knative.json
 
b/components/camel-knative/camel-knative-component/src/generated/resources/org/apache/camel/component/knative/knative.json
index 6b5b5ed1cc7..2f6c7f376b2 100644
--- 
a/components/camel-knative/camel-knative-component/src/generated/resources/org/apache/camel/component/knative/knative.json
+++ 
b/components/camel-knative/camel-knative-component/src/generated/resources/org/apache/camel/component/knative/knative.json
@@ -24,7 +24,7 @@
   },
   "componentProperties": {
     "ceOverride": { "index": 0, "kind": "property", "displayName": "Ce 
Override", "group": "common", "label": "", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.String, java.lang.String>", "prefix": 
"ce.override.", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "CloudEvent headers to 
override" },
-    "cloudEventsSpecVersion": { "index": 1, "kind": "property", "displayName": 
"Cloud Events Spec Version", "group": "common", "label": "", "required": false, 
"type": "string", "javaType": "java.lang.String", "enum": [ "1.0", "1.0.1" ], 
"deprecated": false, "autowired": false, "secret": false, "defaultValue": 
"1.0", "configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "Set the version of the 
cloudevents spec." },
+    "cloudEventsSpecVersion": { "index": 1, "kind": "property", "displayName": 
"Cloud Events Spec Version", "group": "common", "label": "", "required": false, 
"type": "string", "javaType": "java.lang.String", "enum": [ "1.0", "1.0.1", 
"1.0.2" ], "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": "1.0", "configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "Set the version of the 
cloude [...]
     "cloudEventsType": { "index": 2, "kind": "property", "displayName": "Cloud 
Events Type", "group": "common", "label": "", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "defaultValue": "org.apache.camel.event", 
"configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "Set the event-type 
information of the produced events." },
     "configuration": { "index": 3, "kind": "property", "displayName": 
"Configuration", "group": "common", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.knative.KnativeConfiguration", "deprecated": false, 
"autowired": false, "secret": false, "description": "Set the configuration." },
     "consumerFactory": { "index": 4, "kind": "property", "displayName": 
"Consumer Factory", "group": "common", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.knative.spi.KnativeConsumerFactory", "deprecated": 
false, "autowired": false, "secret": false, "description": "The protocol 
consumer factory." },
@@ -50,7 +50,7 @@
     "type": { "index": 0, "kind": "path", "displayName": "Type", "group": 
"common", "label": "", "required": false, "type": "object", "javaType": 
"org.apache.camel.component.knative.spi.Knative.Type", "enum": [ "endpoint", 
"channel", "event" ], "deprecated": false, "autowired": false, "secret": false, 
"description": "The Knative resource type" },
     "typeId": { "index": 1, "kind": "path", "displayName": "Type Id", "group": 
"common", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The identifier of the Knative resource" },
     "ceOverride": { "index": 2, "kind": "parameter", "displayName": "Ce 
Override", "group": "common", "label": "", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.String, java.lang.String>", "prefix": 
"ce.override.", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "CloudEvent headers to 
override" },
-    "cloudEventsSpecVersion": { "index": 3, "kind": "parameter", 
"displayName": "Cloud Events Spec Version", "group": "common", "label": "", 
"required": false, "type": "string", "javaType": "java.lang.String", "enum": [ 
"1.0", "1.0.1" ], "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": "1.0", "configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "Set the version of the 
cloudevents spec." },
+    "cloudEventsSpecVersion": { "index": 3, "kind": "parameter", 
"displayName": "Cloud Events Spec Version", "group": "common", "label": "", 
"required": false, "type": "string", "javaType": "java.lang.String", "enum": [ 
"1.0", "1.0.1", "1.0.2" ], "deprecated": false, "autowired": false, "secret": 
false, "defaultValue": "1.0", "configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "Set the version of the 
cloud [...]
     "cloudEventsType": { "index": 4, "kind": "parameter", "displayName": 
"Cloud Events Type", "group": "common", "label": "", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "defaultValue": "org.apache.camel.event", 
"configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "Set the event-type 
information of the produced events." },
     "environment": { "index": 5, "kind": "parameter", "displayName": 
"Environment", "group": "common", "label": "", "required": false, "type": 
"object", "javaType": 
"org.apache.camel.component.knative.spi.KnativeEnvironment", "deprecated": 
false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "The environment" },
     "filters": { "index": 6, "kind": "parameter", "displayName": "Filters", 
"group": "common", "label": "", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.String, java.lang.String>", "prefix": 
"filter.", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.knative.KnativeConfiguration", 
"configurationField": "configuration", "description": "Set the filters." },
diff --git 
a/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java
 
b/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java
index 8b1d3d7b96d..f9a86aea21f 100644
--- 
a/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java
+++ 
b/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java
@@ -34,7 +34,7 @@ public class KnativeConfiguration implements Cloneable {
     private KnativeSinkBinding sinkBinding;
     @UriParam
     private String typeId;
-    @UriParam(defaultValue = "1.0", enums = "1.0,1.0.1")
+    @UriParam(defaultValue = "1.0", enums = "1.0,1.0.1,1.0.2")
     private String cloudEventsSpecVersion = CloudEvents.v1_0.version();
     @UriParam(defaultValue = "org.apache.camel.event")
     private String cloudEventsType = "org.apache.camel.event";
diff --git 
a/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/ce/CloudEventProcessors.java
 
b/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/ce/CloudEventProcessors.java
index 10dfff88007..b909da37ef0 100644
--- 
a/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/ce/CloudEventProcessors.java
+++ 
b/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/ce/CloudEventProcessors.java
@@ -85,6 +85,33 @@ public enum CloudEventProcessors implements 
CloudEventProcessor {
                 message.setHeader(key.toLowerCase(Locale.US), val);
             });
         }
+    }),
+    v1_0_2(new AbstractCloudEventProcessor(CloudEvents.v1_0_2) {
+        @Override
+        protected void decodeStructuredContent(Exchange exchange, Map<String, 
Object> content) {
+            final CloudEvent ce = cloudEvent();
+            final Message message = exchange.getIn();
+
+            // body
+            ifNotEmpty(content.remove("data"), message::setBody);
+
+            
ifNotEmpty(content.remove(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_DATA_CONTENT_TYPE).json()),
 val -> {
+                message.setHeader(Exchange.CONTENT_TYPE, val);
+            });
+
+            for (CloudEvent.Attribute attribute : ce.attributes()) {
+                ifNotEmpty(content.remove(attribute.json()), val -> {
+                    message.setHeader(attribute.id(), val);
+                });
+            }
+
+            //
+            // Map every remaining field as it is (extensions).
+            //
+            content.forEach((key, val) -> {
+                message.setHeader(key.toLowerCase(Locale.US), val);
+            });
+        }
     });
 
     private final CloudEventProcessor instance;
@@ -115,6 +142,6 @@ public enum CloudEventProcessors implements 
CloudEventProcessor {
             }
         }
 
-        throw new IllegalArgumentException("Unable to find an implementation 
fo CloudEvents spec: " + version);
+        throw new IllegalArgumentException("Unable to find an implementation 
for CloudEvents spec: " + version);
     }
 }
diff --git 
a/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java
 
b/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java
index f13821d2832..e5e5b20bbed 100644
--- 
a/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java
+++ 
b/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java
@@ -344,7 +344,8 @@ public class KnativeHttpTest {
         mock.expectedMessageCount(1);
 
         if (Objects.equals(CloudEvents.v1_0.version(), ce.version())
-                || Objects.equals(CloudEvents.v1_0_1.version(), ce.version())) 
{
+                || Objects.equals(CloudEvents.v1_0_1.version(), ce.version())
+                || Objects.equals(CloudEvents.v1_0_2.version(), ce.version())) 
{
             given()
                     .contentType(Knative.MIME_STRUCTURED_CONTENT_MODE)
                     .body(

Reply via email to