This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new f0ffbaf2e fix(message): reject a blank topic in the rmq.message.send
tool (#7323)
f0ffbaf2e is described below
commit f0ffbaf2ebfe9d7a30c00461ae44206d74e512f3
Author: 0 <[email protected]>
AuthorDate: Fri Nov 27 11:57:51 2026 +0800
fix(message): reject a blank topic in the rmq.message.send tool (#7323)
---
.../ai/tool/handler/message/MessageSendToolHandler.java | 9 +++++++++
.../handler/message/MessageSendToolHandlerTest.java | 17 +++++++++++++++++
2 files changed, 26 insertions(+)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/handler/message/MessageSendToolHandler.java
b/server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/handler/message/MessageSendToolHandler.java
index f93e043fe..102bda7aa 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/handler/message/MessageSendToolHandler.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/handler/message/MessageSendToolHandler.java
@@ -67,6 +67,7 @@ public class MessageSendToolHandler extends
MutationToolHandler<MessageSendInput
@Override
public ToolPlan preview(MessageSendInput input, ToolExecutionContext
context) {
// Validates only: the parsed value is rebuilt by execute(), so the
return value is dropped here.
+ validateTopic(input);
parseProperties(input.properties());
validateForTopicType(resolveTopicType(context.instanceId(),
input.topicName()), input);
Map<String, Object> after = new LinkedHashMap<>();
@@ -88,6 +89,7 @@ public class MessageSendToolHandler extends
MutationToolHandler<MessageSendInput
@Override
public MessageSendOutput execute(MessageSendInput input,
ToolExecutionContext context) {
+ validateTopic(input);
validateForTopicType(resolveTopicType(context.instanceId(),
input.topicName()), input);
SendMessageDTO request = SendMessageDTO.builder()
.instanceId(context.instanceId())
@@ -103,6 +105,13 @@ public class MessageSendToolHandler extends
MutationToolHandler<MessageSendInput
return MessageSendOutput.from(sent);
}
+ /** Matches the REST send contract (@NotBlank "topic is required");
rejected before any topic lookup. */
+ private static void validateTopic(MessageSendInput input) {
+ if (!StringUtils.hasText(input.topicName())) {
+ throw new BusinessException(400, "topic is required");
+ }
+ }
+
/** The registered topic type is the single source of truth; unknown
topics keep plain-send behavior. */
private TopicType resolveTopicType(String instanceId, String topicName) {
return metadataService.findTopic(instanceId, null, topicName)
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/handler/message/MessageSendToolHandlerTest.java
b/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/handler/message/MessageSendToolHandlerTest.java
index e75361506..8ca883779 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/handler/message/MessageSendToolHandlerTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/handler/message/MessageSendToolHandlerTest.java
@@ -62,6 +62,23 @@ class MessageSendToolHandlerTest {
verify(metadata, never()).sendMessage(any(SendMessageDTO.class));
}
+ @ParameterizedTest
+ @ValueSource(strings = {"", " "})
+ void blankTopicIsRejectedBeforeTopicLookupTest(String topicName) {
+ MessageSendInput request = new MessageSendInput("instance-a",
topicName, "hello", null, null,
+ null, null, null);
+
+ assertThatThrownBy(() -> handler.preview(request,
context("instance-a")))
+ .isInstanceOf(BusinessException.class)
+ .hasMessage("topic is required")
+ .satisfies(exception -> assertThat(((BusinessException)
exception).getCode()).isEqualTo(400));
+ assertThatThrownBy(() -> handler.execute(request,
context("instance-a")))
+ .isInstanceOf(BusinessException.class)
+ .hasMessage("topic is required");
+ verify(metadata, never()).findTopic(any(), any(), any());
+ verify(metadata, never()).sendMessage(any(SendMessageDTO.class));
+ }
+
private void givenTopicType(TopicType type) {
TopicVO topic = new TopicVO();
topic.setName("TopicA");