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
This commit is contained in:
Gary Tully 2012-07-11 11:36:20 +00:00
parent 97ac8e22df
commit 75bd4f243a
2 changed files with 18 additions and 1 deletions

View File

@ -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();

View File

@ -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");