View Javadoc

1   /*
2    * $Id: SslSocketFactory.java 7963 2007-08-21 08:53:15Z dirk.olmes $
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 CPAL v1.0
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 org.mule.providers.tcp.TcpSocketFactory;
14  import org.mule.umo.security.tls.TlsConfiguration;
15  
16  import java.io.IOException;
17  import java.net.InetAddress;
18  import java.net.Socket;
19  import java.security.KeyManagementException;
20  import java.security.NoSuchAlgorithmException;
21  
22  public class SslSocketFactory extends TcpSocketFactory 
23  {
24  
25      private TlsConfiguration tls;
26  
27      public SslSocketFactory(TlsConfiguration tls)
28      {
29          this.tls = tls;
30      }
31  
32      // @Override
33      protected Socket createSocket(int port, InetAddress inetAddress) throws IOException
34      {
35          try
36          {
37              return tls.getSocketFactory().createSocket(inetAddress, port);
38          }
39          catch (NoSuchAlgorithmException e)
40          {
41              throw (IOException) new IOException(e.getMessage()).initCause(e);
42          }
43          catch (KeyManagementException e)
44          {
45              throw (IOException) new IOException(e.getMessage()).initCause(e);
46          }
47      }
48  
49  }