This is an automated email from the ASF dual-hosted git repository. cshannon pushed a commit to branch activemq-6.1.x in repository https://gitbox.apache.org/repos/asf/activemq.git
commit c24a6253b8009cafdbf2945ec7fbcdcb2532f97a Author: Benjamin Graf <[email protected]> AuthorDate: Thu Mar 13 22:13:14 2025 +0100 AMQ-9685 - Virtual topic name should have at least one character to avoid Exception (cherry picked from commit 0ffe52a28b85dfb4a31ec6d7d522cb578341c8a9) --- .../broker/region/virtual/VirtualTopic.java | 2 +- .../activemq/broker/virtual/AMQ9685Test.java | 81 ++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualTopic.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualTopic.java index c57d80a16f..7b6bd71ad2 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualTopic.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualTopic.java @@ -67,7 +67,7 @@ public class VirtualTopic implements VirtualDestination { public Destination interceptMappedDestination(Destination destination) { // do a reverse map from destination to get actual virtual destination final String physicalName = destination.getActiveMQDestination().getPhysicalName(); - final Pattern pattern = Pattern.compile(getRegex(prefix) + "(.*)" + getRegex(postfix)); + final Pattern pattern = Pattern.compile(getRegex(prefix) + "(.+)" + getRegex(postfix)); final Matcher matcher = pattern.matcher(physicalName); if (matcher.matches()) { final String virtualName = matcher.group(1); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/virtual/AMQ9685Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/virtual/AMQ9685Test.java new file mode 100644 index 0000000000..35f3d6b9b6 --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/virtual/AMQ9685Test.java @@ -0,0 +1,81 @@ +/** + * 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. + */ +package org.apache.activemq.broker.virtual; + +import jakarta.jms.Connection; +import jakarta.jms.Destination; +import jakarta.jms.Session; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.region.DestinationInterceptor; +import org.apache.activemq.broker.region.virtual.VirtualDestination; +import org.apache.activemq.broker.region.virtual.VirtualDestinationInterceptor; +import org.apache.activemq.broker.region.virtual.VirtualTopic; +import org.apache.activemq.command.ActiveMQQueue; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class AMQ9685Test { + + private BrokerService brokerService; + private Connection connection; + + @Before + public void init() throws Exception { + brokerService = createBroker(); + brokerService.start(); + connection = createConnection(); + connection.start(); + } + + @After + public void after() throws Exception { + try { + connection.close(); + } catch (Exception e) { + //swallow any error so broker can still be stopped + } + brokerService.stop(); + } + + @Test + public void testBrokenWildcardQueueName() throws Exception { + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Destination destination = new ActiveMQQueue("Consumer.foo."); + session.createConsumer(destination, null); + } + + private Connection createConnection() throws Exception { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerService.getVmConnectorURI()); + cf.setWatchTopicAdvisories(false); + return cf.createConnection(); + } + + private BrokerService createBroker() throws Exception { + BrokerService broker = new BrokerService(); + broker.setAdvisorySupport(false); + broker.setPersistent(false); + + VirtualTopic virtualTopic = new VirtualTopic(); + VirtualDestinationInterceptor interceptor = new VirtualDestinationInterceptor(); + interceptor.setVirtualDestinations(new VirtualDestination[]{virtualTopic}); + broker.setDestinationInterceptors(new DestinationInterceptor[]{interceptor}); + return broker; + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information, visit: https://activemq.apache.org/contact
