1 package com.sslexplorer.boot; 2 3 import java.io.IOException ; 4 import java.net.InetAddress ; 5 import java.net.ServerSocket ; 6 7 import javax.net.ServerSocketFactory; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 12 14 public class CustomServerSocketFactory extends ServerSocketFactory { 15 16 private static final Log log = LogFactory.getLog(CustomServerSocketFactory.class); 17 private static ServerSocketFactory instance; 18 private static Class <? extends ServerSocketFactory> socketFactoryImpl = CustomServerSocketFactory.class; 19 20 @Override 21 public ServerSocket createServerSocket(int port) throws IOException { 22 return new ServerSocket (port); 23 } 24 25 @Override 26 public ServerSocket createServerSocket(int port, int backlog) throws IOException { 27 return new ServerSocket (port, backlog); 28 } 29 30 @Override 31 public ServerSocket createServerSocket(int port, int backlog, InetAddress address) throws IOException { 32 return new ServerSocket (port, backlog, address); 33 } 34 35 public static ServerSocketFactory getDefault() { 36 try { 37 return instance == null ? instance = (ServerSocketFactory) socketFactoryImpl.newInstance() : instance; 38 } catch (Exception e) { 39 log.error("Could not create instance of class " + socketFactoryImpl.getCanonicalName(), e); 40 return instance == null ? instance = new CustomServerSocketFactory() : instance; 41 } 42 } 43 44 47 public static void setFactoryImpl(Class <? extends ServerSocketFactory> socketFactoryImpl) { 48 CustomServerSocketFactory.socketFactoryImpl = socketFactoryImpl; 49 } 50 } | Popular Tags |