You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@eventmesh.apache.org by "mxsm (via GitHub)" <gi...@apache.org> on 2023/07/21 13:12:46 UTC
Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)
mxsm commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270661358
##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +108,32 @@ 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(), StandardCharsets.UTF_8));
Review Comment:
StandardCharsets.UTF_8 replace with Constants.DEFAULT_CHARSET
--
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: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org