| java.lang.Object org.jgroups.util.Proxy
Proxy | public class Proxy (Code) | | Redirects incoming TCP connections to other hosts/ports. All redirections are defined in a file as for example
127.0.0.1:8888=www.ibm.com:80
localhost:80=pop.mail.yahoo.com:110
The first line forwards all requests to port 8888 on to www.ibm.com at port 80 (it also forwards the HTTP
response back to the sender. The second line essentially provides a POP-3 service on port 8110, using
Yahoo's POP service. This is neat when you're behind a firewall and one of the few services in the outside
world that are not blocked is port 80 (HHTP).
Note that JDK 1.4 is required for this class. Also, concurrent.jar has to be on the classpath. Note that
you also need to include jsse.jar/jce.jar (same location as rt.jar) if you want SSL sockets.
To create SSLServerSockets you'll need to do the following:
Generate a certificate as follows:
keytool -genkey -keystore /home/bela/.keystore -keyalg rsa -alias bela -storepass -keypass
Start the Proxy as follows:
java -Djavax.net.ssl.keyStore=/home/bela/.keystore -Djavax.net.ssl.keyStorePassword=
-Djavax.net.ssl.trustStore=/home/bela/.keystore -Djavax.net.ssl.trustStorePassword=
org.jgroups.util.Proxy -file /home/bela/map.properties
Start client as follows:
java -Djavax.net.ssl.trustStore=/home/bela/.keystore -Djavax.net.ssl.trustStorePassword= sslclient
To import a certificate into the keystore, use the following steps:
openssl x509 -in server.crt -out server.crt.der -outform DER
keytool -import -trustcacerts -alias -file server.crt.der
This will store the server's certificate in the ${user.home}/.keystore key store.
Note that an SSL client or server can be debugged by starting it as follows:
-Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol -Djavax.net.debug=ssl
If you run a web browser, simply enter https://: as URL to connect to an SSLServerSocket
Note that we cannot use JDK 1.4's selectors for SSL sockets, as
getChannel() on an SSL socket doesn't seem to work.
author: Bela Ban |
Inner Class :static class Relayer implements Runnable | |
Inner Class :class SocketAcceptor implements Runnable | |
Inner Class :static class Connection implements Relayer.Listener | |
Constructor Summary | |
public | Proxy(InetAddress local, int local_port, InetAddress remote, int remote_port, boolean verbose, boolean debug) | public | Proxy(InetAddress local, int local_port, InetAddress remote, int remote_port, boolean verbose, boolean debug, String mapping_file) |
Method Summary | |
void | _handleConnection(SocketChannel in_channel, SocketChannel out_channel) | void | check(URI u) | void | close(Selector sel, SocketChannel in_channel, SocketChannel out_channel) | static void | close(Socket in, Socket out) | static void | close(Socket sock) | void | handleConnection(SocketChannel in, SocketChannel out) | static void | help() | static void | log(String method_name, String msg) | static void | log(String msg) | void | loop(Selector selector) | public static void | main(String[] args) | void | populateMappings(String filename) Populates mappings hashmap. | static String | printRelayedData(String from, String to, int num_bytes) | String | printSelectionOps(SelectionKey key) | boolean | relay(SocketChannel from, SocketChannel to, ByteBuffer buf) Read all data from from and write it to to . | public void | start() | SocketAddress | strToAddr(String input) | String | toString(SocketChannel ch) | String | toString(InetSocketAddress addr) |
BUFSIZE | final static int BUFSIZE(Code) | | |
MAX_THREAD_POOL_SIZE | final static int MAX_THREAD_POOL_SIZE(Code) | | |
debug | static boolean debug(Code) | | |
executor | Executor executor(Code) | | |
local_portremote_port | int local_portremote_port(Code) | | |
verbose | static boolean verbose(Code) | | |
loop | void loop(Selector selector)(Code) | | We handle only non-SSL connections
|
populateMappings | void populateMappings(String filename) throws Exception(Code) | | Populates mappings hashmap. An example of a definition file is:
http://localhost:8888=http://www.yahoo.com:80
https://localhost:2200=https://cvs.sourceforge.net:22
http://localhost:8000=https://www.ibm.com:443
Mappings can be http-https, https-http, http-http or https-https
|
|
|