You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cs...@apache.org on 2016/11/04 12:31:40 UTC
activemq git commit: https://issues.apache.org/jira/browse/AMQ-6489
Repository: activemq
Updated Branches:
refs/heads/master 512b643f7 -> 016ae05d0
https://issues.apache.org/jira/browse/AMQ-6489
Adding a new ActiveMQXASslContextFactory and jndi support for it
in ActiveMQSslInitialContextFactory
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/016ae05d
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/016ae05d
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/016ae05d
Branch: refs/heads/master
Commit: 016ae05d0e2697fe53db276d8e6f098d2e9f6f05
Parents: 512b643
Author: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Authored: Fri Nov 4 08:29:54 2016 -0400
Committer: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Committed: Fri Nov 4 08:31:19 2016 -0400
----------------------------------------------------------------------
.../ActiveMQXASslConnectionFactory.java | 100 +++++++++++++++++++
.../jndi/ActiveMQInitialContextFactory.java | 2 +-
.../jndi/ActiveMQSslInitialContextFactory.java | 3 +-
.../ActiveMQSslConnectionFactoryTest.java | 8 +-
.../ActiveMQXASslConnectionFactoryTest.java | 27 +++++
.../ActiveMQSslConnectionFactoryTest.java | 18 ++--
.../ActiveMQXAConnectionFactoryTest.java | 55 ++++++----
.../ActiveMQXASslConnectionFactoryTest.java | 26 +++++
.../ActiveMQXASslConnectionFactoryVmTest.java | 36 +++++++
.../ActiveMQSslInitialContextFactoryTest.java | 46 +++++++--
.../apache/activemq/jndi/JNDITestSupport.java | 5 +-
.../jndi/XASslConnectionFactoryTest.java | 45 +++++++++
12 files changed, 331 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASslConnectionFactory.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASslConnectionFactory.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASslConnectionFactory.java
new file mode 100644
index 0000000..e6e5726
--- /dev/null
+++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASslConnectionFactory.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq;
+
+import java.net.URI;
+import java.util.Properties;
+
+import javax.jms.JMSException;
+import javax.jms.XAConnection;
+import javax.jms.XAConnectionFactory;
+import javax.jms.XAQueueConnection;
+import javax.jms.XAQueueConnectionFactory;
+import javax.jms.XATopicConnection;
+import javax.jms.XATopicConnectionFactory;
+
+import org.apache.activemq.management.JMSStatsImpl;
+import org.apache.activemq.transport.Transport;
+
+public class ActiveMQXASslConnectionFactory extends ActiveMQSslConnectionFactory implements XAConnectionFactory, XAQueueConnectionFactory, XATopicConnectionFactory {
+
+ public ActiveMQXASslConnectionFactory() {
+ }
+
+ public ActiveMQXASslConnectionFactory(String brokerURL) {
+ super(brokerURL);
+ }
+
+ public ActiveMQXASslConnectionFactory(URI brokerURL) {
+ super(brokerURL);
+ }
+
+ @Override
+ public XAConnection createXAConnection() throws JMSException {
+ return (XAConnection) createActiveMQConnection();
+ }
+
+ @Override
+ public XAConnection createXAConnection(String userName, String password) throws JMSException {
+ return (XAConnection) createActiveMQConnection(userName, password);
+ }
+
+ @Override
+ public XAQueueConnection createXAQueueConnection() throws JMSException {
+ return (XAQueueConnection) createActiveMQConnection();
+ }
+
+ @Override
+ public XAQueueConnection createXAQueueConnection(String userName, String password) throws JMSException {
+ return (XAQueueConnection) createActiveMQConnection(userName, password);
+ }
+
+ @Override
+ public XATopicConnection createXATopicConnection() throws JMSException {
+ return (XATopicConnection) createActiveMQConnection();
+ }
+
+ @Override
+ public XATopicConnection createXATopicConnection(String userName, String password) throws JMSException {
+ return (XATopicConnection) createActiveMQConnection(userName, password);
+ }
+
+ @Override
+ protected ActiveMQConnection createActiveMQConnection(Transport transport, JMSStatsImpl stats) throws Exception {
+ ActiveMQXAConnection connection = new ActiveMQXAConnection(transport, getClientIdGenerator(), getConnectionIdGenerator(), stats);
+ configureXAConnection(connection);
+ return connection;
+ }
+
+ private void configureXAConnection(ActiveMQXAConnection connection) {
+ connection.setXaAckMode(xaAckMode);
+ }
+
+ public int getXaAckMode() {
+ return xaAckMode;
+ }
+
+ public void setXaAckMode(int xaAckMode) {
+ this.xaAckMode = xaAckMode;
+ }
+
+ @Override
+ public void populateProperties(Properties props) {
+ super.populateProperties(props);
+ props.put("xaAckMode", Integer.toString(xaAckMode));
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java b/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java
index c0434fd..34c42d6 100644
--- a/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java
+++ b/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java
@@ -211,7 +211,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
return answer;
}
- private boolean needsXA(Hashtable environment) {
+ protected boolean needsXA(Hashtable environment) {
boolean isXA = Boolean.parseBoolean((String) environment.get("xa"));
// property not applicable to connectionfactory so remove
environment.remove("xa");
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactory.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactory.java b/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactory.java
index d13ab67..8111b17 100644
--- a/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactory.java
+++ b/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactory.java
@@ -22,6 +22,7 @@ import java.util.Properties;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ActiveMQSslConnectionFactory;
+import org.apache.activemq.ActiveMQXASslConnectionFactory;
public class ActiveMQSslInitialContextFactory extends ActiveMQInitialContextFactory {
@@ -31,7 +32,7 @@ public class ActiveMQSslInitialContextFactory extends ActiveMQInitialContextFact
*/
@Override
protected ActiveMQConnectionFactory createConnectionFactory(Hashtable environment) throws URISyntaxException {
- ActiveMQConnectionFactory answer = new ActiveMQSslConnectionFactory();
+ ActiveMQConnectionFactory answer = needsXA(environment) ? new ActiveMQXASslConnectionFactory() : new ActiveMQSslConnectionFactory();
Properties properties = new Properties();
properties.putAll(environment);
answer.setProperties(properties);
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-client/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java b/activemq-client/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
index fb03532..8b90183 100644
--- a/activemq-client/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
+++ b/activemq-client/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
@@ -114,12 +114,16 @@ public class ActiveMQSslConnectionFactoryTest {
}
protected void executeTest(String transport, String name) throws Throwable {
- executeTest(transport, name, null);
+ executeTest(transport, name, null);
+ }
+
+ protected ActiveMQSslConnectionFactory getFactory(String transport) {
+ return new ActiveMQSslConnectionFactory(transport);
}
protected void executeTest(String transport, String name, String type) throws Throwable {
try {
- ActiveMQSslConnectionFactory activeMQSslConnectionFactory = new ActiveMQSslConnectionFactory(transport);
+ ActiveMQSslConnectionFactory activeMQSslConnectionFactory = getFactory(transport);
activeMQSslConnectionFactory.setTrustStoreType(type != null ? type : activeMQSslConnectionFactory.getTrustStoreType());
activeMQSslConnectionFactory.setTrustStore(name);
activeMQSslConnectionFactory.setTrustStorePassword(TRUST_STORE_PASSWORD);
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-client/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryTest.java b/activemq-client/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryTest.java
new file mode 100644
index 0000000..38e97af
--- /dev/null
+++ b/activemq-client/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryTest.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq;
+
+public class ActiveMQXASslConnectionFactoryTest extends ActiveMQSslConnectionFactoryTest {
+
+ @Override
+ protected ActiveMQSslConnectionFactory getFactory(String transport) {
+ return new ActiveMQXASslConnectionFactory(transport);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
index cbf4af3..979f377 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
@@ -63,7 +63,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
broker = createBroker("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
// This should create the connection.
- ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
+ ActiveMQSslConnectionFactory cf = getFactory("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
connection = (ActiveMQConnection)cf.createConnection();
assertNotNull(connection);
connection.start();
@@ -76,7 +76,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
broker = createBroker("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
// This should create the connection.
- ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("failover:(tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true)");
+ ActiveMQSslConnectionFactory cf = getFactory("failover:(tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true)");
connection = (ActiveMQConnection)cf.createConnection();
assertNotNull(connection);
connection.start();
@@ -91,7 +91,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
assertNotNull(broker);
// This should create the connection.
- ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory(sslUri);
+ ActiveMQSslConnectionFactory cf = getFactory(sslUri);
cf.setTrustStore("server.keystore");
cf.setTrustStorePassword("password");
connection = (ActiveMQConnection)cf.createConnection();
@@ -109,7 +109,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
assertNotNull(broker);
// This should create the connection.
- ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4");
+ ActiveMQSslConnectionFactory cf = getFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4");
cf.setTrustStore("server.keystore");
cf.setTrustStorePassword("password");
connection = (ActiveMQConnection)cf.createConnection();
@@ -126,7 +126,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
broker = createSslBroker(sslUri);
assertNotNull(broker);
- ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4");
+ ActiveMQSslConnectionFactory cf = getFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4");
cf.setKeyAndTrustManagers(getKeyManager(), getTrustManager(), new SecureRandom());
connection = (ActiveMQConnection)cf.createConnection();
LOG.info("Created client connection");
@@ -144,7 +144,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
assertNotNull(broker);
// This should FAIL to connect, due to wrong password.
- ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory(sslUri);
+ ActiveMQSslConnectionFactory cf = getFactory(sslUri);
cf.setTrustStore("server.keystore");
cf.setTrustStorePassword("wrongPassword");
try {
@@ -166,7 +166,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
assertNotNull(broker);
// This should FAIL to connect, due to wrong password.
- ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory(sslUri);
+ ActiveMQSslConnectionFactory cf = getFactory(sslUri);
cf.setTrustStore("dummy.keystore");
cf.setTrustStorePassword("password");
try {
@@ -213,6 +213,10 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
broker.stop();
}
+ protected ActiveMQSslConnectionFactory getFactory(String uri) {
+ return new ActiveMQSslConnectionFactory(uri);
+ }
+
public static TrustManager[] getTrustManager() throws Exception {
TrustManager[] trustStoreManagers = null;
KeyStore trustedCertStore = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE);
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
index 4b89851..3055181 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
@@ -30,6 +30,7 @@ import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.TextMessage;
import javax.jms.XAConnection;
+import javax.jms.XAConnectionFactory;
import javax.jms.XAQueueConnection;
import javax.jms.XASession;
import javax.jms.XATopicConnection;
@@ -73,30 +74,37 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
}
}
+ protected ActiveMQConnectionFactory getXAConnectionFactory(String brokerUrl) {
+ return new ActiveMQXAConnectionFactory(brokerUrl);
+ }
+
+ protected ActiveMQConnectionFactory getXAConnectionFactory(URI uri) {
+ return new ActiveMQXAConnectionFactory(uri);
+ }
+
public void testCopy() throws URISyntaxException, JMSException {
- ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("vm://localhost?");
+ ActiveMQConnectionFactory cf = getXAConnectionFactory("vm://localhost?");
ActiveMQConnectionFactory copy = cf.copy();
- assertTrue("Should be an ActiveMQXAConnectionFactory", copy instanceof ActiveMQXAConnectionFactory);
+ assertTrue("Should be an ActiveMQXAConnectionFactory", copy.getClass().equals(cf.getClass()));
}
public void testUseURIToSetOptionsOnConnectionFactory() throws URISyntaxException, JMSException {
- ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(
- "vm://localhost?jms.useAsyncSend=true");
+ ActiveMQConnectionFactory cf = getXAConnectionFactory("vm://localhost?jms.useAsyncSend=true");
assertTrue(cf.isUseAsyncSend());
// the broker url have been adjusted.
assertEquals("vm://localhost", cf.getBrokerURL());
- cf = new ActiveMQXAConnectionFactory("vm://localhost?jms.useAsyncSend=false");
+ cf = getXAConnectionFactory("vm://localhost?jms.useAsyncSend=false");
assertFalse(cf.isUseAsyncSend());
// the broker url have been adjusted.
assertEquals("vm://localhost", cf.getBrokerURL());
- cf = new ActiveMQXAConnectionFactory("vm:(broker:()/localhost)?jms.useAsyncSend=true");
+ cf = getXAConnectionFactory("vm:(broker:()/localhost)?jms.useAsyncSend=true");
assertTrue(cf.isUseAsyncSend());
// the broker url have been adjusted.
assertEquals("vm:(broker:()/localhost)", cf.getBrokerURL());
- cf = new ActiveMQXAConnectionFactory(
+ cf = getXAConnectionFactory(
"vm://localhost?jms.redeliveryPolicy.maximumRedeliveries=10&" +
"jms.redeliveryPolicy.initialRedeliveryDelay=10000&" +
"jms.redeliveryPolicy.redeliveryDelay=10000&" +
@@ -113,7 +121,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
}
public void testCreateVMConnectionWithEmbdeddBroker() throws URISyntaxException, JMSException {
- ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("vm://myBroker?broker.persistent=false");
+ ActiveMQConnectionFactory cf = getXAConnectionFactory("vm://myBroker?broker.persistent=false");
// Make sure the broker is not created until the connection is
// instantiated.
assertNull(BrokerRegistry.getInstance().lookup("myBroker"));
@@ -130,7 +138,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
}
public void testGetBrokerName() throws URISyntaxException, JMSException {
- ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
+ ActiveMQConnectionFactory cf = getXAConnectionFactory("vm://localhost?broker.persistent=false");
connection = (ActiveMQConnection)cf.createConnection();
connection.start();
@@ -154,12 +162,12 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
XAConnection connection1 = null;
XAConnection connection2 = null;
try {
- ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
+ ActiveMQConnectionFactory cf1 = getXAConnectionFactory("vm://localhost?broker.persistent=false");
connection1 = (XAConnection)cf1.createConnection();
XASession session1 = connection1.createXASession();
XAResource resource1 = session1.getXAResource();
- ActiveMQXAConnectionFactory cf2 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
+ ActiveMQConnectionFactory cf2 = getXAConnectionFactory("vm://localhost?broker.persistent=false");
connection2 = (XAConnection)cf2.createConnection();
XASession session2 = connection2.createXASession();
XAResource resource2 = session2.getXAResource();
@@ -190,12 +198,12 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
XAConnection connection1 = null;
XAConnection connection2 = null;
try {
- ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false&jms.rmIdFromConnectionId=true");
+ ActiveMQConnectionFactory cf1 = getXAConnectionFactory("vm://localhost?broker.persistent=false&jms.rmIdFromConnectionId=true");
connection1 = (XAConnection)cf1.createConnection();
XASession session1 = connection1.createXASession();
XAResource resource1 = session1.getXAResource();
- ActiveMQXAConnectionFactory cf2 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
+ ActiveMQConnectionFactory cf2 = getXAConnectionFactory("vm://localhost?broker.persistent=false");
connection2 = (XAConnection)cf2.createConnection();
XASession session2 = connection2.createXASession();
XAResource resource2 = session2.getXAResource();
@@ -229,7 +237,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
XAConnection connection1 = null;
try {
- ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
+ ActiveMQConnectionFactory cf1 = getXAConnectionFactory("vm://localhost?broker.persistent=false");
connection1 = (XAConnection)cf1.createConnection();
connection1.start();
XASession session = connection1.createXASession();
@@ -272,7 +280,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
public void testConsumerCloseTransactionalSendReceive() throws Exception {
- ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
+ ActiveMQConnectionFactory cf1 = getXAConnectionFactory("vm://localhost?broker.persistent=false");
XAConnection connection1 = (XAConnection)cf1.createConnection();
connection1.start();
XASession session = connection1.createXASession();
@@ -316,7 +324,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
public void testSessionCloseTransactionalSendReceive() throws Exception {
- ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
+ ActiveMQConnectionFactory cf1 = getXAConnectionFactory("vm://localhost?broker.persistent=false");
XAConnection connection1 = (XAConnection)cf1.createConnection();
connection1.start();
XASession session = connection1.createXASession();
@@ -363,7 +371,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
broker.setPersistent(false);
broker.start();
- ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("failover:(" + broker.getTransportConnectors().get(0).getConnectUri() + ")");
+ ActiveMQConnectionFactory cf1 = getXAConnectionFactory("failover:(" + broker.getTransportConnectors().get(0).getConnectUri() + ")");
cf1.setStatsEnabled(true);
ActiveMQXAConnection xaConnection = (ActiveMQXAConnection)cf1.createConnection();
xaConnection.start();
@@ -405,7 +413,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
broker.start();
broker.waitUntilStarted();
- ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
+ ActiveMQConnectionFactory cf = getXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
XAConnection connection = (XAConnection)cf.createConnection();
connection.start();
XASession session = connection.createXASession();
@@ -429,7 +437,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
public void testExceptionAfterClose() throws Exception {
- ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
+ ActiveMQConnectionFactory cf1 = getXAConnectionFactory("vm://localhost?broker.persistent=false");
XAConnection connection1 = (XAConnection)cf1.createConnection();
connection1.start();
@@ -456,7 +464,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
broker.start();
broker.waitUntilStarted();
- ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
+ ActiveMQConnectionFactory cf = getXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
XAConnection connection = (XAConnection)cf.createConnection();
connection.start();
XASession session = connection.createXASession();
@@ -536,7 +544,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
LOG.info("connection URI is: " + connectURI);
// This should create the connection.
- ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(connectURI);
+ ActiveMQConnectionFactory cf = getXAConnectionFactory(connectURI);
Connection connection = cf.createConnection();
assertXAConnection(connection);
@@ -544,7 +552,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
assertNotNull(connection);
connection.close();
- connection = cf.createXAConnection();
+ connection = ((XAConnectionFactory)cf).createXAConnection();
assertXAConnection(connection);
@@ -566,14 +574,17 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
final byte[] bs = baos.toByteArray();
return new Xid() {
+ @Override
public int getFormatId() {
return 86;
}
+ @Override
public byte[] getGlobalTransactionId() {
return bs;
}
+ @Override
public byte[] getBranchQualifier() {
return bs;
}
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryTest.java
new file mode 100644
index 0000000..4a7af89
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryTest.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq;
+
+public class ActiveMQXASslConnectionFactoryTest extends ActiveMQSslConnectionFactoryTest {
+
+ @Override
+ protected ActiveMQSslConnectionFactory getFactory(String uri) {
+ return new ActiveMQXASslConnectionFactory(uri);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryVmTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryVmTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryVmTest.java
new file mode 100644
index 0000000..b6746bc
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXASslConnectionFactoryVmTest.java
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq;
+
+import java.net.URI;
+
+/**
+ * Test the against the VM transport
+ */
+public class ActiveMQXASslConnectionFactoryVmTest extends ActiveMQXAConnectionFactoryTest {
+
+ @Override
+ protected ActiveMQConnectionFactory getXAConnectionFactory(String brokerUrl) {
+ return new ActiveMQXASslConnectionFactory(brokerUrl);
+ }
+
+ @Override
+ protected ActiveMQConnectionFactory getXAConnectionFactory(URI uri) {
+ return new ActiveMQXASslConnectionFactory(uri);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactoryTest.java
index e2962bf..e6859a8 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactoryTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactoryTest.java
@@ -16,22 +16,49 @@
*/
package org.apache.activemq.jndi;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
+import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ActiveMQSslConnectionFactory;
+import org.apache.activemq.ActiveMQXASslConnectionFactory;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+@RunWith(Parameterized.class)
public class ActiveMQSslInitialContextFactoryTest {
protected Context context;
+ protected boolean isXa;
+
+ @Parameters(name = "isXa={0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ {true},
+ {false}
+ });
+ }
+
+ /**
+ * @param isXa
+ */
+ public ActiveMQSslInitialContextFactoryTest(boolean isXa) {
+ super();
+ this.isXa = isXa;
+ }
@Before
public void setUp() throws Exception {
@@ -46,14 +73,21 @@ public class ActiveMQSslInitialContextFactoryTest {
environment.put("connection.ConnectionFactory.trustStore", "truststore.jks");
environment.put("connection.ConnectionFactory.trustStorePassword", "test");
environment.put("connection.ConnectionFactory.trustStoreType", "JKS");
-
+ environment.put("xa", Boolean.toString(isXa));
+
context = factory.getInitialContext(environment);
assertTrue("No context created", context != null);
}
@Test
- public void testCreateConnectionFactory() throws NamingException {
- assertTrue(context.lookup("ConnectionFactory") instanceof ActiveMQSslConnectionFactory);
+ public void testCreateXaConnectionFactory() throws NamingException {
+ ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
+ assertTrue(factory instanceof ActiveMQSslConnectionFactory);
+ if (isXa) {
+ assertTrue(factory instanceof ActiveMQXASslConnectionFactory);
+ } else {
+ assertFalse(factory instanceof ActiveMQXASslConnectionFactory);
+ }
}
@Test
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java
index 13adbc4..c1d751a 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/JNDITestSupport.java
@@ -69,11 +69,14 @@ public abstract class JNDITestSupport extends TestCase {
configureEnvironment();
- InitialContextFactory factory = new ActiveMQInitialContextFactory();
+ InitialContextFactory factory = getInitialContextFactory();
context = factory.getInitialContext(environment);
assertTrue("No context created", context != null);
}
+ protected InitialContextFactory getInitialContextFactory() {
+ return new ActiveMQInitialContextFactory();
+ }
/**
* Stops all existing ActiveMQConnectionFactory in Context.
*
http://git-wip-us.apache.org/repos/asf/activemq/blob/016ae05d/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/XASslConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/XASslConnectionFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/XASslConnectionFactoryTest.java
new file mode 100644
index 0000000..9a7b1cf
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/XASslConnectionFactoryTest.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.jndi;
+
+import javax.jms.XAConnectionFactory;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+import org.apache.activemq.ActiveMQXASslConnectionFactory;
+
+public class XASslConnectionFactoryTest extends ActiveMQInitialContextFactoryTest {
+
+ public void testConnectionFactoriesIsXA() throws NamingException {
+ Object factory = context.lookup(getConnectionFactoryLookupName());
+ assertTrue("connection factory implements XA", factory instanceof XAConnectionFactory);
+ assertTrue("is always sync send", ((ActiveMQXASslConnectionFactory)factory).isAlwaysSyncSend());
+ }
+
+ @Override
+ protected void configureEnvironment() {
+ environment.put("xa", "true");
+ environment.put(Context.PROVIDER_URL, "vm://locahost?jms.alwaysSyncSend=true");
+ super.configureEnvironment();
+ }
+
+ @Override
+ protected InitialContextFactory getInitialContextFactory() {
+ return new ActiveMQSslInitialContextFactory();
+ }
+}