KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > ssl > SslMessageDispatcher


1 /*
2  * $Id: SslMessageDispatcher.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.ssl;
12
13 import java.io.IOException JavaDoc;
14 import java.net.InetAddress JavaDoc;
15 import java.net.Socket JavaDoc;
16 import java.security.NoSuchAlgorithmException JavaDoc;
17 import java.security.KeyManagementException JavaDoc;
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 /**
26  * <code>TcpMessageDispatcher</code> will send transformed mule events over tcp.
27  *
28  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
29  * @version $Revision: 3798 $
30  */

31
32 public class SslMessageDispatcher extends TcpMessageDispatcher
33 {
34     public SslMessageDispatcher(UMOImmutableEndpoint endpoint)
35     {
36         super(endpoint);
37     }
38
39     protected Socket JavaDoc createSocket(int port, InetAddress JavaDoc inetAddress) throws IOException JavaDoc
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 JavaDoc e)
50         {
51             throw new IOException JavaDoc(e.getMessage());
52         }
53         catch (KeyManagementException JavaDoc e)
54         {
55             throw new IOException JavaDoc(e.getMessage());
56         }
57
58         SocketFactory factory = context.getSocketFactory();
59         SSLSocket socket = (SSLSocket)factory.createSocket(inetAddress, port);
60         // startHandshake() will reset the current trust and initiate a new
61
// negotiation
62
// socket.startHandshake();
63
return socket;
64     }
65 }
66
Popular Tags