Skip to content

Commit e084fda

Browse files
clebertsuconictabish121
authored andcommitted
ARTEMIS-6056 Throw proper exception if wildcard addresses are used in routing / sending
1 parent 6794e2c commit e084fda

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/WildcardAddressManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.activemq.artemis.core.postoffice.Binding;
2323
import org.apache.activemq.artemis.core.postoffice.Bindings;
2424
import org.apache.activemq.artemis.core.postoffice.BindingsFactory;
25+
import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
2526
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
2627
import org.apache.activemq.artemis.core.server.metrics.MetricsManager;
2728
import org.apache.activemq.artemis.core.transaction.Transaction;
@@ -45,7 +46,9 @@ public WildcardAddressManager(final BindingsFactory bindingsFactory,
4546
// won't contain a wildcard because we don't ever route to a wildcards at this time
4647
@Override
4748
public Bindings getBindingsForRoutingAddress(final SimpleString address) throws Exception {
48-
assert !wildcardConfiguration.isWild(address);
49+
if (wildcardConfiguration.isWild(address)) {
50+
throw ActiveMQMessageBundle.BUNDLE.wildcardOnProducerNotSupported(String.valueOf(address));
51+
}
4952

5053
Bindings bindings = super.getBindingsForRoutingAddress(address);
5154

artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,7 @@ IllegalStateException invalidRoutingTypeUpdate(String queueName,
541541
@Message(id = 229259, value = "Invalid disk full message policy type {}")
542542
IllegalArgumentException invalidDiskFullPolicyType(String val);
543543

544+
@Message(id = 229260, value = "Wildcard addresses are not supported on producers. Only on consumers. Please send to a real address. {}")
545+
ActiveMQException wildcardOnProducerNotSupported(String val);
546+
544547
}

tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/WildCardRoutingTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
*/
1717
package org.apache.activemq.artemis.tests.integration.client;
1818

19+
import java.lang.invoke.MethodHandles;
20+
1921
import org.apache.activemq.artemis.api.core.QueueConfiguration;
22+
import org.apache.activemq.artemis.api.core.RoutingType;
2023
import org.apache.activemq.artemis.api.core.SimpleString;
2124
import org.apache.activemq.artemis.api.core.client.ClientConsumer;
2225
import org.apache.activemq.artemis.api.core.client.ClientMessage;
@@ -27,16 +30,24 @@
2730
import org.apache.activemq.artemis.core.config.Configuration;
2831
import org.apache.activemq.artemis.core.server.ActiveMQServer;
2932
import org.apache.activemq.artemis.core.server.ActiveMQServers;
33+
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
34+
import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
3035
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
3136
import org.junit.jupiter.api.BeforeEach;
3237
import org.junit.jupiter.api.Test;
38+
import org.slf4j.Logger;
39+
import org.slf4j.LoggerFactory;
3340

3441
import static org.junit.jupiter.api.Assertions.assertEquals;
3542
import static org.junit.jupiter.api.Assertions.assertNotNull;
3643
import static org.junit.jupiter.api.Assertions.assertNull;
44+
import static org.junit.jupiter.api.Assertions.assertThrows;
45+
import static org.junit.jupiter.api.Assertions.assertTrue;
3746

3847
public class WildCardRoutingTest extends ActiveMQTestBase {
3948

49+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
50+
4051
private ActiveMQServer server;
4152
private ServerLocator locator;
4253
private ClientSession clientSession;
@@ -755,6 +766,27 @@ public void testLargeWildcardRouting() throws Exception {
755766
assertEquals(0, server.getPostOffice().getBindingsForAddress(address).getBindings().size());
756767
}
757768

769+
770+
@Test
771+
public void testInvalidWildcard() throws Exception {
772+
String wildcardAddress = "a.*.*.*.*.*.*";
773+
server.addAddressInfo(new AddressInfo(wildcardAddress).addRoutingType(RoutingType.ANYCAST));
774+
775+
try (AssertionLoggerHandler loggerHandler = new AssertionLoggerHandler(true)) {
776+
assertThrows(Exception.class, () -> {
777+
try {
778+
ClientProducer producer = clientSession.createProducer(wildcardAddress);
779+
producer.send(clientSession.createMessage(true));
780+
} catch (Exception e) {
781+
logger.warn(e.getMessage(), e);
782+
throw e;
783+
}
784+
});
785+
assertTrue(loggerHandler.findText("AMQ229260"));
786+
}
787+
}
788+
789+
758790
@Override
759791
@BeforeEach
760792
public void setUp() throws Exception {

0 commit comments

Comments
 (0)