View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.ssl;
8   
9   import org.mule.api.security.tls.TlsConfiguration;
10  import org.mule.transport.tcp.AbstractTcpSocketFactory;
11  import org.mule.transport.tcp.TcpSocketKey;
12  
13  import java.io.IOException;
14  import java.net.Socket;
15  import java.security.KeyManagementException;
16  import java.security.NoSuchAlgorithmException;
17  
18  public class SslSocketFactory extends AbstractTcpSocketFactory
19  {
20  
21      private TlsConfiguration tls;
22  
23      public SslSocketFactory(TlsConfiguration tls)
24      {
25          this.tls = tls;
26      }
27  
28      protected Socket createSocket(TcpSocketKey key) throws IOException
29      {
30          try
31          {
32              return tls.getSocketFactory().createSocket(key.getInetAddress(), key.getPort());
33          }
34          catch (NoSuchAlgorithmException e)
35          {
36              throw (IOException) new IOException(e.getMessage()).initCause(e);
37          }
38          catch (KeyManagementException e)
39          {
40              throw (IOException) new IOException(e.getMessage()).initCause(e);
41          }
42      }
43  
44  }