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/06 06:44:07 UTC

[incubator-eventmesh] 01/01: Revert "Extraction of constants grpc、JAVA and application/cloudevents+json."

This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch revert-1226-master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git

commit a43d93539fcae5067fd9606b5b545bcf6b3b3dcf
Author: mike_xwm <mi...@126.com>
AuthorDate: Tue Sep 6 14:44:00 2022 +0800

    Revert "Extraction of constants grpc、JAVA and application/cloudevents+json."
---
 .../src/main/java/org/apache/eventmesh/common/Constants.java | 12 +-----------
 .../org/apache/eventmesh/tcp/common/EventMeshTestUtils.java  |  2 +-
 .../protocol/cloudevents/CloudEventsProtocolAdaptor.java     |  2 +-
 .../resolver/grpc/GrpcMessageProtocolResolver.java           |  7 +++----
 .../protocol/meshmessage/MeshMessageProtocolAdaptor.java     |  2 +-
 .../resolver/grpc/GrpcMessageProtocolResolver.java           |  3 +--
 .../runtime/core/protocol/grpc/push/WebhookPushRequest.java  |  2 +-
 .../eventmesh/client/grpc/producer/CloudEventProducer.java   |  4 ++--
 .../eventmesh/client/grpc/util/EventMeshClientUtil.java      |  6 +++---
 .../eventmesh/client/grpc/util/EventMeshClientUtilTest.java  |  2 +-
 10 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/Constants.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/Constants.java
index ba594d61..faf82275 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/Constants.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/Constants.java
@@ -154,14 +154,4 @@ public class Constants {
     public static final String AND = "&";
 
     public static final String EMPTY = "";
-
-    /**
-     * GRPC PROTOCOL
-     */
-    public static final String PROTOCOL_GRPC = "grpc";
-
-    /**
-     * application/cloudevents+json Content-type
-     */
-    public static final String CONTENT_TYPE_CLOUDEVENTS_JSON = "application/cloudevents+json";
-}
\ No newline at end of file
+}
diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java
index b0631e92..db3182a4 100644
--- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java
+++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java
@@ -171,7 +171,7 @@ public class EventMeshTestUtils {
                 .withId(UUID.randomUUID().toString())
                 .withSubject(ExampleConstants.EVENTMESH_TCP_ASYNC_TEST_TOPIC)
                 .withSource(URI.create("/"))
-                .withDataContentType(ExampleConstants.CLOUDEVENT_CONTENT_TYPE)
+                .withDataContentType("application/cloudevents+json")
                 .withType(EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME)
                 .withData(JsonUtils.serialize(content).getBytes(StandardCharsets.UTF_8))
                 .withExtension("ttl", "30000")
diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
index c75cbaa0..5763e60e 100644
--- a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
+++ b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
@@ -143,7 +143,7 @@ public class CloudEventsProtocolAdaptor<T extends ProtocolTransportObject>
                 String.format("DateContentType:%s is not supported", dataContentType));
             pkg.setBody(eventFormat.serialize(cloudEvent));
             return pkg;
