You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/09/21 07:11:58 UTC

svn commit: r1388326 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms: JmsConnector.java JmsQueueConnector.java JmsTopicConnector.java

Author: tabish
Date: Fri Sep 21 05:11:57 2012
New Revision: 1388326

URL: http://svn.apache.org/viewvc?rev=1388326&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQ-3298

Add property preferJndiDestinationLookup so that users can override the default order as needed and have the connector first go to JNDI before trying the JMS create method.

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsConnector.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsQueueConnector.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsTopicConnector.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsConnector.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsConnector.java?rev=1388326&r1=1388325&r2=1388326&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsConnector.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsConnector.java Fri Sep 21 05:11:57 2012
@@ -50,6 +50,7 @@ public abstract class JmsConnector imple
     private static int nextId;
     private static final Logger LOG = LoggerFactory.getLogger(JmsConnector.class);
 
+    protected boolean preferJndiDestinationLookup = false;
     protected JndiTemplate jndiLocalTemplate;
     protected JndiTemplate jndiOutboundTemplate;
     protected JmsMesageConvertor inboundMessageConvertor;
@@ -375,6 +376,25 @@ public abstract class JmsConnector imple
     }
 
     /**
+     * @return the preferJndiDestinationLookup
+     */
+    public boolean isPreferJndiDestinationLookup() {
+        return preferJndiDestinationLookup;
+    }
+
+    /**
+     * Sets whether the connector should prefer to first try to find a destination in JNDI before
+     * using JMS semantics to create a Destination.  By default the connector will first use JMS
+     * semantics and then fall-back to JNDI lookup, setting this value to true will reverse that
+     * ordering.
+     *
+     * @param preferJndiDestinationLookup the preferJndiDestinationLookup to set
+     */
+    public void setPreferJndiDestinationLookup(boolean preferJndiDestinationLookup) {
+        this.preferJndiDestinationLookup = preferJndiDestinationLookup;
+    }
+
+    /**
      * @return returns true if the {@link JmsConnector} is connected to both brokers.
      */
     public boolean isConnected() {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsQueueConnector.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsQueueConnector.java?rev=1388326&r1=1388325&r2=1388326&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsQueueConnector.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsQueueConnector.java Fri Sep 21 05:11:57 2012
@@ -429,21 +429,39 @@ public class JmsQueueConnector extends J
 
     protected Queue createForeignQueue(QueueSession session, String queueName) throws JMSException {
         Queue result = null;
-        try {
-            result = session.createQueue(queueName);
-        } catch (JMSException e) {
-            // look-up the Queue
+
+        if (preferJndiDestinationLookup) {
             try {
+                // look-up the Queue
                 result = (Queue)jndiOutboundTemplate.lookup(queueName, Queue.class);
-            } catch (NamingException e1) {
-                String errStr = "Failed to look-up Queue for name: " + queueName;
-                LOG.error(errStr, e);
-                JMSException jmsEx = new JMSException(errStr);
-                jmsEx.setLinkedException(e1);
-                throw jmsEx;
+            } catch (NamingException e) {
+                try {
+                    result = session.createQueue(queueName);
+                } catch (JMSException e1) {
+                    String errStr = "Failed to look-up or create Queue for name: " + queueName;
+                    LOG.error(errStr, e);
+                    JMSException jmsEx = new JMSException(errStr);
+                    jmsEx.setLinkedException(e1);
+                    throw jmsEx;
+                }
+            }
+        } else {
+            try {
+                result = session.createQueue(queueName);
+            } catch (JMSException e) {
+                // look-up the Queue
+                try {
+                    result = (Queue)jndiOutboundTemplate.lookup(queueName, Queue.class);
+                } catch (NamingException e1) {
+                    String errStr = "Failed to look-up Queue for name: " + queueName;
+                    LOG.error(errStr, e);
+                    JMSException jmsEx = new JMSException(errStr);
+                    jmsEx.setLinkedException(e1);
+                    throw jmsEx;
+                }
             }
         }
+
         return result;
     }
-
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsTopicConnector.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsTopicConnector.java?rev=1388326&r1=1388325&r2=1388326&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsTopicConnector.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsTopicConnector.java Fri Sep 21 05:11:57 2012
@@ -20,11 +20,11 @@ import javax.jms.Connection;
 import javax.jms.Destination;
 import javax.jms.ExceptionListener;
 import javax.jms.JMSException;
+import javax.jms.Session;
 import javax.jms.Topic;
 import javax.jms.TopicConnection;
 import javax.jms.TopicConnectionFactory;
 import javax.jms.TopicSession;
-import javax.jms.Session;
 import javax.naming.NamingException;
 
 import org.slf4j.Logger;
@@ -426,18 +426,36 @@ public class JmsTopicConnector extends J
 
     protected Topic createForeignTopic(TopicSession session, String topicName) throws JMSException {
         Topic result = null;
-        try {
-            result = session.createTopic(topicName);
-        } catch (JMSException e) {
-            // look-up the Topic
+
+        if (preferJndiDestinationLookup) {
             try {
+                // look-up the Queue
                 result = (Topic)jndiOutboundTemplate.lookup(topicName, Topic.class);
-            } catch (NamingException e1) {
-                String errStr = "Failed to look-up Topic for name: " + topicName;
-                LOG.error(errStr, e);
-                JMSException jmsEx = new JMSException(errStr);
-                jmsEx.setLinkedException(e1);
-                throw jmsEx;
+            } catch (NamingException e) {
+                try {
+                    result = session.createTopic(topicName);
+                } catch (JMSException e1) {
+                    String errStr = "Failed to look-up or create Topic for name: " + topicName;
+                    LOG.error(errStr, e);
+                    JMSException jmsEx = new JMSException(errStr);
+                    jmsEx.setLinkedException(e1);
+                    throw jmsEx;
+                }
+            }
+        } else {
+            try {
+                result = session.createTopic(topicName);
+            } catch (JMSException e) {
+                // look-up the Topic
+                try {
+                    result = (Topic)jndiOutboundTemplate.lookup(topicName, Topic.class);
+                } catch (NamingException e1) {
+                    String errStr = "Failed to look-up Topic for name: " + topicName;
+                    LOG.error(errStr, e);
+                    JMSException jmsEx = new JMSException(errStr);
+                    jmsEx.setLinkedException(e1);
+                    throw jmsEx;
+                }
             }
         }
         return result;