mirror of https://github.com/apache/activemq.git
Adding a new ActiveMQXASslContextFactory and jndi support for it
in ActiveMQSslInitialContextFactory
(cherry picked from commit 016ae05d0e
)
This commit is contained in:
parent
ba1eab20d2
commit
f9e624a487
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -211,7 +211,7 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory {
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean needsXA(Hashtable environment) {
|
protected boolean needsXA(Hashtable environment) {
|
||||||
boolean isXA = Boolean.parseBoolean((String) environment.get("xa"));
|
boolean isXA = Boolean.parseBoolean((String) environment.get("xa"));
|
||||||
// property not applicable to connectionfactory so remove
|
// property not applicable to connectionfactory so remove
|
||||||
environment.remove("xa");
|
environment.remove("xa");
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.ActiveMQSslConnectionFactory;
|
import org.apache.activemq.ActiveMQSslConnectionFactory;
|
||||||
|
import org.apache.activemq.ActiveMQXASslConnectionFactory;
|
||||||
|
|
||||||
public class ActiveMQSslInitialContextFactory extends ActiveMQInitialContextFactory {
|
public class ActiveMQSslInitialContextFactory extends ActiveMQInitialContextFactory {
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ public class ActiveMQSslInitialContextFactory extends ActiveMQInitialContextFact
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected ActiveMQConnectionFactory createConnectionFactory(Hashtable environment) throws URISyntaxException {
|
protected ActiveMQConnectionFactory createConnectionFactory(Hashtable environment) throws URISyntaxException {
|
||||||
ActiveMQConnectionFactory answer = new ActiveMQSslConnectionFactory();
|
ActiveMQConnectionFactory answer = needsXA(environment) ? new ActiveMQXASslConnectionFactory() : new ActiveMQSslConnectionFactory();
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.putAll(environment);
|
properties.putAll(environment);
|
||||||
answer.setProperties(properties);
|
answer.setProperties(properties);
|
||||||
|
|
|
@ -114,12 +114,16 @@ public class ActiveMQSslConnectionFactoryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void executeTest(String transport, String name) throws Throwable {
|
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 {
|
protected void executeTest(String transport, String name, String type) throws Throwable {
|
||||||
try {
|
try {
|
||||||
ActiveMQSslConnectionFactory activeMQSslConnectionFactory = new ActiveMQSslConnectionFactory(transport);
|
ActiveMQSslConnectionFactory activeMQSslConnectionFactory = getFactory(transport);
|
||||||
activeMQSslConnectionFactory.setTrustStoreType(type != null ? type : activeMQSslConnectionFactory.getTrustStoreType());
|
activeMQSslConnectionFactory.setTrustStoreType(type != null ? type : activeMQSslConnectionFactory.getTrustStoreType());
|
||||||
activeMQSslConnectionFactory.setTrustStore(name);
|
activeMQSslConnectionFactory.setTrustStore(name);
|
||||||
activeMQSslConnectionFactory.setTrustStorePassword(TRUST_STORE_PASSWORD);
|
activeMQSslConnectionFactory.setTrustStorePassword(TRUST_STORE_PASSWORD);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -63,7 +63,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
broker = createBroker("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
|
broker = createBroker("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
|
||||||
|
|
||||||
// This should create the connection.
|
// 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();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
assertNotNull(connection);
|
assertNotNull(connection);
|
||||||
connection.start();
|
connection.start();
|
||||||
|
@ -76,7 +76,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
broker = createBroker("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
|
broker = createBroker("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
|
||||||
|
|
||||||
// This should create the connection.
|
// 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();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
assertNotNull(connection);
|
assertNotNull(connection);
|
||||||
connection.start();
|
connection.start();
|
||||||
|
@ -91,7 +91,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
assertNotNull(broker);
|
assertNotNull(broker);
|
||||||
|
|
||||||
// This should create the connection.
|
// This should create the connection.
|
||||||
ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory(sslUri);
|
ActiveMQSslConnectionFactory cf = getFactory(sslUri);
|
||||||
cf.setTrustStore("server.keystore");
|
cf.setTrustStore("server.keystore");
|
||||||
cf.setTrustStorePassword("password");
|
cf.setTrustStorePassword("password");
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
|
@ -109,7 +109,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
assertNotNull(broker);
|
assertNotNull(broker);
|
||||||
|
|
||||||
// This should create the connection.
|
// 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.setTrustStore("server.keystore");
|
||||||
cf.setTrustStorePassword("password");
|
cf.setTrustStorePassword("password");
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
|
@ -126,7 +126,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
broker = createSslBroker(sslUri);
|
broker = createSslBroker(sslUri);
|
||||||
assertNotNull(broker);
|
assertNotNull(broker);
|
||||||
|
|
||||||
ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4");
|
ActiveMQSslConnectionFactory cf = getFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4");
|
||||||
cf.setKeyAndTrustManagers(getKeyManager(), getTrustManager(), new SecureRandom());
|
cf.setKeyAndTrustManagers(getKeyManager(), getTrustManager(), new SecureRandom());
|
||||||
connection = (ActiveMQConnection)cf.createConnection();
|
connection = (ActiveMQConnection)cf.createConnection();
|
||||||
LOG.info("Created client connection");
|
LOG.info("Created client connection");
|
||||||
|
@ -144,7 +144,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
assertNotNull(broker);
|
assertNotNull(broker);
|
||||||
|
|
||||||
// This should FAIL to connect, due to wrong password.
|
// This should FAIL to connect, due to wrong password.
|
||||||
ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory(sslUri);
|
ActiveMQSslConnectionFactory cf = getFactory(sslUri);
|
||||||
cf.setTrustStore("server.keystore");
|
cf.setTrustStore("server.keystore");
|
||||||
cf.setTrustStorePassword("wrongPassword");
|
cf.setTrustStorePassword("wrongPassword");
|
||||||
try {
|
try {
|
||||||
|
@ -166,7 +166,7 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
assertNotNull(broker);
|
assertNotNull(broker);
|
||||||
|
|
||||||
// This should FAIL to connect, due to wrong password.
|
// This should FAIL to connect, due to wrong password.
|
||||||
ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory(sslUri);
|
ActiveMQSslConnectionFactory cf = getFactory(sslUri);
|
||||||
cf.setTrustStore("dummy.keystore");
|
cf.setTrustStore("dummy.keystore");
|
||||||
cf.setTrustStorePassword("password");
|
cf.setTrustStorePassword("password");
|
||||||
try {
|
try {
|
||||||
|
@ -213,6 +213,10 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
|
||||||
broker.stop();
|
broker.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ActiveMQSslConnectionFactory getFactory(String uri) {
|
||||||
|
return new ActiveMQSslConnectionFactory(uri);
|
||||||
|
}
|
||||||
|
|
||||||
public static TrustManager[] getTrustManager() throws Exception {
|
public static TrustManager[] getTrustManager() throws Exception {
|
||||||
TrustManager[] trustStoreManagers = null;
|
TrustManager[] trustStoreManagers = null;
|
||||||
KeyStore trustedCertStore = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE);
|
KeyStore trustedCertStore = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE);
|
||||||
|
|
|
@ -30,6 +30,7 @@ import javax.jms.MessageConsumer;
|
||||||
import javax.jms.MessageProducer;
|
import javax.jms.MessageProducer;
|
||||||
import javax.jms.TextMessage;
|
import javax.jms.TextMessage;
|
||||||
import javax.jms.XAConnection;
|
import javax.jms.XAConnection;
|
||||||
|
import javax.jms.XAConnectionFactory;
|
||||||
import javax.jms.XAQueueConnection;
|
import javax.jms.XAQueueConnection;
|
||||||
import javax.jms.XASession;
|
import javax.jms.XASession;
|
||||||
import javax.jms.XATopicConnection;
|
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 {
|
public void testCopy() throws URISyntaxException, JMSException {
|
||||||
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("vm://localhost?");
|
ActiveMQConnectionFactory cf = getXAConnectionFactory("vm://localhost?");
|
||||||
ActiveMQConnectionFactory copy = cf.copy();
|
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 {
|
public void testUseURIToSetOptionsOnConnectionFactory() throws URISyntaxException, JMSException {
|
||||||
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(
|
ActiveMQConnectionFactory cf = getXAConnectionFactory("vm://localhost?jms.useAsyncSend=true");
|
||||||
"vm://localhost?jms.useAsyncSend=true");
|
|
||||||
assertTrue(cf.isUseAsyncSend());
|
assertTrue(cf.isUseAsyncSend());
|
||||||
// the broker url have been adjusted.
|
// the broker url have been adjusted.
|
||||||
assertEquals("vm://localhost", cf.getBrokerURL());
|
assertEquals("vm://localhost", cf.getBrokerURL());
|
||||||
|
|
||||||
cf = new ActiveMQXAConnectionFactory("vm://localhost?jms.useAsyncSend=false");
|
cf = getXAConnectionFactory("vm://localhost?jms.useAsyncSend=false");
|
||||||
assertFalse(cf.isUseAsyncSend());
|
assertFalse(cf.isUseAsyncSend());
|
||||||
// the broker url have been adjusted.
|
// the broker url have been adjusted.
|
||||||
assertEquals("vm://localhost", cf.getBrokerURL());
|
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());
|
assertTrue(cf.isUseAsyncSend());
|
||||||
// the broker url have been adjusted.
|
// the broker url have been adjusted.
|
||||||
assertEquals("vm:(broker:()/localhost)", cf.getBrokerURL());
|
assertEquals("vm:(broker:()/localhost)", cf.getBrokerURL());
|
||||||
|
|
||||||
cf = new ActiveMQXAConnectionFactory(
|
cf = getXAConnectionFactory(
|
||||||
"vm://localhost?jms.redeliveryPolicy.maximumRedeliveries=10&" +
|
"vm://localhost?jms.redeliveryPolicy.maximumRedeliveries=10&" +
|
||||||
"jms.redeliveryPolicy.initialRedeliveryDelay=10000&" +
|
"jms.redeliveryPolicy.initialRedeliveryDelay=10000&" +
|
||||||
"jms.redeliveryPolicy.redeliveryDelay=10000&" +
|
"jms.redeliveryPolicy.redeliveryDelay=10000&" +
|
||||||
|
@ -113,7 +121,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateVMConnectionWithEmbdeddBroker() throws URISyntaxException, JMSException {
|
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
|
// Make sure the broker is not created until the connection is
|
||||||
// instantiated.
|
// instantiated.
|
||||||
assertNull(BrokerRegistry.getInstance().lookup("myBroker"));
|
assertNull(BrokerRegistry.getInstance().lookup("myBroker"));
|
||||||
|
@ -130,7 +138,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetBrokerName() throws URISyntaxException, JMSException {
|
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 = (ActiveMQConnection)cf.createConnection();
|
||||||
connection.start();
|
connection.start();
|
||||||
|
|
||||||
|
@ -154,12 +162,12 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
XAConnection connection1 = null;
|
XAConnection connection1 = null;
|
||||||
XAConnection connection2 = null;
|
XAConnection connection2 = null;
|
||||||
try {
|
try {
|
||||||
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
|
ActiveMQConnectionFactory cf1 = getXAConnectionFactory("vm://localhost?broker.persistent=false");
|
||||||
connection1 = (XAConnection)cf1.createConnection();
|
connection1 = (XAConnection)cf1.createConnection();
|
||||||
XASession session1 = connection1.createXASession();
|
XASession session1 = connection1.createXASession();
|
||||||
XAResource resource1 = session1.getXAResource();
|
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();
|
connection2 = (XAConnection)cf2.createConnection();
|
||||||
XASession session2 = connection2.createXASession();
|
XASession session2 = connection2.createXASession();
|
||||||
XAResource resource2 = session2.getXAResource();
|
XAResource resource2 = session2.getXAResource();
|
||||||
|
@ -190,12 +198,12 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
XAConnection connection1 = null;
|
XAConnection connection1 = null;
|
||||||
XAConnection connection2 = null;
|
XAConnection connection2 = null;
|
||||||
try {
|
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();
|
connection1 = (XAConnection)cf1.createConnection();
|
||||||
XASession session1 = connection1.createXASession();
|
XASession session1 = connection1.createXASession();
|
||||||
XAResource resource1 = session1.getXAResource();
|
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();
|
connection2 = (XAConnection)cf2.createConnection();
|
||||||
XASession session2 = connection2.createXASession();
|
XASession session2 = connection2.createXASession();
|
||||||
XAResource resource2 = session2.getXAResource();
|
XAResource resource2 = session2.getXAResource();
|
||||||
|
@ -229,7 +237,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
|
|
||||||
XAConnection connection1 = null;
|
XAConnection connection1 = null;
|
||||||
try {
|
try {
|
||||||
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
|
ActiveMQConnectionFactory cf1 = getXAConnectionFactory("vm://localhost?broker.persistent=false");
|
||||||
connection1 = (XAConnection)cf1.createConnection();
|
connection1 = (XAConnection)cf1.createConnection();
|
||||||
connection1.start();
|
connection1.start();
|
||||||
XASession session = connection1.createXASession();
|
XASession session = connection1.createXASession();
|
||||||
|
@ -272,7 +280,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
|
|
||||||
public void testConsumerCloseTransactionalSendReceive() throws Exception {
|
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();
|
XAConnection connection1 = (XAConnection)cf1.createConnection();
|
||||||
connection1.start();
|
connection1.start();
|
||||||
XASession session = connection1.createXASession();
|
XASession session = connection1.createXASession();
|
||||||
|
@ -316,7 +324,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
|
|
||||||
public void testSessionCloseTransactionalSendReceive() throws Exception {
|
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();
|
XAConnection connection1 = (XAConnection)cf1.createConnection();
|
||||||
connection1.start();
|
connection1.start();
|
||||||
XASession session = connection1.createXASession();
|
XASession session = connection1.createXASession();
|
||||||
|
@ -363,7 +371,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
|
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
|
||||||
broker.setPersistent(false);
|
broker.setPersistent(false);
|
||||||
broker.start();
|
broker.start();
|
||||||
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("failover:(" + broker.getTransportConnectors().get(0).getConnectUri() + ")");
|
ActiveMQConnectionFactory cf1 = getXAConnectionFactory("failover:(" + broker.getTransportConnectors().get(0).getConnectUri() + ")");
|
||||||
cf1.setStatsEnabled(true);
|
cf1.setStatsEnabled(true);
|
||||||
ActiveMQXAConnection xaConnection = (ActiveMQXAConnection)cf1.createConnection();
|
ActiveMQXAConnection xaConnection = (ActiveMQXAConnection)cf1.createConnection();
|
||||||
xaConnection.start();
|
xaConnection.start();
|
||||||
|
@ -405,7 +413,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
|
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
|
||||||
broker.start();
|
broker.start();
|
||||||
broker.waitUntilStarted();
|
broker.waitUntilStarted();
|
||||||
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
|
ActiveMQConnectionFactory cf = getXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
|
||||||
XAConnection connection = (XAConnection)cf.createConnection();
|
XAConnection connection = (XAConnection)cf.createConnection();
|
||||||
connection.start();
|
connection.start();
|
||||||
XASession session = connection.createXASession();
|
XASession session = connection.createXASession();
|
||||||
|
@ -429,7 +437,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
|
|
||||||
public void testExceptionAfterClose() throws Exception {
|
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();
|
XAConnection connection1 = (XAConnection)cf1.createConnection();
|
||||||
connection1.start();
|
connection1.start();
|
||||||
|
|
||||||
|
@ -456,7 +464,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
|
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
|
||||||
broker.start();
|
broker.start();
|
||||||
broker.waitUntilStarted();
|
broker.waitUntilStarted();
|
||||||
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
|
ActiveMQConnectionFactory cf = getXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
|
||||||
XAConnection connection = (XAConnection)cf.createConnection();
|
XAConnection connection = (XAConnection)cf.createConnection();
|
||||||
connection.start();
|
connection.start();
|
||||||
XASession session = connection.createXASession();
|
XASession session = connection.createXASession();
|
||||||
|
@ -536,7 +544,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
LOG.info("connection URI is: " + connectURI);
|
LOG.info("connection URI is: " + connectURI);
|
||||||
|
|
||||||
// This should create the connection.
|
// This should create the connection.
|
||||||
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(connectURI);
|
ActiveMQConnectionFactory cf = getXAConnectionFactory(connectURI);
|
||||||
Connection connection = cf.createConnection();
|
Connection connection = cf.createConnection();
|
||||||
|
|
||||||
assertXAConnection(connection);
|
assertXAConnection(connection);
|
||||||
|
@ -544,7 +552,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
assertNotNull(connection);
|
assertNotNull(connection);
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
connection = cf.createXAConnection();
|
connection = ((XAConnectionFactory)cf).createXAConnection();
|
||||||
|
|
||||||
assertXAConnection(connection);
|
assertXAConnection(connection);
|
||||||
|
|
||||||
|
@ -566,14 +574,17 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
|
||||||
final byte[] bs = baos.toByteArray();
|
final byte[] bs = baos.toByteArray();
|
||||||
|
|
||||||
return new Xid() {
|
return new Xid() {
|
||||||
|
@Override
|
||||||
public int getFormatId() {
|
public int getFormatId() {
|
||||||
return 86;
|
return 86;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public byte[] getGlobalTransactionId() {
|
public byte[] getGlobalTransactionId() {
|
||||||
return bs;
|
return bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public byte[] getBranchQualifier() {
|
public byte[] getBranchQualifier() {
|
||||||
return bs;
|
return bs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,22 +16,49 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.jndi;
|
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 java.util.Hashtable;
|
||||||
|
|
||||||
import javax.naming.Context;
|
import javax.naming.Context;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
import javax.naming.spi.InitialContextFactory;
|
import javax.naming.spi.InitialContextFactory;
|
||||||
|
|
||||||
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.ActiveMQSslConnectionFactory;
|
import org.apache.activemq.ActiveMQSslConnectionFactory;
|
||||||
|
import org.apache.activemq.ActiveMQXASslConnectionFactory;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertTrue;
|
import org.junit.runner.RunWith;
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.junit.runners.Parameterized;
|
||||||
import static org.junit.Assert.fail;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
public class ActiveMQSslInitialContextFactoryTest {
|
public class ActiveMQSslInitialContextFactoryTest {
|
||||||
|
|
||||||
protected Context context;
|
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
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
@ -46,14 +73,21 @@ public class ActiveMQSslInitialContextFactoryTest {
|
||||||
environment.put("connection.ConnectionFactory.trustStore", "truststore.jks");
|
environment.put("connection.ConnectionFactory.trustStore", "truststore.jks");
|
||||||
environment.put("connection.ConnectionFactory.trustStorePassword", "test");
|
environment.put("connection.ConnectionFactory.trustStorePassword", "test");
|
||||||
environment.put("connection.ConnectionFactory.trustStoreType", "JKS");
|
environment.put("connection.ConnectionFactory.trustStoreType", "JKS");
|
||||||
|
environment.put("xa", Boolean.toString(isXa));
|
||||||
|
|
||||||
context = factory.getInitialContext(environment);
|
context = factory.getInitialContext(environment);
|
||||||
assertTrue("No context created", context != null);
|
assertTrue("No context created", context != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateConnectionFactory() throws NamingException {
|
public void testCreateXaConnectionFactory() throws NamingException {
|
||||||
assertTrue(context.lookup("ConnectionFactory") instanceof ActiveMQSslConnectionFactory);
|
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
|
||||||
|
assertTrue(factory instanceof ActiveMQSslConnectionFactory);
|
||||||
|
if (isXa) {
|
||||||
|
assertTrue(factory instanceof ActiveMQXASslConnectionFactory);
|
||||||
|
} else {
|
||||||
|
assertFalse(factory instanceof ActiveMQXASslConnectionFactory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -69,11 +69,14 @@ public abstract class JNDITestSupport extends TestCase {
|
||||||
|
|
||||||
configureEnvironment();
|
configureEnvironment();
|
||||||
|
|
||||||
InitialContextFactory factory = new ActiveMQInitialContextFactory();
|
InitialContextFactory factory = getInitialContextFactory();
|
||||||
context = factory.getInitialContext(environment);
|
context = factory.getInitialContext(environment);
|
||||||
assertTrue("No context created", context != null);
|
assertTrue("No context created", context != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected InitialContextFactory getInitialContextFactory() {
|
||||||
|
return new ActiveMQInitialContextFactory();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Stops all existing ActiveMQConnectionFactory in Context.
|
* Stops all existing ActiveMQConnectionFactory in Context.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue