diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/ReadOnlyContext.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/ReadOnlyContext.java index d032d075e4..a9cc7841ff 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/ReadOnlyContext.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/ReadOnlyContext.java @@ -215,7 +215,7 @@ public class ReadOnlyContext implements Context, Serializable { } if (result == null) { int pos = name.indexOf(':'); - if (pos > 0) { + if (pos > 0 && !name.contains("::")) { String scheme = name.substring(0, pos); Context ctx = NamingManager.getURLContext(scheme, environment); if (ctx == null) { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java index f6cbb2485e..26dbef2b14 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java @@ -60,6 +60,7 @@ import org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory; import org.apache.activemq.artemis.logs.AssertionLoggerHandler; import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; +import org.apache.activemq.artemis.utils.Wait; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -475,6 +476,29 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase { Assert.assertTrue(destination instanceof Queue); } + @Test + public void testQueueFQQN() throws Exception { + final String QUEUE = "myQueue"; + Hashtable props = new Hashtable<>(); + props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); + props.put("queue.myQueue", "myAddress::" + QUEUE); + Context ctx = new InitialContext(props); + liveService.getSecurityStore().setSecurityEnabled(false); + + Destination destination = (Destination) ctx.lookup(QUEUE); + Assert.assertTrue(destination instanceof Queue); + ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); + try (Connection connection = connectionFactory.createConnection()) { + Session session = connection.createSession(); + MessageProducer producer = session.createProducer(destination); + producer.send(session.createMessage()); + Wait.assertTrue(() -> liveService.locateQueue(QUEUE).getMessageCount() == 1, 2000, 100); + MessageConsumer consumer = session.createConsumer(destination); + connection.start(); + assertNotNull(consumer.receiveNoWait()); + } + } + @Test public void testDynamicQueue() throws NamingException, JMSException { Hashtable props = new Hashtable<>(); @@ -485,6 +509,28 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase { Assert.assertTrue(destination instanceof Queue); } + @Test + public void testDynamicQueueFQQN() throws Exception { + final String QUEUE = "myQueue"; + Hashtable props = new Hashtable<>(); + props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); + Context ctx = new InitialContext(props); + liveService.getSecurityStore().setSecurityEnabled(false); + + Destination destination = (Destination) ctx.lookup("dynamicQueues/myAddress::" + QUEUE); + Assert.assertTrue(destination instanceof Queue); + ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); + try (Connection connection = connectionFactory.createConnection()) { + Session session = connection.createSession(); + MessageProducer producer = session.createProducer(destination); + producer.send(session.createMessage()); + Wait.assertTrue(() -> liveService.locateQueue(QUEUE).getMessageCount() == 1, 2000, 100); + MessageConsumer consumer = session.createConsumer(destination); + connection.start(); + assertNotNull(consumer.receiveNoWait()); + } + } + @Test public void testTopic() throws NamingException, JMSException { Hashtable props = new Hashtable<>(); @@ -500,6 +546,28 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase { Assert.assertTrue(destination instanceof Topic); } + @Test + public void testTopicFQQN() throws Exception { + final String SUBSCRIPTION = "mySubsription"; + Hashtable props = new Hashtable<>(); + props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); + props.put("topic.myTopic", "myTopic::" + SUBSCRIPTION); + Context ctx = new InitialContext(props); + liveService.getSecurityStore().setSecurityEnabled(false); + + Destination destination = (Destination) ctx.lookup("myTopic"); + Assert.assertTrue(destination instanceof Topic); + ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); + Connection connection = connectionFactory.createConnection(); + Session session = connection.createSession(); + MessageProducer producer = session.createProducer(destination); + producer.send(session.createMessage()); + Wait.assertTrue(() -> liveService.locateQueue(SUBSCRIPTION).getMessageCount() == 1, 2000, 100); + MessageConsumer consumer = session.createConsumer(destination); + connection.start(); + assertNotNull(consumer.receiveNoWait()); + } + @Test public void testDynamicTopic() throws NamingException, JMSException { Hashtable props = new Hashtable<>(); @@ -510,6 +578,28 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase { Assert.assertTrue(destination instanceof Topic); } + @Test + public void testDynamicTopicFQQN() throws Exception { + final String SUBSCRIPTION = "mySubsription"; + Hashtable props = new Hashtable<>(); + props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); + props.put("topic.myTopic", "myTopic::" + SUBSCRIPTION); + Context ctx = new InitialContext(props); + liveService.getSecurityStore().setSecurityEnabled(false); + + Destination destination = (Destination) ctx.lookup("dynamicTopics/myTopic::" + SUBSCRIPTION); + Assert.assertTrue(destination instanceof Topic); + ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); + Connection connection = connectionFactory.createConnection(); + Session session = connection.createSession(); + MessageProducer producer = session.createProducer(destination); + producer.send(session.createMessage()); + Wait.assertTrue(() -> liveService.locateQueue(SUBSCRIPTION).getMessageCount() == 1, 2000, 100); + MessageConsumer consumer = session.createConsumer(destination); + connection.start(); + assertNotNull(consumer.receiveNoWait()); + } + @Test public void testRemoteCFWithTCPUserPassword() throws Exception {