Skip to content

Commit

Permalink
[ISSUE #858] Jave client validate Message Body to avoid setting empty…
Browse files Browse the repository at this point in the history
… Body (#859)
  • Loading branch information
qianye1001 authored Nov 21, 2024
1 parent 552cf9e commit bedcf25
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 23 deletions.
4 changes: 2 additions & 2 deletions java/client-shade/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
4 changes: 2 additions & 2 deletions java/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public static void check(Status status, RpcFuture<?, ?> future) throws ClientExc
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -62,7 +63,7 @@ public MessageBuilder setTopic(String topic) {
*/
@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;
}
Expand Down
24 changes: 6 additions & 18 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit bedcf25

Please sign in to comment.