This is an automated email from the ASF dual-hosted git repository.
lizhimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git
The following commit(s) were added to refs/heads/master by this push:
new bedcf25f [ISSUE #858] Jave client validate Message Body to avoid
setting empty Body (#859)
bedcf25f is described below
commit bedcf25f10f17110874accee8eea012c9bb5b01c
Author: qianye <[email protected]>
AuthorDate: Thu Nov 21 10:25:13 2024 +0800
[ISSUE #858] Jave client validate Message Body to avoid setting empty Body
(#859)
---
java/client-shade/pom.xml | 4 +--
java/client/pom.xml | 4 +--
.../java/exception/PayloadEmptyException.java | 29 ++++++++++++++++++++++
.../client/java/exception/StatusChecker.java | 2 ++
.../client/java/message/MessageBuilderImpl.java | 3 ++-
java/pom.xml | 24 +++++-------------
6 files changed, 43 insertions(+), 23 deletions(-)
diff --git a/java/client-shade/pom.xml b/java/client-shade/pom.xml
index ff8a9780..5dc223ea 100644
--- a/java/client-shade/pom.xml
+++ b/java/client-shade/pom.xml
@@ -42,8 +42,8 @@
<artifactId>rocketmq-client-java-noshade</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>annotations-api</artifactId>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
</dependency>
</dependencies>
diff --git a/java/client/pom.xml b/java/client/pom.xml
index a3ea357e..3c8ceb49 100644
--- a/java/client/pom.xml
+++ b/java/client/pom.xml
@@ -45,8 +45,8 @@
<artifactId>rocketmq-proto</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>annotations-api</artifactId>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
diff --git
a/java/client/src/main/java/org/apache/rocketmq/client/java/exception/PayloadEmptyException.java
b/java/client/src/main/java/org/apache/rocketmq/client/java/exception/PayloadEmptyException.java
new file mode 100644
index 00000000..36be7b80
--- /dev/null
+++
b/java/client/src/main/java/org/apache/rocketmq/client/java/exception/PayloadEmptyException.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.client.java.exception;
+
+import org.apache.rocketmq.client.apis.ClientException;
+
+/**
+ * Generic exception represents that the request entity is empty.
+ */
+public class PayloadEmptyException extends ClientException {
+ public PayloadEmptyException(int responseCode, String requestId, String
message) {
+ super(responseCode, requestId, message);
+ }
+}
diff --git
a/java/client/src/main/java/org/apache/rocketmq/client/java/exception/StatusChecker.java
b/java/client/src/main/java/org/apache/rocketmq/client/java/exception/StatusChecker.java
index 76f5a225..58e9cfc0 100644
---
a/java/client/src/main/java/org/apache/rocketmq/client/java/exception/StatusChecker.java
+++
b/java/client/src/main/java/org/apache/rocketmq/client/java/exception/StatusChecker.java
@@ -79,6 +79,8 @@ public class StatusChecker {
case PAYLOAD_TOO_LARGE:
case MESSAGE_BODY_TOO_LARGE:
throw new PayloadTooLargeException(codeNumber, requestId,
statusMessage);
+ case MESSAGE_BODY_EMPTY:
+ throw new PayloadEmptyException(codeNumber, requestId,
statusMessage);
case TOO_MANY_REQUESTS:
throw new TooManyRequestsException(codeNumber, requestId,
statusMessage);
case REQUEST_HEADER_FIELDS_TOO_LARGE:
diff --git
a/java/client/src/main/java/org/apache/rocketmq/client/java/message/MessageBuilderImpl.java
b/java/client/src/main/java/org/apache/rocketmq/client/java/message/MessageBuilderImpl.java
index 83cbb30c..f5a066b2 100644
---
a/java/client/src/main/java/org/apache/rocketmq/client/java/message/MessageBuilderImpl.java
+++
b/java/client/src/main/java/org/apache/rocketmq/client/java/message/MessageBuilderImpl.java
@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.client.apis.message.Message;
import org.apache.rocketmq.client.apis.message.MessageBuilder;
@@ -62,7 +63,7 @@ public class MessageBuilderImpl implements MessageBuilder {
*/
@Override
public MessageBuilder setBody(byte[] body) {
- checkNotNull(body, "body should not be null");
+ checkArgument(ArrayUtils.isNotEmpty(body), "body should not be empty");
this.body = body.clone();
return this;
}
diff --git a/java/pom.xml b/java/pom.xml
index ee05f650..df27bfe0 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -48,8 +48,8 @@
~ 1. Whether it is essential, because the current shaded jar is
fat enough.
~ 2. Make sure that it is compatible with Java 8.
-->
- <rocketmq-proto.version>2.0.3</rocketmq-proto.version>
- <annotations-api.version>6.0.53</annotations-api.version>
+ <rocketmq-proto.version>2.0.4</rocketmq-proto.version>
+ <annotations-api.version>1.3.5</annotations-api.version>
<protobuf.version>3.24.4</protobuf.version>
<grpc.version>1.50.0</grpc.version>
<guava.version>32.0.0-jre</guava.version>
@@ -110,26 +110,14 @@
<version>${rocketmq-proto.version}</version>
<exclusions>
<exclusion>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-protobuf</artifactId>
- </exclusion>
- <exclusion>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-stub</artifactId>
- </exclusion>
- <exclusion>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-netty-shaded</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>annotations-api</artifactId>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>annotations-api</artifactId>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
<version>${annotations-api.version}</version>
</dependency>
<dependency>