1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.proxy;
17
18 import org.jboss.netty.bootstrap.ServerBootstrap;
19 import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
20 import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
21 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
22
23 import java.net.InetSocketAddress;
24 import java.util.concurrent.Executor;
25 import java.util.concurrent.Executors;
26
27 public final class HexDumpProxy {
28
29 static final int LOCAL_PORT = Integer.parseInt(System.getProperty("localPort", "8443"));
30 static final String REMOTE_HOST = System.getProperty("remoteHost", "www.google.com");
31 static final int REMOTE_PORT = Integer.parseInt(System.getProperty("remotePort", "443"));
32
33 public static void main(String[] args) {
34 System.err.println("Proxying *:" + LOCAL_PORT + " to " + REMOTE_HOST + ':' + REMOTE_PORT + " ...");
35
36
37 Executor executor = Executors.newCachedThreadPool();
38 ServerBootstrap sb = new ServerBootstrap(new NioServerSocketChannelFactory(executor, executor));
39
40
41 ClientSocketChannelFactory cf = new NioClientSocketChannelFactory(executor, executor);
42
43 sb.setPipelineFactory(new HexDumpProxyPipelineFactory(cf));
44
45
46 sb.bind(new InetSocketAddress(LOCAL_PORT));
47 }
48 }