qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject [01/13] qpid-jms git commit: rework factory definition to 'connectionfactory.lookup = uri', only pass through properties specific to that factory
Date Fri, 30 Jan 2015 17:15:22 GMT
Repository: qpid-jms
Updated Branches:
  refs/heads/master 5e219b819 -> dba3f1a38


rework factory definition to 'connectionfactory.lookup = uri', only pass through properties
specific to that factory


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/47a83bc7
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/47a83bc7
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/47a83bc7

Branch: refs/heads/master
Commit: 47a83bc7d4908a8e702595a4c1329af7184bbeff
Parents: 5e219b8
Author: Robert Gemmell <robbie@apache.org>
Authored: Fri Jan 30 10:38:02 2015 +0000
Committer: Robert Gemmell <robbie@apache.org>
Committed: Fri Jan 30 10:38:02 2015 +0000

----------------------------------------------------------------------
 .../apache/qpid/jms/JmsConnectionFactory.java   |  3 +-
 .../qpid/jms/jndi/JmsInitialContextFactory.java | 76 ++++++++------------
 .../jms/jndi/JmsInitialContextFactoryTest.java  | 17 +++++
 3 files changed, 47 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/47a83bc7/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java
index b44474c..789f2ae 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java
@@ -49,7 +49,8 @@ public class JmsConnectionFactory extends JNDIStorable implements ConnectionFact
 
     private static final Logger LOG = LoggerFactory.getLogger(JmsConnectionFactory.class);
     private static final String CLIENT_ID_PROP = "clientID";
