diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java index 09af08c85b..eb0c4fe97b 100644 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java @@ -104,9 +104,9 @@ public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory { if (keyStore != null || trustStore != null) { keyManager = createKeyManager(); trustManager = createTrustManager(); - if (keyManager != null || trustManager != null) { - SslContext.setCurrentSslContext(new SslContext(keyManager, trustManager, secureRandom)); - } + } + if (keyManager != null || trustManager != null) { + SslContext.setCurrentSslContext(new SslContext(keyManager, trustManager, secureRandom)); } return super.createTransport(); } catch (Exception e) { diff --git a/activemq-core/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java b/activemq-core/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java index 641fa93d4d..77405f85a6 100644 --- a/activemq-core/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java @@ -25,6 +25,7 @@ import java.io.ObjectOutputStream; import java.net.URI; import java.net.URISyntaxException; import java.security.KeyStore; +import java.security.SecureRandom; import javax.jms.ExceptionListener; import javax.jms.JMSException; @@ -129,6 +130,22 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { brokerStop(); } + public void testFailoverSslConnectionWithKeyAndTrustManagers() throws Exception { + String sslUri = "ssl://localhost:61611"; + broker = createSslBroker(sslUri); + assertNotNull(broker); + + ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4"); + cf.setKeyAndTrustManagers(getKeyManager(), getTrustManager(), new SecureRandom()); + connection = (ActiveMQConnection)cf.createConnection(); + LOG.info("Created client connection"); + assertNotNull(connection); + connection.start(); + connection.stop(); + + brokerStop(); + } + public void testNegativeCreateSslConnectionWithWrongPassword() throws Exception { // Create SSL/TLS connection with trusted cert from truststore. String sslUri = "ssl://localhost:61611";