Adding a new ActiveMQXASslContextFactory and jndi support for it
in ActiveMQSslInitialContextFactory

(cherry picked from commit 016ae05d0e)
This commit is contained in:
Christopher L. Shannon (cshannon) 2016-11-04 08:29:54 -04:00
parent ba1eab20d2
commit f9e624a487
12 changed files with 331 additions and 40 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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;
}

View File

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

View File

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

View File

@ -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

View File

@ -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.
*

View File

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