Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import org.apache.eventmesh.protocol.cloudevents.resolver.http.SendMessageRequestProtocolResolver;
import org.apache.eventmesh.protocol.cloudevents.resolver.tcp.TcpMessageProtocolResolver;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -89,16 +87,16 @@ 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));
switch (RequestCode.valueOf(requestCode)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valueOf method is to transfer an Enum constant specified name to return an Enum constant.So It can not transfer requestCode as specified name to get any Enum constant.
image

So as the same as #4270.It causes client to fail to connect to the runtime server.
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my mistake here, the valueof here returns the enum constant for the specified string value, here it is judged by the requestCode, so it won't match up by doing so.
You might consider writing a method in the RequestCode class that returns the corresponding Enum type constant based on the requestCode.

case MSG_BATCH_SEND:
return SendMessageBatchProtocolResolver.buildEvent(header, body);
case MSG_BATCH_SEND_V2:
return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
case MSG_SEND_SYNC:
case MSG_SEND_ASYNC:
return SendMessageRequestProtocolResolver.buildEvent(header, body);
default:
throw new ProtocolHandleException(String.format("unsupported requestCode: %s", requestCode));
}

}
Expand All @@ -117,36 +115,37 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
Preconditions.checkNotNull(cloudEvent, "cloudEvent cannot be null");
String protocolDesc = Objects.requireNonNull(cloudEvent.getExtension(Constants.PROTOCOL_DESC)).toString();
if (StringUtils.equals("http", protocolDesc)) {
HttpCommand httpCommand = new HttpCommand();
Body body = new Body() {
final Map<String, Object> map = new HashMap<>();

@Override
public Map<String, Object> toMap() {
byte[] eventByte =
Objects.requireNonNull(EventFormatProvider.getInstance()
.resolveFormat(JsonFormat.CONTENT_TYPE)).serialize(cloudEvent);
map.put("content", new String(eventByte, Constants.DEFAULT_CHARSET));
return map;
}
};
body.toMap();
httpCommand.setBody(body);
return httpCommand;
} else if (StringUtils.equals("tcp", protocolDesc)) {
Package pkg = new Package();
String dataContentType = cloudEvent.getDataContentType();
Preconditions.checkNotNull(dataContentType, "DateContentType cannot be null");
EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(dataContentType);
Preconditions.checkNotNull(eventFormat,
String.format("DateContentType:%s is not supported", dataContentType));
pkg.setBody(eventFormat.serialize(cloudEvent));
return pkg;
} else if (StringUtils.equals(CloudEventsProtocolConstant.PROTOCOL_DESC_GRPC_CLOUD_EVENT, protocolDesc)) {
return GrpcEventMeshCloudEventProtocolResolver.buildEventMeshCloudEvent(cloudEvent);
} else {
throw new ProtocolHandleException(String.format("Unsupported protocolDesc: %s", protocolDesc));
switch (protocolDesc) {
case "http":
HttpCommand httpCommand = new HttpCommand();
Body body = new Body() {
final Map<String, Object> map = new HashMap<>();

@Override
public Map<String, Object> toMap() {
byte[] eventByte =
Objects.requireNonNull(EventFormatProvider.getInstance()
.resolveFormat(JsonFormat.CONTENT_TYPE)).serialize(cloudEvent);
map.put("content", new String(eventByte, Constants.DEFAULT_CHARSET));
return map;
}
};
body.toMap();
httpCommand.setBody(body);
return httpCommand;
case "tcp":
Package pkg = new Package();
String dataContentType = cloudEvent.getDataContentType();
Preconditions.checkNotNull(dataContentType, "DateContentType cannot be null");
EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(dataContentType);
Preconditions.checkNotNull(eventFormat,
String.format("DateContentType:%s is not supported", dataContentType));
pkg.setBody(eventFormat.serialize(cloudEvent));
return pkg;
case CloudEventsProtocolConstant.PROTOCOL_DESC_GRPC_CLOUD_EVENT:
return GrpcEventMeshCloudEventProtocolResolver.buildEventMeshCloudEvent(cloudEvent);
default:
throw new ProtocolHandleException(String.format("Unsupported protocolDesc: %s", protocolDesc));
}

}
Expand Down