KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > DirectTCPSocketFactory


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.agent.client;
21
22 import java.io.IOException JavaDoc;
23 import java.net.InetAddress JavaDoc;
24 import java.net.Socket JavaDoc;
25 import java.net.UnknownHostException JavaDoc;
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 JavaDoc createSocket(String JavaDoc host, int port) throws IOException JavaDoc, UnknownHostException JavaDoc {
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 JavaDoc e) throws IOException JavaDoc {
51         IOException JavaDoc ioe = new IOException JavaDoc("Failed to create socket. " + e.getMessage());
52         throw ioe;
53     }
54
55     public Socket JavaDoc createSocket(InetAddress JavaDoc host, int port) throws IOException JavaDoc {
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 JavaDoc createSocket(String JavaDoc host, int port, InetAddress JavaDoc localHost, int localPort) throws IOException JavaDoc,
65                     UnknownHostException JavaDoc {
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 JavaDoc createSocket(InetAddress JavaDoc address, int port, InetAddress JavaDoc localAddress, int localPort) throws IOException JavaDoc {
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