This is an automated email from the ASF dual-hosted git repository.
jinrongtong 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 1f49ca5b [ISSUE #916] Add message body empty check for C# client
1f49ca5b is described below
commit 1f49ca5b59a78c9fe3700eaf5754997493a73c64
Author: Jack Tsai <[email protected]>
AuthorDate: Wed Jan 22 09:50:57 2025 +0800
[ISSUE #916] Add message body empty check for C# client
---
.../Error/PayloadEmptyException.cs | 34 ++++++++++++++++++++++
csharp/rocketmq-client-csharp/Message.cs | 2 +-
csharp/rocketmq-client-csharp/StatusChecker.cs | 2 ++
3 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/csharp/rocketmq-client-csharp/Error/PayloadEmptyException.cs
b/csharp/rocketmq-client-csharp/Error/PayloadEmptyException.cs
new file mode 100644
index 00000000..0db1be9c
--- /dev/null
+++ b/csharp/rocketmq-client-csharp/Error/PayloadEmptyException.cs
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+namespace Org.Apache.Rocketmq.Error
+{
+ /// <summary>
+ /// Generic exception represents when the request entity is empty.
+ /// </summary>
+ public class PayloadEmptyException : ClientException
+ {
+ public PayloadEmptyException(int responseCode, string requestId,
string message) : base(responseCode,
+ requestId, message)
+ {
+ }
+
+ public PayloadEmptyException(int responseCode, string message) :
base(responseCode, message)
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/rocketmq-client-csharp/Message.cs
b/csharp/rocketmq-client-csharp/Message.cs
index bbd2c20e..c1e2094e 100644
--- a/csharp/rocketmq-client-csharp/Message.cs
+++ b/csharp/rocketmq-client-csharp/Message.cs
@@ -91,7 +91,7 @@ namespace Org.Apache.Rocketmq
public Builder SetBody(byte[] body)
{
- Preconditions.CheckArgument(null != body, "body should not be
null");
+ Preconditions.CheckArgument(null != body || body.Length == 0,
"body should not be empty");
_body = body;
return this;
}
diff --git a/csharp/rocketmq-client-csharp/StatusChecker.cs
b/csharp/rocketmq-client-csharp/StatusChecker.cs
index 12d12fe6..e8764f2c 100644
--- a/csharp/rocketmq-client-csharp/StatusChecker.cs
+++ b/csharp/rocketmq-client-csharp/StatusChecker.cs
@@ -77,6 +77,8 @@ namespace Org.Apache.Rocketmq
case Proto.Code.PayloadTooLarge:
case Proto.Code.MessageBodyTooLarge:
throw new PayloadTooLargeException((int)statusCode,
requestId, statusMessage);
+ case Proto.Code.MessageBodyEmpty:
+ throw new PayloadEmptyException((int)statusCode,
requestId, statusMessage);
case Proto.Code.TooManyRequests:
throw new TooManyRequestsException((int)statusCode,
requestId, statusMessage);
case Proto.Code.RequestHeaderFieldsTooLarge: