View Javadoc

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