This is an automated email from the ASF dual-hosted git repository.

tabish121 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new e084fda741 ARTEMIS-6056 Throw proper exception if wildcard addresses 
are used in routing / sending
e084fda741 is described below

commit e084fda74131d60e02661dc3ded51e9cda3c8901
Author: Clebert Suconic <[email protected]>
AuthorDate: Tue May 12 15:41:55 2026 -0400

    ARTEMIS-6056 Throw proper exception if wildcard addresses are used in 
routing / sending
---
 .../postoffice/impl/WildcardAddressManager.java    |  5 +++-
 .../artemis/core/server/ActiveMQMessageBundle.java |  3 ++
 .../integration/client/WildCardRoutingTest.java    | 32 ++++++++++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/WildcardAddressManager.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/WildcardAddressManager.java
index 7a3ab89dde..3dfb6f3d25 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/WildcardAddressManager.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/WildcardAddressManager.java
@@ -22,6 +22,7 @@ import 
org.apache.activemq.artemis.core.persistence.StorageManager;
 import org.apache.activemq.artemis.core.postoffice.Binding;
 import org.apache.activemq.artemis.core.postoffice.Bindings;
 import org.apache.activemq.artemis.core.postoffice.BindingsFactory;
+import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
 import org.apache.activemq.artemis.core.server.impl.AddressInfo;
 import org.apache.activemq.artemis.core.server.metrics.MetricsManager;
 import org.apache.activemq.artemis.core.transaction.Transaction;
@@ -45,7 +46,9 @@ public class WildcardAddressManager extends 
SimpleAddressManager {
    // won't contain a wildcard because we don't ever route to a wildcards at 
this time
    @Override
    public Bindings getBindingsForRoutingAddress(final SimpleString address) 
throws Exception {
-      assert !wildcardConfiguration.isWild(address);
+      if (wildcardConfiguration.isWild(address)) {
+         throw 
ActiveMQMessageBundle.BUNDLE.wildcardOnProducerNotSupported(String.valueOf(address));
+      }
 
       Bindings bindings = super.getBindingsForRoutingAddress(address);
 
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
index 02b532341d..0ca2902c56 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
@@ -541,4 +541,7 @@ public interface ActiveMQMessageBundle {
    @Message(id = 229259, value = "Invalid disk full message policy type {}")
    IllegalArgumentException invalidDiskFullPolicyType(String val);
 
+   @Message(id = 229260, value = "Wildcard addresses are not supported on 
producers. Only on consumers. Please send to a real address. {}")
+   ActiveMQException wildcardOnProducerNotSupported(String val);
+
 }
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/WildCardRoutingTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/WildCardRoutingTest.java
index fd1d032604..e630f2ab4d 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/WildCardRoutingTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/WildCardRoutingTest.java
@@ -16,7 +16,10 @@
  */
 package org.apache.activemq.artemis.tests.integration.client;
 
+import java.lang.invoke.MethodHandles;
+
 import org.apache.activemq.artemis.api.core.QueueConfiguration;
+import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.client.ClientConsumer;
 import org.apache.activemq.artemis.api.core.client.ClientMessage;
@@ -27,16 +30,24 @@ import 
org.apache.activemq.artemis.api.core.client.ServerLocator;
 import org.apache.activemq.artemis.core.config.Configuration;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.ActiveMQServers;
+import org.apache.activemq.artemis.core.server.impl.AddressInfo;
+import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class WildCardRoutingTest extends ActiveMQTestBase {
 
+   private static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
    private ActiveMQServer server;
    private ServerLocator locator;
    private ClientSession clientSession;
@@ -755,6 +766,27 @@ public class WildCardRoutingTest extends ActiveMQTestBase {
       assertEquals(0, 
server.getPostOffice().getBindingsForAddress(address).getBindings().size());
    }
 
+
+   @Test
+   public void testInvalidWildcard() throws Exception {
+      String wildcardAddress = "a.*.*.*.*.*.*";
+      server.addAddressInfo(new 
AddressInfo(wildcardAddress).addRoutingType(RoutingType.ANYCAST));
+
+      try (AssertionLoggerHandler loggerHandler = new 
AssertionLoggerHandler(true)) {
+         assertThrows(Exception.class, () -> {
+            try {
+               ClientProducer producer = 
clientSession.createProducer(wildcardAddress);
+               producer.send(clientSession.createMessage(true));
+            } catch (Exception e) {
+               logger.warn(e.getMessage(), e);
+               throw e;
+            }
+         });
+         assertTrue(loggerHandler.findText("AMQ229260"));
+      }
+   }
+
+
    @Override
    @BeforeEach
    public void setUp() throws Exception {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to