Alonexc commented on code in PR #3709:
URL: https://github.com/apache/eventmesh/pull/3709#discussion_r1165230534
##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageRequestProtocolResolver.java:
##########
@@ -42,98 +42,59 @@ public static CloudEvent buildEvent(Header header, Body
body) throws ProtocolHan
SendMessageRequestHeader sendMessageRequestHeader =
(SendMessageRequestHeader) header;
SendMessageRequestBody sendMessageRequestBody =
(SendMessageRequestBody) body;
- String protocolType = sendMessageRequestHeader.getProtocolType();
- String protocolDesc = sendMessageRequestHeader.getProtocolDesc();
- String protocolVersion =
sendMessageRequestHeader.getProtocolVersion();
-
- String code = sendMessageRequestHeader.getCode();
- String env = sendMessageRequestHeader.getEnv();
- String idc = sendMessageRequestHeader.getIdc();
- String ip = sendMessageRequestHeader.getIp();
- String pid = sendMessageRequestHeader.getPid();
- String sys = sendMessageRequestHeader.getSys();
- String username = sendMessageRequestHeader.getUsername();
- String passwd = sendMessageRequestHeader.getPasswd();
- ProtocolVersion version = sendMessageRequestHeader.getVersion();
- String language = sendMessageRequestHeader.getLanguage();
-
- String content = sendMessageRequestBody.getContent();
-
- CloudEvent event = null;
CloudEventBuilder cloudEventBuilder;
- if (StringUtils.equals(SpecVersion.V1.toString(),
protocolVersion)) {
- cloudEventBuilder = CloudEventBuilder.v1();
-
- cloudEventBuilder =
cloudEventBuilder.withId(sendMessageRequestBody.getBizSeqNo())
- .withSubject(sendMessageRequestBody.getTopic())
- .withType("eventmeshmessage")
- .withSource(URI.create("/"))
- .withData(content.getBytes(StandardCharsets.UTF_8))
- .withExtension(ProtocolKey.REQUEST_CODE, code)
- .withExtension(ProtocolKey.ClientInstanceKey.ENV, env)
- .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc)
- .withExtension(ProtocolKey.ClientInstanceKey.IP, ip)
- .withExtension(ProtocolKey.ClientInstanceKey.PID, pid)
- .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys)
- .withExtension(ProtocolKey.ClientInstanceKey.USERNAME,
username)
- .withExtension(ProtocolKey.ClientInstanceKey.PASSWD,
passwd)
- .withExtension(ProtocolKey.VERSION, version.getVersion())
- .withExtension(ProtocolKey.LANGUAGE, language)
- .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType)
- .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc)
- .withExtension(ProtocolKey.PROTOCOL_VERSION,
protocolVersion)
- .withExtension(SendMessageRequestBody.BIZSEQNO,
sendMessageRequestBody.getBizSeqNo())
- .withExtension(SendMessageRequestBody.UNIQUEID,
sendMessageRequestBody.getUniqueId())
- .withExtension(SendMessageRequestBody.PRODUCERGROUP,
- sendMessageRequestBody.getProducerGroup())
- .withExtension(SendMessageRequestBody.TTL,
sendMessageRequestBody.getTtl());
- if (StringUtils.isNotEmpty(sendMessageRequestBody.getTag())) {
- cloudEventBuilder =
cloudEventBuilder.withExtension(SendMessageRequestBody.TAG,
sendMessageRequestBody.getTag());
- }
- if (sendMessageRequestBody.getExtFields() != null &&
sendMessageRequestBody.getExtFields().size() > 0) {
- for (Map.Entry<String, String> entry :
sendMessageRequestBody.getExtFields().entrySet()) {
- cloudEventBuilder =
cloudEventBuilder.withExtension(entry.getKey(), entry.getValue());
- }
- }
- event = cloudEventBuilder.build();
- } else if (StringUtils.equals(SpecVersion.V03.toString(),
protocolVersion)) {
- cloudEventBuilder = CloudEventBuilder.v03();
- cloudEventBuilder =
cloudEventBuilder.withId(sendMessageRequestBody.getBizSeqNo())
- .withSubject(sendMessageRequestBody.getTopic())
- .withType("eventmeshmessage")
- .withSource(URI.create("/"))
- .withData(content.getBytes(StandardCharsets.UTF_8))
- .withExtension(ProtocolKey.REQUEST_CODE, code)
- .withExtension(ProtocolKey.ClientInstanceKey.ENV, env)
- .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc)
- .withExtension(ProtocolKey.ClientInstanceKey.IP, ip)
- .withExtension(ProtocolKey.ClientInstanceKey.PID, pid)
- .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys)
- .withExtension(ProtocolKey.ClientInstanceKey.USERNAME,
username)
- .withExtension(ProtocolKey.ClientInstanceKey.PASSWD,
passwd)
- .withExtension(ProtocolKey.VERSION, version.getVersion())
- .withExtension(ProtocolKey.LANGUAGE, language)
- .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType)
- .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc)
- .withExtension(ProtocolKey.PROTOCOL_VERSION,
protocolVersion)
- .withExtension(SendMessageRequestBody.BIZSEQNO,
sendMessageRequestBody.getBizSeqNo())
- .withExtension(SendMessageRequestBody.UNIQUEID,
sendMessageRequestBody.getUniqueId())
- .withExtension(SendMessageRequestBody.PRODUCERGROUP,
- sendMessageRequestBody.getProducerGroup())
- .withExtension(SendMessageRequestBody.TTL,
sendMessageRequestBody.getTtl());
- if (StringUtils.isNotEmpty(sendMessageRequestBody.getTag())) {
- cloudEventBuilder =
cloudEventBuilder.withExtension(SendMessageRequestBody.TAG,
sendMessageRequestBody.getTag());
- }
- if (sendMessageRequestBody.getExtFields() != null &&
sendMessageRequestBody.getExtFields().size() > 0) {
- for (Map.Entry<String, String> entry :
sendMessageRequestBody.getExtFields().entrySet()) {
- cloudEventBuilder =
cloudEventBuilder.withExtension(entry.getKey(), entry.getValue());
- }
- }
- event = cloudEventBuilder.build();
+ switch
(SpecVersion.parse(sendMessageRequestHeader.getProtocolVersion())) {
+ case SpecVersion.V1:
Review Comment:
Enumeration types are defined in switch statements. For each case clause,
the compiler simply checks for the presence of text in the enumeration, and if
it is allowed to specify fully qualified class names in the case clause, then
the compiler must perform a useless step.
--
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]