You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/08/23 20:10:18 UTC

[activemq-artemis] 02/04: ARTEMIS-2880 support FQQN syntax for JNDI lookup

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

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 57b8c22a62f0e64a7e7fdda8c10aa31f3d24d0ea
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Fri Aug 14 15:05:44 2020 -0500

    ARTEMIS-2880 support FQQN syntax for JNDI lookup
---
 .../activemq/artemis/jndi/ReadOnlyContext.java     |  2 +-
 .../integration/jms/SimpleJNDIClientTest.java      | 90 ++++++++++++++++++++++
 2 files changed, 91 insertions(+), 1 deletion(-)

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 d032d07..a9cc784 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 f6cbb24..26dbef2 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;
@@ -476,6 +477,29 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
    }
 
    @Test
+   public void testQueueFQQN() throws Exception {
+      final String QUEUE = "myQueue";
+      Hashtable<String, String> 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<String, String> props = new Hashtable<>();
       props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
@@ -486,6 +510,28 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
    }
 
    @Test
+   public void testDynamicQueueFQQN() throws Exception {
+      final String QUEUE = "myQueue";
+      Hashtable<String, String> 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<String, String> props = new Hashtable<>();
       props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
@@ -501,6 +547,28 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
    }
 
    @Test
+   public void testTopicFQQN() throws Exception {
+      final String SUBSCRIPTION = "mySubsription";
+      Hashtable<String, String> 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<String, String> props = new Hashtable<>();
       props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
@@ -511,6 +579,28 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
    }
 
    @Test
+   public void testDynamicTopicFQQN() throws Exception {
+      final String SUBSCRIPTION = "mySubsription";
+      Hashtable<String, String> 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 {
 
       //setup user and role on broker