1 19 20 package com.sslexplorer.agent.client; 21 22 import java.io.IOException ; 23 import java.net.InetAddress ; 24 import java.net.Socket ; 25 import java.net.UnknownHostException ; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 import com.maverick.multiplex.ChannelOpenException; 31 32 public class DirectTCPSocketFactory { 33 final static Log log = LogFactory.getLog(DirectTCPSocketFactory.class); 34 35 private Agent agent; 36 37 public DirectTCPSocketFactory(Agent agent) { 38 this.agent = agent; 39 } 40 41 public Socket createSocket(String host, int port) throws IOException , UnknownHostException { 42 try { 43 return new LocalForwardingChannelSocket(agent, host, port); 44 } catch (ChannelOpenException e) { 45 rethrow(e); 46 } 47 return null; 48 } 49 50 void rethrow(Exception e) throws IOException { 51 IOException ioe = new IOException ("Failed to create socket. " + e.getMessage()); 52 throw ioe; 53 } 54 55 public Socket createSocket(InetAddress host, int port) throws IOException { 56 try { 57 return new LocalForwardingChannelSocket(agent, host.getHostAddress(), port); 58 } catch (ChannelOpenException e) { 59 rethrow(e); 60 } 61 return null; 62 } 63 64 public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException , 65 UnknownHostException { 66 try { 67 return new LocalForwardingChannelSocket(agent, host, port); 68 } catch (ChannelOpenException e) { 69 rethrow(e); 70 } 71 return null; 72 } 73 74 public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { 75 try { 76 return new LocalForwardingChannelSocket(agent, address.getHostAddress(), port); 77 } catch (ChannelOpenException e) { 78 rethrow(e); 79 } 80 return null; 81 } 82 83 } 84 | Popular Tags |