SourceForge.net Logo

Home | SF Project | Download | Forum | Bugs | History | For Coders | HowTo | Commentary | TODO | Support This Project


Basic | Connection | Advanced | Secure | Certificate | JMX | XML

DonsProxy HowTo - Basic one-server example

Assume there's a server, google.com, listening on port 80:

We want to set up DonsProxy to listen on 9090, and forward requests to 80:

java -Dlisten.port=9090 -Dtarget.host=google.com -Dtarget.port=80 com.moneybender.proxy.Proxy
But rather than type this, find the line that looks like the line below in scripts/proxy.sh, set the values accordingly, and run it. Alternatively, you can run com.moneybender.proxy.Proxy from your IDE, with the proper classpath and settings. Just look at env.sh and proxy.sh, and do the same thing they do in your IDE. If you're using Windows without Cygwin, running DonsProxy from your IDE is probably the quickest alternative.
PROXY_PROPS="-Dlisten.port=9090 -Dtarget.host=google.com -Dtarget.port=80"

Also, we'd like to see some of the traffic as it goes by, so we'll run a Subscriber. We could run more than one, and they would all receive the packets as they go by. The Subscribers connect to the proxy via TCP, so the proxy we just started also listens on three TCP ports: one is requests only, one is responses only, and one is duplex - that is, both requests and responses.

So, let's run a Subscriber that shows HTTP Headers. There's a script for that named httphead.sh. It will connect to the duplex port, and show us all request and response headers. Again, run that, or run com.moneybender.proxy.subscribers.HttpHeadSubscriber from your IDE:

Now, hit http://localhost:9090 with your favorite browser:

and you should see something like this:

2007-12-31 09:02:08,520 INFO  [HttpHeadSubscriber] - HttpHeadSubscriber started.
Sender is CLIENT at 127.0.0.1:51291
Packet ID:3-1
GET / HTTP/1.1
Host: localhost:9090
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

Sender is SERVER at 64.233.167.99:80
Packet ID:3-1
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=a25675923eea32fd:TM=1199113342:LM=1199113342:S=6r_Z7Gz1t-wOfVMb; expires=Wed, 30-Dec-2009 15:02:22 GMT; path=/; domain=.google.com
Content-Encoding: gzip
Server: gws
Content-Length: 1543
Date: Mon, 31 Dec 2007 15:02:22 GMT
Now, there's a basic problem here. That is, we can see the first request, but the HTML documents that most sites return include embedded links to other docs and to images, and these all result in additional requests from your browser that will not go to localhost:9090, they'll go right to the host site. So, to see all requests, we need to do something a little more advanced.