Pil0tXia commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270836771


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -77,19 +75,20 @@ private CloudEvent deserializeTcpProtocol(Header header, 
String bodyJson) throws
     }
 
     private CloudEvent deserializeHttpProtocol(String requestCode,
-        org.apache.eventmesh.common.protocol.http.header.Header header,
-        Body body) throws ProtocolHandleException {
-
-        if 
(String.valueOf(RequestCode.MSG_BATCH_SEND.getRequestCode()).equals(requestCode))
 {
-            return SendMessageBatchProtocolResolver.buildEvent(header, body);
-        } else if 
(String.valueOf(RequestCode.MSG_BATCH_SEND_V2.getRequestCode()).equals(requestCode))
 {
-            return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
-        } else if 
(String.valueOf(RequestCode.MSG_SEND_SYNC.getRequestCode()).equals(requestCode))
 {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else if 
(String.valueOf(RequestCode.MSG_SEND_ASYNC.getRequestCode()).equals(requestCode))
 {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else {
-            throw new ProtocolHandleException(String.format("unsupported 
requestCode: %s", requestCode));
+                                               
org.apache.eventmesh.common.protocol.http.header.Header header,
+                                               Body body) throws 
ProtocolHandleException {
+
+        switch (RequestCode.valueOf(requestCode)) {
+            case MSG_BATCH_SEND:
+                return SendMessageBatchProtocolResolver.buildEvent(header, 
body);
+            case MSG_BATCH_SEND_V2:
+                return SendMessageBatchV2ProtocolResolver.buildEvent(header, 
body);
+            case MSG_SEND_SYNC:
+                return SendMessageRequestProtocolResolver.buildEvent(header, 
body);

Review Comment:
   This line is redundant.



##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> 
toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) 
throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : 
cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, 
protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? 
null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();

Review Comment:
   No change needs to be made in this line.



##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> 
toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) 
throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : 
cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, 
protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? 
null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        
map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new 
String(cloudEvent.getData().toBytes(),
+                                Constants.DEFAULT_CHARSET));

Review Comment:
   Consider putting the second argument on the same line.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to