-        } else if (StringUtils.equals(Constants.PROTOCOL_GRPC, protocolDesc)) {
+        } else if (StringUtils.equals("grpc", protocolDesc)) {
             return GrpcMessageProtocolResolver.buildSimpleMessage(cloudEvent);
         } else {
             throw new ProtocolHandleException(String.format("Unsupported protocolDesc: %s", protocolDesc));
diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/grpc/GrpcMessageProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/grpc/GrpcMessageProtocolResolver.java
index e75b57e1..6424c724 100644
--- a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/grpc/GrpcMessageProtocolResolver.java
+++ b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/grpc/GrpcMessageProtocolResolver.java
@@ -17,7 +17,6 @@
 
 package org.apache.eventmesh.protocol.cloudevents.resolver.grpc;
 
-import org.apache.eventmesh.common.Constants;
 import org.apache.eventmesh.common.protocol.grpc.common.ProtocolKey;
 import org.apache.eventmesh.common.protocol.grpc.common.SimpleMessageWrapper;
 import org.apache.eventmesh.common.protocol.grpc.protos.BatchMessage;
@@ -41,7 +40,7 @@ public class GrpcMessageProtocolResolver {
     public static CloudEvent buildEvent(SimpleMessage message) {
         String cloudEventJson = message.getContent();
 
-        String contentType = message.getPropertiesOrDefault(ProtocolKey.CONTENT_TYPE, Constants.CONTENT_TYPE_CLOUDEVENTS_JSON);
+        String contentType = message.getPropertiesOrDefault(ProtocolKey.CONTENT_TYPE, "application/cloudevents+json");
         EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(contentType);
         CloudEvent event = eventFormat.deserialize(cloudEventJson.getBytes(StandardCharsets.UTF_8));
 
@@ -116,7 +115,7 @@ public class GrpcMessageProtocolResolver {
         String sys = cloudEvent.getExtension(ProtocolKey.SYS) == null ? "sys123" : cloudEvent.getExtension(ProtocolKey.SYS).toString();
         String userName = cloudEvent.getExtension(ProtocolKey.USERNAME) == null ? "user" : cloudEvent.getExtension(ProtocolKey.USERNAME).toString();
         String passwd = cloudEvent.getExtension(ProtocolKey.PASSWD) == null ? "pass" : cloudEvent.getExtension(ProtocolKey.PASSWD).toString();
-        String language = cloudEvent.getExtension(ProtocolKey.LANGUAGE) == null ? Constants.LANGUAGE_JAVA : cloudEvent.getExtension(ProtocolKey.LANGUAGE).toString();
+        String language = cloudEvent.getExtension(ProtocolKey.LANGUAGE) == null ? "JAVA" : cloudEvent.getExtension(ProtocolKey.LANGUAGE).toString();
         String protocol = cloudEvent.getExtension(ProtocolKey.PROTOCOL_TYPE) == null ? "protocol" :
             cloudEvent.getExtension(ProtocolKey.PROTOCOL_TYPE).toString();
         String protocolDesc = cloudEvent.getExtension(ProtocolKey.PROTOCOL_DESC) == null ? "protocolDesc" :
@@ -167,7 +166,7 @@ public class GrpcMessageProtocolResolver {
         for (BatchMessage.MessageItem item : batchMessage.getMessageItemList()) {
             String cloudEventJson = item.getContent();
 
-            String contentType = item.getPropertiesOrDefault(ProtocolKey.CONTENT_TYPE, Constants.CONTENT_TYPE_CLOUDEVENTS_JSON);
+            String contentType = item.getPropertiesOrDefault(ProtocolKey.CONTENT_TYPE, "application/cloudevents+json");
             EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(contentType);
             CloudEvent event = eventFormat.deserialize(cloudEventJson.getBytes(StandardCharsets.UTF_8));
 
diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java
index 26a390d2..df60c396 100644
--- a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java
+++ b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java
@@ -127,7 +127,7 @@ public class MeshMessageProtocolAdaptor implements ProtocolAdaptor<ProtocolTrans
             body.toMap();
             httpCommand.setBody(body);
             return httpCommand;
-        } else if (StringUtils.equals(Constants.PROTOCOL_GRPC, protocolDesc)) {
+        } else if (StringUtils.equals("grpc", protocolDesc)) {
             return GrpcMessageProtocolResolver.buildSimpleMessage(cloudEvent);
         } else if (StringUtils.equals("tcp", protocolDesc)) {
             return TcpMessageProtocolResolver.buildEventMeshMessage(cloudEvent);
diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/grpc/GrpcMessageProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/grpc/GrpcMessageProtocolResolver.java
index bc74785c..47b4278c 100644
--- a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/grpc/GrpcMessageProtocolResolver.java
+++ b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/grpc/GrpcMessageProtocolResolver.java
@@ -17,7 +17,6 @@
 
 package org.apache.eventmesh.protocol.meshmessage.resolver.grpc;
 
-import org.apache.eventmesh.common.Constants;
 import org.apache.eventmesh.common.protocol.grpc.common.ProtocolKey;
 import org.apache.eventmesh.common.protocol.grpc.common.SimpleMessageWrapper;
 import org.apache.eventmesh.common.protocol.grpc.protos.BatchMessage;
@@ -228,7 +227,7 @@ public class GrpcMessageProtocolResolver {
         String sys = cloudEvent.getExtension(ProtocolKey.SYS) == null ? "sys" : cloudEvent.getExtension(ProtocolKey.SYS).toString();
         String userName = cloudEvent.getExtension(ProtocolKey.USERNAME) == null ? "user" : cloudEvent.getExtension(ProtocolKey.USERNAME).toString();
         String passwd = cloudEvent.getExtension(ProtocolKey.PASSWD) == null ? "pass" : cloudEvent.getExtension(ProtocolKey.PASSWD).toString();
-        String language = cloudEvent.getExtension(ProtocolKey.LANGUAGE) == null ? Constants.LANGUAGE_JAVA : cloudEvent.getExtension(ProtocolKey.LANGUAGE).toString();
+        String language = cloudEvent.getExtension(ProtocolKey.LANGUAGE) == null ? "JAVA" : cloudEvent.getExtension(ProtocolKey.LANGUAGE).toString();
         String protocol = cloudEvent.getExtension(ProtocolKey.PROTOCOL_TYPE) == null ? "" :
             cloudEvent.getExtension(ProtocolKey.PROTOCOL_TYPE).toString();
         String protocolDesc = cloudEvent.getExtension(ProtocolKey.PROTOCOL_DESC) == null ? "" :
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/WebhookPushRequest.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/WebhookPushRequest.java
index a27864bd..f5d6bcf0 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/WebhookPushRequest.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/WebhookPushRequest.java
@@ -116,7 +116,7 @@ public class WebhookPushRequest extends AbstractPushRequest {
             builder.addHeader(ProtocolKey.PROTOCOL_DESC, requestHeader.getProtocolDesc());
             builder.addHeader(ProtocolKey.PROTOCOL_VERSION, requestHeader.getProtocolVersion());
             builder.addHeader(ProtocolKey.CONTENT_TYPE, simpleMessage.getPropertiesOrDefault(ProtocolKey.CONTENT_TYPE,
-                Constants.CONTENT_TYPE_CLOUDEVENTS_JSON));
+                    "application/cloudevents+json"));
 
             List<NameValuePair> body = new ArrayList<>();
             body.add(new BasicNameValuePair(PushMessageRequestBody.CONTENT, simpleMessage.getContent()));
diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java
index fc6297e0..99118f1d 100644
--- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java
+++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java
@@ -118,9 +118,9 @@ public class CloudEventProducer {
             .withExtension(ProtocolKey.IP, IPUtils.getLocalAddress())
             .withExtension(ProtocolKey.PID, Long.toString(ThreadUtils.getPID()))
             .withExtension(ProtocolKey.SYS, clientConfig.getSys())
-            .withExtension(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA)
+            .withExtension(ProtocolKey.LANGUAGE, "JAVA")
             .withExtension(ProtocolKey.PROTOCOL_TYPE, PROTOCOL_TYPE)
-            .withExtension(ProtocolKey.PROTOCOL_DESC, Constants.PROTOCOL_GRPC)
+            .withExtension(ProtocolKey.PROTOCOL_DESC, "grpc")
             .withExtension(ProtocolKey.PROTOCOL_VERSION, cloudEvent.getSpecVersion().toString())
             .withExtension(ProtocolKey.UNIQUE_ID, RandomStringUtils.generateNum(30))
             .withExtension(ProtocolKey.SEQ_NUM, RandomStringUtils.generateNum(30))
diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshClientUtil.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshClientUtil.java
index 2bce7570..71b0e2aa 100644
--- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshClientUtil.java
+++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshClientUtil.java
@@ -64,7 +64,7 @@ public class EventMeshClientUtil {
             .setUsername(clientConfig.getUserName())
             .setPassword(clientConfig.getPassword())
             .setProtocolType(protocolType)
-            .setProtocolDesc(Constants.PROTOCOL_GRPC)
+            .setProtocolDesc("grpc")
             // default CloudEvents version is V1
             .setProtocolVersion(SpecVersion.V1.toString())
             .build();
@@ -117,7 +117,7 @@ public class EventMeshClientUtil {
                                                        String protocolType) {
         if (EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME.equals(protocolType)) {
             CloudEvent cloudEvent = (CloudEvent) message;
-            String contentType = StringUtils.isEmpty(cloudEvent.getDataContentType()) ? Constants.CONTENT_TYPE_CLOUDEVENTS_JSON
+            String contentType = StringUtils.isEmpty(cloudEvent.getDataContentType()) ? "application/cloudevents+json"
                 : cloudEvent.getDataContentType();
             byte[] bodyByte = EventFormatProvider.getInstance().resolveFormat(contentType)
                 .serialize(cloudEvent);
@@ -183,7 +183,7 @@ public class EventMeshClientUtil {
                 .setTopic(events.get(0).getSubject());
 
             for (CloudEvent event : events) {
-                String contentType = StringUtils.isEmpty(event.getDataContentType()) ? Constants.CONTENT_TYPE_CLOUDEVENTS_JSON
+                String contentType = StringUtils.isEmpty(event.getDataContentType()) ? "application/cloudevents+json"
                     : event.getDataContentType();
                 byte[] bodyByte = EventFormatProvider.getInstance().resolveFormat(contentType)
                     .serialize(event);
diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/util/EventMeshClientUtilTest.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/util/EventMeshClientUtilTest.java
index 7c15cf3a..4b54314e 100644
--- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/util/EventMeshClientUtilTest.java
+++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/util/EventMeshClientUtilTest.java
@@ -58,7 +58,7 @@ public class EventMeshClientUtilTest {
             .hasFieldOrPropertyWithValue("username", clientConfig.getUserName())
             .hasFieldOrPropertyWithValue("password", clientConfig.getPassword())
             .hasFieldOrPropertyWithValue("protocolType", "protocolType")
-            .hasFieldOrPropertyWithValue("protocolDesc", Constants.PROTOCOL_GRPC)
+            .hasFieldOrPropertyWithValue("protocolDesc", "grpc")
             .hasFieldOrPropertyWithValue("protocolVersion", SpecVersion.V1.toString());
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org