1 18 19 package org.apache.activemq; 20 21 import org.apache.activemq.transport.Transport; 22 import org.apache.activemq.transport.TransportFactory; 23 import org.apache.activemq.transport.tcp.SslTransportFactory; 24 import org.apache.activemq.util.JMSExceptionSupport; 25 26 import java.net.URI ; 27 import java.net.URISyntaxException ; 28 import java.security.KeyManagementException ; 29 import java.security.NoSuchAlgorithmException ; 30 import java.security.SecureRandom ; 31 32 import javax.jms.JMSException ; 33 import javax.net.ssl.KeyManager; 34 import javax.net.ssl.SSLContext; 35 import javax.net.ssl.TrustManager; 36 37 47 public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory { 48 protected KeyManager[] keyManager = null; 50 protected TrustManager[] trustManager = null; 51 protected SecureRandom secureRandom = null; 52 53 60 public void setKeyAndTrustManagers(KeyManager[] km, TrustManager[] tm, SecureRandom random) { 61 keyManager = km; 62 trustManager = tm; 63 secureRandom = random; 64 } 65 66 75 protected Transport createTransport() throws JMSException { 76 if (!brokerURL.getScheme().equals("ssl")) { 78 return super.createTransport(); 79 } 80 81 try { 82 SslTransportFactory sslFactory = new SslTransportFactory(); 83 sslFactory.setKeyAndTrustManagers(keyManager, trustManager, secureRandom); 84 return sslFactory.doConnect(brokerURL); 85 } catch (Exception e) { 86 throw JMSExceptionSupport.create("Could not create Transport. Reason: " + e, e); 87 } 88 } 89 } 90 | Popular Tags |