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.TcpServerSocketFactory;
11  
12  import java.io.IOException;
13  import java.net.InetAddress;
14  import java.net.ServerSocket;
15  import java.net.InetSocketAddress;
16  
17  import javax.net.ServerSocketFactory;
18  
19  public class SslServerSocketFactory extends TcpServerSocketFactory
20  {
21  
22      private TlsConfiguration tls;
23  
24      public SslServerSocketFactory(TlsConfiguration tls)
25      {
26          this.tls = tls;
27      }
28  
29      @Override
30      public ServerSocket createServerSocket(InetAddress address, int port, int backlog, Boolean reuse) throws IOException
31      {
32          try
33          {
34              ServerSocketFactory ssf = tls.getServerSocketFactory();
35              return configure(ssf.createServerSocket(), reuse, new InetSocketAddress(address, port), backlog);
36          }
37          catch (IOException e)
38          {
39              throw e;
40          }
41          catch (Exception e)
42          {
43              throw (IOException) new IOException(e.getMessage()).initCause(e);
44          }
45      }
46  
47      @Override
48      public ServerSocket createServerSocket(int port, int backlog, Boolean reuse) throws IOException
49      {
50          try
51          {
52              ServerSocketFactory ssf = tls.getServerSocketFactory();
53              return configure(ssf.createServerSocket(), reuse, new InetSocketAddress(port), backlog);
54          }
55          catch (IOException e)
56          {
57              throw e;
58          }
59          catch (Exception e)
60          {
61              throw (IOException) new IOException(e.getMessage()).initCause(e);
62          }
63      }
64  
65  }