1 10 11 package org.mule.providers.ssl; 12 13 import java.io.IOException ; 14 import java.net.InetAddress ; 15 import java.net.Socket ; 16 import java.security.NoSuchAlgorithmException ; 17 import java.security.KeyManagementException ; 18 import javax.net.SocketFactory; 19 import javax.net.ssl.SSLContext; 20 import javax.net.ssl.SSLSocket; 21 22 import org.mule.providers.tcp.TcpMessageDispatcher; 23 import org.mule.umo.endpoint.UMOImmutableEndpoint; 24 25 31 32 public class SslMessageDispatcher extends TcpMessageDispatcher 33 { 34 public SslMessageDispatcher(UMOImmutableEndpoint endpoint) 35 { 36 super(endpoint); 37 } 38 39 protected Socket createSocket(int port, InetAddress inetAddress) throws IOException 40 { 41 SslConnector conn = (SslConnector)getConnector(); 42 SSLContext context; 43 try 44 { 45 context = SSLContext.getInstance(conn.getProtocol()); 46 context.init(conn.getKeyManagerFactory().getKeyManagers(), conn.getTrustManagerFactory() 47 .getTrustManagers(), null); 48 } 49 catch (NoSuchAlgorithmException e) 50 { 51 throw new IOException (e.getMessage()); 52 } 53 catch (KeyManagementException e) 54 { 55 throw new IOException (e.getMessage()); 56 } 57 58 SocketFactory factory = context.getSocketFactory(); 59 SSLSocket socket = (SSLSocket)factory.createSocket(inetAddress, port); 60 return socket; 64 } 65 } 66 | Popular Tags |