1 package com.sslexplorer.boot; 2 3 import java.io.IOException ; 4 import java.net.InetAddress ; 5 import java.net.Socket ; 6 import java.net.UnknownHostException ; 7 8 import javax.net.SocketFactory; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 public class CustomSocketFactory extends SocketFactory { 14 15 static Log log = LogFactory.getLog(CustomSSLSocketFactory.class); 16 17 static SocketFactory instance; 18 static Class socketFactoryImpl = CustomSocketFactory.class; 19 20 public Socket createSocket(String arg0, int arg1) throws IOException , 21 UnknownHostException { 22 return new Socket (arg0, arg1); 23 } 24 25 public Socket createSocket(InetAddress arg0, int arg1) throws IOException { 26 return new Socket (arg0, arg1); 27 } 28 29 public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) 30 throws IOException , UnknownHostException { 31 return new Socket (arg0, arg1, arg2, arg3); 32 } 33 34 public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, 35 int arg3) throws IOException { 36 return new Socket (arg0, arg1, arg2, arg3); 37 } 38 39 public static SocketFactory getDefault() { 40 try { 41 return instance == null ? instance = (SocketFactory) socketFactoryImpl.newInstance() : instance; 42 } catch (Exception e) { 43 log.error("Could not create instance of class " + socketFactoryImpl.getCanonicalName(), e); 44 return instance == null ? instance = new CustomSocketFactory() : instance; 45 } 46 } 47 48 public static void setFactoryImpl(Class socketFactoryImpl) { 49 CustomSocketFactory.socketFactoryImpl = socketFactoryImpl; 50 instance = null; 51 } 52 } 53 | Popular Tags |