-    private static final String REMOTE_URI_PROP = "remoteURI";
+
+    public static final String REMOTE_URI_PROP = "remoteURI";
 
     private URI remoteURI;
     private String username;

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/47a83bc7/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
b/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
index 3d2a771..4cc450e 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
@@ -18,13 +18,13 @@ package org.apache.qpid.jms.jndi;
 
 import java.net.URISyntaxException;
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Arrays;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.StringTokenizer;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jms.Queue;
@@ -92,15 +92,14 @@ public class JmsInitialContextFactory implements InitialContextFactory
{
     }
 
     private void createConnectionFactories(Hashtable<Object, Object> environment, Map<String,
Object> bindings) throws NamingException {
-        String[] names = getConnectionFactoryNames(environment);
-        for (int i = 0; i < names.length; i++) {
+        List<String> names = getConnectionFactoryNames(environment);
+        for (String name : names) {
             JmsConnectionFactory factory = null;
-            String name = names[i];
 
             try {
                 factory = createConnectionFactory(name, environment);
             } catch (Exception e) {
-                throw new NamingException("Invalid broker URL");
+                throw new NamingException("Invalid ConnectionFactory definition");
             }
 
             bindings.put(name, factory);
@@ -115,36 +114,33 @@ public class JmsInitialContextFactory implements InitialContextFactory
{
     }
 
     protected JmsConnectionFactory createConnectionFactory(String name, Hashtable<Object,
Object> environment) throws URISyntaxException {
-        Hashtable<Object, Object> temp = new Hashtable<Object, Object>(environment);
-        String prefix = connectionFactoryPrefix + name + ".";
+        String cfNameKey = connectionFactoryPrefix + name;
+        Map<String, String> props = new LinkedHashMap<String, String>();
+
+        props.put(JmsConnectionFactory.REMOTE_URI_PROP, String.valueOf(environment.get(cfNameKey)));
+
+        //TODO: support gathering up any other per-factory properties from the environment
+
+        return createConnectionFactory(props);
+    }
+
+    protected List<String> getConnectionFactoryNames(Map<Object, Object> environment)
{
+        List<String> list = new ArrayList<String>();
         for (Iterator<Entry<Object, Object>> iter = environment.entrySet().iterator();
iter.hasNext();) {
             Map.Entry<Object, Object> entry = iter.next();
-            String key = (String) entry.getKey();
-            if (key.startsWith(prefix)) {
-                // Rename the key...
-                temp.remove(key);
-                key = key.substring(prefix.length());
-                temp.put(key, entry.getValue());
+            String key = String.valueOf(entry.getKey());
+            if (key.startsWith(connectionFactoryPrefix)) {
+                String jndiName = key.substring(connectionFactoryPrefix.length());
+                list.add(jndiName);
             }
         }
-        return createConnectionFactory(temp);
-    }
 
-    protected String[] getConnectionFactoryNames(Map<Object, Object> environment) {
-        String factoryNames = (String) environment.get("factories");
-        if (factoryNames != null) {
-            List<String> list = new ArrayList<String>();
-            for (StringTokenizer enumeration = new StringTokenizer(factoryNames, ","); enumeration.hasMoreTokens();)
{
-                list.add(enumeration.nextToken().trim());
-            }
-            int size = list.size();
-            if (size > 0) {
-                String[] answer = new String[size];
-                list.toArray(answer);
-                return answer;
-            }
+        if(list.isEmpty())
+        {
+            list.addAll(Arrays.asList(DEFAULT_CONNECTION_FACTORY_NAMES));
         }
-        return DEFAULT_CONNECTION_FACTORY_NAMES;
+
+        return list;
     }
 
     protected void createQueues(Hashtable<Object, Object> environment, Map<String,
Object> bindings) {
@@ -184,27 +180,11 @@ public class JmsInitialContextFactory implements InitialContextFactory
{
     }
 
     /**
-     * Factory method to create a new connection factory from the given
-     * environment
+     * Factory method to create a new connection factory using the given properties
      */
-    protected JmsConnectionFactory createConnectionFactory(Hashtable<Object,Object>
environment) throws URISyntaxException {
-        Map<String, String> properties = toMap(environment);
-
-        // Remove naming-related properties which relate to the
-        // InitialContextFactory implementation itself
-        properties.remove(Context.INITIAL_CONTEXT_FACTORY);
-        properties.remove(Context.PROVIDER_URL);
-
+    protected JmsConnectionFactory createConnectionFactory(Map<String, String> properties)
throws URISyntaxException {
         JmsConnectionFactory factory = new JmsConnectionFactory();
         factory.setProperties(properties);
         return factory;
     }
-
-    public Map<String, String> toMap(Hashtable<Object, Object> props) {
-        Map<String, String> map = new HashMap<String, String>();
-        for (Map.Entry<Object, Object> entry : props.entrySet()) {
-            map.put(entry.getKey().toString(), entry.getValue().toString());
-        }
-        return map;
-    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/47a83bc7/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
index 64a0925..9042d74 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
@@ -24,6 +24,7 @@ import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.naming.OperationNotSupportedException;
 
+import org.apache.qpid.jms.JmsConnectionFactory;
 import org.apache.qpid.jms.JmsQueue;
 import org.apache.qpid.jms.JmsTopic;
 import org.apache.qpid.jms.test.QpidJmsTestCase;
@@ -43,6 +44,22 @@ public class JmsInitialContextFactoryTest extends QpidJmsTestCase {
     }
 
     @Test
+    public void testConnectionFactoryBinding() throws Exception {
+        String factoryName = "myNewFactory";
+        String uri = "amqp://example.com:1234";
+
+        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+        env.put("connectionfactory." + factoryName, uri);
+        Context ctx = createInitialContext(env);
+
+        Object o = ctx.lookup(factoryName);
+
+        assertNotNull("No object returned", o);
+        assertEquals("Unexpected class type for returned object", JmsConnectionFactory.class,
o.getClass());
+        assertEquals("Unexpected URI for returned factory", ((JmsConnectionFactory) o).getRemoteURI(),
uri);
+    }
+
+    @Test
     public void testQueueBinding() throws Exception {
         String lookupName = "myLookupName";
         String actualName = "myQueueName";


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message