From e49f5d9ff85f833bd3a400bd82f0a4cf7c7a10a4 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Fri, 17 Aug 2012 12:55:35 +0000 Subject: [PATCH] fix for: https://issues.apache.org/jira/browse/AMQ-3981 Remove the commons log reference and unused logger. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1374231 13f79535-47bb-0310-9956-ffa450edef68 --- .../ActiveMQSslConnectionFactory.java | 90 +++++++++---------- 1 file changed, 44 insertions(+), 46 deletions(-) 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 8b259401bb..09af08c85b 100644 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java @@ -21,12 +21,12 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.security.KeyStore; - import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.security.KeyStore; import java.security.SecureRandom; + import javax.jms.JMSException; import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; @@ -36,8 +36,6 @@ import javax.net.ssl.TrustManagerFactory; import org.apache.activemq.broker.SslContext; import org.apache.activemq.transport.Transport; import org.apache.activemq.util.JMSExceptionSupport; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * An ActiveMQConnectionFactory that allows access to the key and trust managers @@ -45,19 +43,19 @@ import org.apache.commons.logging.LogFactory; * being used AND the key and trust managers need to be specified from within * code. In fact, if the URI passed to this class does not have an "ssl" scheme, * this class will pass all work on to its superclass. - * + * * There are two alternative approaches you can use to provide X.509 certificates * for the SSL connections: - * + * * Call setTrustStore, setTrustStorePassword, setKeyStore, * and setKeyStorePassword. - * + * * Call setKeyAndTrustManagers. - * + * * @author sepandm@gmail.com */ public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory { - private static final Log LOG = LogFactory.getLog(ActiveMQSslConnectionFactory.class); + // The key and trust managers used to initialize the used SSLContext. protected KeyManager[] keyManager; protected TrustManager[] trustManager; @@ -81,7 +79,7 @@ public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory { /** * Sets the key and trust managers used when creating SSL connections. - * + * * @param km The KeyManagers used. * @param tm The TrustManagers used. * @param random The SecureRandom number used. @@ -97,7 +95,7 @@ public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory { * not using SSL, the superclass's method is called. If we are using SSL, an * SslConnectionFactory is used and it is given the needed key and trust * managers. - * + * * @author sepandm@gmail.com */ protected Transport createTransport() throws JMSException { @@ -132,12 +130,12 @@ public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory { tmf.init(trustedCertStore); trustStoreManagers = tmf.getTrustManagers(); } - return trustStoreManagers; + return trustStoreManagers; } protected KeyManager[] createKeyManager() throws Exception { - KeyManagerFactory kmf = - KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + KeyManagerFactory kmf = + KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); KeyStore ks = KeyStore.getInstance("jks"); KeyManager[] keystoreManagers = null; if (keyStore != null) { @@ -150,7 +148,7 @@ public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory { keystoreManagers = kmf.getKeyManagers(); } } - return keystoreManagers; + return keystoreManagers; } protected byte[] loadClientCredential(String fileName) throws IOException { @@ -168,79 +166,79 @@ public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory { in.close(); return out.toByteArray(); } - + protected InputStream getUrlOrResourceAsStream(String urlOrResource) throws IOException { - InputStream ins = null; - try { - URL url = new URL(urlOrResource); - ins = url.openStream(); - } - catch (MalformedURLException ignore) { - ins = null; - } - - // Alternatively, treat as classpath resource - if (ins == null) { - ins = getClass().getClassLoader().getResourceAsStream(urlOrResource); - } - - if (ins == null) { + InputStream ins = null; + try { + URL url = new URL(urlOrResource); + ins = url.openStream(); + } + catch (MalformedURLException ignore) { + ins = null; + } + + // Alternatively, treat as classpath resource + if (ins == null) { + ins = getClass().getClassLoader().getResourceAsStream(urlOrResource); + } + + if (ins == null) { throw new java.io.IOException("Could not load resource: " + urlOrResource); - } - - return ins; + } + + return ins; } - + public String getTrustStore() { return trustStore; } - + /** * The location of a keystore file (in jks format) containing one or more * trusted certificates. - * + * * @param trustStore If specified with a scheme, treat as a URL, otherwise treat as a classpath resource. */ public void setTrustStore(String trustStore) throws Exception { this.trustStore = trustStore; trustManager = null; } - + public String getTrustStorePassword() { return trustStorePassword; } - + /** * The password to match the trust store specified by {@link setTrustStore}. - * + * * @param trustStorePassword The password used to unlock the keystore file. */ public void setTrustStorePassword(String trustStorePassword) { this.trustStorePassword = trustStorePassword; } - + public String getKeyStore() { return keyStore; } - + /** * The location of a keystore file (in jks format) containing a certificate * and its private key. - * + * * @param keyStore If specified with a scheme, treat as a URL, otherwise treat as a classpath resource. */ public void setKeyStore(String keyStore) throws Exception { this.keyStore = keyStore; keyManager = null; } - + public String getKeyStorePassword() { return keyStorePassword; } - + /** * The password to match the key store specified by {@link setKeyStore}. - * + * * @param keyStorePassword The password, which is used both to unlock the keystore file * and as the pass phrase for the private key stored in the keystore. */