You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/09/22 01:48:36 UTC
[incubator-eventmesh] branch master updated: [ISSUE #1361] Update WebHookProtocolAdaptor for pub/sub
This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new b622e932 [ISSUE #1361] Update WebHookProtocolAdaptor for pub/sub
new 8365f07f Merge pull request #1362 from githublaohu/webhook-repair5
b622e932 is described below
commit b622e9321497f5346eaca168664f637bd22ac3c2
Author: githublaohu <Ni...@989898>
AuthorDate: Wed Sep 21 16:37:11 2022 +0800
[ISSUE #1361] Update WebHookProtocolAdaptor for pub/sub
---
.../protocol/webhook/WebHookProtocolAdaptor.java | 43 +++++++++++++++++-----
1 file changed, 34 insertions(+), 9 deletions(-)
diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/java/org/apache/eventmesh/protocol/webhook/WebHookProtocolAdaptor.java b/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/java/org/apache/eventmesh/protocol/webhook/WebHookProtocolAdaptor.java
index 6fb448ee..2a102ad6 100644
--- a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/java/org/apache/eventmesh/protocol/webhook/WebHookProtocolAdaptor.java
+++ b/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/java/org/apache/eventmesh/protocol/webhook/WebHookProtocolAdaptor.java
@@ -17,14 +17,20 @@
package org.apache.eventmesh.protocol.webhook;
+import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.common.protocol.ProtocolTransportObject;
+import org.apache.eventmesh.common.protocol.http.HttpEventWrapper;
import org.apache.eventmesh.common.protocol.http.WebhookProtocolTransportObject;
import org.apache.eventmesh.protocol.api.ProtocolAdaptor;
import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException;
+
import java.net.URI;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import io.cloudevents.CloudEvent;
import io.cloudevents.core.builder.CloudEventBuilder;
@@ -34,13 +40,14 @@ public class WebHookProtocolAdaptor implements ProtocolAdaptor<WebhookProtocolTr
@Override
public CloudEvent toCloudEvent(WebhookProtocolTransportObject protocol) throws ProtocolHandleException {
return CloudEventBuilder.v1()
- .withId(protocol.getCloudEventId())
- .withSubject(protocol.getCloudEventName())
- .withSource(URI.create(protocol.getCloudEventSource()))
- .withDataContentType(protocol.getDataContentType())
- .withType(protocol.getEventType())
- .withData(protocol.getBody())
- .build();
+ .withId(protocol.getCloudEventId())
+ .withSubject(protocol.getCloudEventName())
+ .withSource(URI.create(protocol.getCloudEventSource()))
+ .withDataContentType(protocol.getDataContentType())
+ .withType(protocol.getEventType())
+ .withData(protocol.getBody())
+ .withExtension(Constants.PROTOCOL_TYPE, "webhookProtocolAdaptor")
+ .build();
}
@Override
@@ -51,12 +58,30 @@ public class WebHookProtocolAdaptor implements ProtocolAdaptor<WebhookProtocolTr
@Override
public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
- return null;
+ final HttpEventWrapper httpEventWrapper = new HttpEventWrapper();
+ Map<String, Object> sysHeaderMap = new HashMap<>();
+ // ce attributes
+ Set<String> attributeNames = cloudEvent.getAttributeNames();
+ // ce extensions
+ Set<String> extensionNames = cloudEvent.getExtensionNames();
+ for (String attributeName : attributeNames) {
+ sysHeaderMap.put(attributeName, cloudEvent.getAttribute(attributeName));
+ }
+ for (String extensionName : extensionNames) {
+ sysHeaderMap.put(extensionName, cloudEvent.getExtension(extensionName));
+ }
+ sysHeaderMap.put("cloudEventId", cloudEvent.getId());
+ sysHeaderMap.put("cloudEventName", cloudEvent.getSubject());
+ sysHeaderMap.put("cloudEventSource", cloudEvent.getSource().toString());
+ sysHeaderMap.put("type", cloudEvent.getType());
+ httpEventWrapper.setSysHeaderMap(sysHeaderMap);
+ httpEventWrapper.setBody(cloudEvent.getData().toBytes());
+ return httpEventWrapper;
}
@Override
public String getProtocolType() {
- return "webhook";
+ return "webhookProtocolAdaptor";
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org