This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new 8be418012 [ISSUE #4345]Fix publish EventMeshMessage without
requestCode throw java.lang.NullPointerException (#4352)
8be418012 is described below
commit 8be418012a682397c446efbd1461d540eed16422
Author: mxsm <[email protected]>
AuthorDate: Mon Aug 14 09:57:38 2023 +0800
[ISSUE #4345]Fix publish EventMeshMessage without requestCode throw
java.lang.NullPointerException (#4352)
* [ISSUE #4345]Fix publish EventMeshMessage without requestCode throw
java.lang.NullPointerException
* optimize logic
---
.../common/protocol/http/HttpCommand.java | 11 +++---
.../protocol/http/common/EventMeshRetCode.java | 42 +++++++++++-----------
.../common/protocol/http/common/RequestCode.java | 2 ++
.../common/protocol/http/HttpCommandTest.java | 10 ++++++
4 files changed, 38 insertions(+), 27 deletions(-)
diff --git
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java
index fa2057ae4..1e56b2bec 100644
---
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java
+++
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java
@@ -22,12 +22,11 @@ import
org.apache.eventmesh.common.protocol.ProtocolTransportObject;
import org.apache.eventmesh.common.protocol.http.body.BaseResponseBody;
import org.apache.eventmesh.common.protocol.http.body.Body;
import org.apache.eventmesh.common.protocol.http.common.EventMeshRetCode;
+import org.apache.eventmesh.common.protocol.http.common.RequestCode;
import org.apache.eventmesh.common.protocol.http.header.BaseResponseHeader;
import org.apache.eventmesh.common.protocol.http.header.Header;
import org.apache.eventmesh.common.utils.JsonUtils;
-import org.apache.commons.lang3.StringUtils;
-
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
@@ -82,8 +81,8 @@ public class HttpCommand implements ProtocolTransportObject {
}
public HttpCommand createHttpCommandResponse(Header header, Body body) {
- if (StringUtils.isBlank(requestCode)) {
- return null;
+ if (this.requestCode == null) {
+ this.requestCode = RequestCode.UNKNOWN.getRequestCode().toString();
}
HttpCommand response = new HttpCommand(this.httpMethod,
this.httpVersion, this.requestCode);
response.setOpaque(this.opaque);
@@ -96,8 +95,8 @@ public class HttpCommand implements ProtocolTransportObject {
}
public HttpCommand createHttpCommandResponse(EventMeshRetCode
eventMeshRetCode) {
- if (StringUtils.isBlank(requestCode)) {
- return null;
+ if (this.requestCode == null) {
+ this.requestCode = RequestCode.UNKNOWN.getRequestCode().toString();
}
HttpCommand response = new HttpCommand(this.httpMethod,
this.httpVersion, this.requestCode);
response.setOpaque(this.opaque);
diff --git
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/EventMeshRetCode.java
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/EventMeshRetCode.java
index d5b46475c..d3c7b067d 100644
---
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/EventMeshRetCode.java
+++
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/EventMeshRetCode.java
@@ -20,29 +20,29 @@ package org.apache.eventmesh.common.protocol.http.common;
public enum EventMeshRetCode {
SUCCESS(0, "success"),
- OVERLOAD(1, "eventMesh overload, try later, "),
- EVENTMESH_REQUESTCODE_INVALID(2, "requestCode can't be null, or must be
number, "),
- EVENTMESH_SEND_SYNC_MSG_ERR(3, "eventMesh send rr msg err, "),
- EVENTMESH_WAITING_RR_MSG_ERR(4, "eventMesh waiting rr msg err, "),
- EVENTMESH_PROTOCOL_HEADER_ERR(6, "eventMesh protocol[header] err, "),
- EVENTMESH_PROTOCOL_BODY_ERR(7, "eventMesh protocol[body] err, "),
- EVENTMESH_PROTOCOL_BODY_SIZE_ERR(8, "event size exceeds the limit, "),
- EVENTMESH_STOP(9, "eventMesh will stop or had stopped, "),
- EVENTMESH_REJECT_BY_PROCESSOR_ERROR(10, "eventMesh reject by processor
error, "),
- EVENTMESH_BATCH_PRODUCER_STOPED_ERR(11, "eventMesh batch msg producer
stopped, "),
- EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR(12, "eventMesh batch msg speed over
the limit, "),
+ OVERLOAD(1, "eventMesh overload, try later"),
+ EVENTMESH_REQUESTCODE_INVALID(2, "requestCode can't be null, or must be
number"),
+ EVENTMESH_SEND_SYNC_MSG_ERR(3, "eventMesh send rr msg error"),
+ EVENTMESH_WAITING_RR_MSG_ERR(4, "eventMesh waiting rr msg error"),
+ EVENTMESH_PROTOCOL_HEADER_ERR(6, "eventMesh protocol[header] error"),
+ EVENTMESH_PROTOCOL_BODY_ERR(7, "eventMesh protocol[body] error"),
+ EVENTMESH_PROTOCOL_BODY_SIZE_ERR(8, "event size exceeds the limit"),
+ EVENTMESH_STOP(9, "eventMesh will stop or had stopped"),
+ EVENTMESH_REJECT_BY_PROCESSOR_ERROR(10, "eventMesh reject by processor
error"),
+ EVENTMESH_BATCH_PRODUCER_STOPED_ERR(11, "eventMesh batch msg producer
stopped"),
+ EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR(12, "eventMesh batch msg speed over
the limit"),
EVENTMESH_PACKAGE_MSG_ERR(13, "eventMesh package msg err, "),
- EVENTMESH_GROUP_PRODUCER_STOPED_ERR(14, "eventMesh group producer stopped,
"),
- EVENTMESH_SEND_ASYNC_MSG_ERR(15, "eventMesh send async msg err, "),
+ EVENTMESH_GROUP_PRODUCER_STOPED_ERR(14, "eventMesh group producer
stopped"),
+ EVENTMESH_SEND_ASYNC_MSG_ERR(15, "eventMesh send async msg error"),
EVENTMESH_REPLY_MSG_ERR(16, "eventMesh reply msg err, "),
- EVENTMESH_SEND_BATCHLOG_MSG_ERR(17, "eventMesh send batchlog msg err, "),
- EVENTMESH_RUNTIME_ERR(18, "eventMesh runtime err, "),
- EVENTMESH_SUBSCRIBE_ERR(19, "eventMesh subscribe err"),
- EVENTMESH_UNSUBSCRIBE_ERR(20, "eventMesh unsubscribe err"),
- EVENTMESH_HEARTBEAT_ERR(21, "eventMesh heartbeat err"),
- EVENTMESH_ACL_ERR(22, "eventMesh acl err"),
- EVENTMESH_HTTP_MES_SEND_OVER_LIMIT_ERR(23, "eventMesh http msg send over
the limit, "),
- EVENTMESH_OPERATE_FAIL(100, "operate fail, ");
+ EVENTMESH_SEND_BATCHLOG_MSG_ERR(17, "eventMesh send batch log msg error"),
+ EVENTMESH_RUNTIME_ERR(18, "eventMesh runtime error"),
+ EVENTMESH_SUBSCRIBE_ERR(19, "eventMesh subscribe error"),
+ EVENTMESH_UNSUBSCRIBE_ERR(20, "eventMesh unsubscribe error"),
+ EVENTMESH_HEARTBEAT_ERR(21, "eventMesh heartbeat error"),
+ EVENTMESH_ACL_ERR(22, "eventMesh acl error"),
+ EVENTMESH_HTTP_MES_SEND_OVER_LIMIT_ERR(23, "eventMesh http msg send over
the limit"),
+ EVENTMESH_OPERATE_FAIL(100, "operate fail");
private final Integer retCode;
diff --git
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/RequestCode.java
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/RequestCode.java
index 1d6e351bb..7c89f38fa 100644
---
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/RequestCode.java
+++
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/RequestCode.java
@@ -19,6 +19,8 @@ package org.apache.eventmesh.common.protocol.http.common;
public enum RequestCode {
+ UNKNOWN(0, "UNKNOWN"),
+
MSG_BATCH_SEND(102, "SEND BATCH MSG"),
MSG_BATCH_SEND_V2(107, "SEND BATCH MSG V2"),
diff --git
a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/HttpCommandTest.java
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/HttpCommandTest.java
index 962d6c7a7..1754aadb6 100644
---
a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/HttpCommandTest.java
+++
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/HttpCommandTest.java
@@ -20,6 +20,7 @@ package org.apache.eventmesh.common.protocol.http;
import static org.mockito.Mockito.when;
import org.apache.eventmesh.common.protocol.http.body.Body;
+import org.apache.eventmesh.common.protocol.http.common.EventMeshRetCode;
import org.apache.eventmesh.common.protocol.http.header.Header;
import java.util.HashMap;
@@ -89,4 +90,13 @@ public class HttpCommandTest {
DefaultFullHttpResponse response = httpCommand.httpResponse();
Assert.assertNull(response);
}
+
+ @Test
+ public void testCreateHttpCommandResponse() {
+ HttpCommand command = new HttpCommand();
+ HttpCommand response =
command.createHttpCommandResponse(EventMeshRetCode.SUCCESS);
+ Assert.assertNotNull(response);
+ Assert.assertEquals("0", response.getRequestCode());
+
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]