From 75bd4f243a19a807df8077d0901a5428969efa4e Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Wed, 11 Jul 2012 11:36:20 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-2656 - add wellknown xa factory name, XAConnectionFactory so that context.lookup("XAConnectionFactory") will work as expected out of the box git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1360125 13f79535-47bb-0310-9956-ffa450edef68 --- .../jndi/ActiveMQInitialContextFactory.java | 6 +++++- .../apache/activemq/jndi/InitialContextTest.java | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java b/activemq-core/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java index 896e42988f..a3b74194a7 100755 --- a/activemq-core/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java @@ -48,7 +48,7 @@ import org.apache.activemq.command.ActiveMQTopic; */ public class ActiveMQInitialContextFactory implements InitialContextFactory { - private static final String[] DEFAULT_CONNECTION_FACTORY_NAMES = {"ConnectionFactory", "QueueConnectionFactory", "TopicConnectionFactory"}; + private static final String[] DEFAULT_CONNECTION_FACTORY_NAMES = {"ConnectionFactory", "XAConnectionFactory", "QueueConnectionFactory", "TopicConnectionFactory"}; private String connectionPrefix = "connection."; private String queuePrefix = "queue."; @@ -127,6 +127,10 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory { protected ActiveMQConnectionFactory createConnectionFactory(String name, Hashtable environment) throws URISyntaxException { Hashtable temp = new Hashtable(environment); + if (DEFAULT_CONNECTION_FACTORY_NAMES[1].equals(name)) { + // don't try to mod environment, it may be readonly + temp.put("xa", String.valueOf(true)); + } String prefix = connectionPrefix + name + "."; for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry)iter.next(); diff --git a/activemq-core/src/test/java/org/apache/activemq/jndi/InitialContextTest.java b/activemq-core/src/test/java/org/apache/activemq/jndi/InitialContextTest.java index 7c4695ae21..2c983a5a36 100755 --- a/activemq-core/src/test/java/org/apache/activemq/jndi/InitialContextTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/jndi/InitialContextTest.java @@ -23,6 +23,7 @@ import javax.naming.InitialContext; import junit.framework.TestCase; import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.ActiveMQXAConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,6 +46,18 @@ public class InitialContextTest extends TestCase { } + public void testInitialContextHasXA() throws Exception { + InitialContext context = new InitialContext(); + assertTrue("Created context", context != null); + + ActiveMQXAConnectionFactory connectionFactory = (ActiveMQXAConnectionFactory)context.lookup("XAConnectionFactory"); + + assertTrue("Should have created an XAConnectionFactory", connectionFactory != null); + + LOG.info("Created with brokerURL: " + connectionFactory.getBrokerURL()); + + } + public void testUsingStandardJNDIKeys() throws Exception { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");