Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand All @@ -45,7 +46,9 @@ public WildcardAddressManager(final BindingsFactory bindingsFactory,
// 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,7 @@ IllegalStateException invalidRoutingTypeUpdate(String queueName,
@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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,16 +30,24 @@
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;
Expand Down Expand Up @@ -755,6 +766,27 @@ public void testLargeWildcardRouting() throws Exception {
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 {
Expand Down