aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes tcpmon minimal implementation. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "tcpmon minimal implementation." Watch "tcpmon minimal implementation." New topic
Author

tcpmon minimal implementation.

Edward Rice
Greenhorn

Joined: Mar 16, 2004
Posts: 5
Hi
Can someone tell me what's involved creating a minimal effort http proxy like apache's tcpmon.
I want my simple application just to sit and wait and scan a port, for example 8080 on localhost, for http requests which I sent to that proxy by setting System.setProperty("http.proxyHost", "127.0.0.1") and System.setProperty("http.proxyPort", "8080").
If it get's a request, use a BufferedReader to read the request and send it on. Same for the reply. My proxy should be able to receive it, show it and forward it to the original sender. Is this hard to implement?
Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

Hi Mr. Rice,
Welcome to JavaRanch!
We don't have too many rules round these parts, but we do have our naming policy, which requires that your display name not be a fictitious name. Pleae head over here and update yours, pronto. Thanks, pardner!


[Jess in Action][AskingGoodQuestions]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

Depends on how well you want it to work, I suppose. Basically, you'd open a ServerSocket. Each incoming proxy request should look something like
GET http://server:port/file.html HTTP/1.0
Header1: something
Header2: something else
...
(blank line)
The GET can be POST instead, in which case the blank line will be followed by POST data; a Content-Length: header will specify how much. This is just one of potentially many headers that could be meaningful to the proxy server.
In any case, when you get a connection on the ServerSocket, you read the first line as text, parse out the URL, open a connection with a Socket, pass along the request and the headers (and optional data).
Then you'll get back a response code line line
HTTP/1.1 200 OK
or
HTTP/1.1 404 File Not Found
some headers, a blank line, and then the document. You can just pass everything back to the Socket for the incoming connection.
Now, there's also HTTPS, which adds a few wrinkles of its own.
Maybe you could just use Muffin?
[ March 16, 2004: Message edited by: Ernest Friedman-Hill ]
Edward Rice
Greenhorn

Joined: Mar 16, 2004
Posts: 5
No me not Muffin. Why? Bad Spammer?
Ok, thanks for your answer. I now have something like that that nearly works so thanks for your help.
Can anyone point me to some open source that implements the simplest proxy, i.e. just intercepting and forwarding. I pressume there will be a seperate thread for each incoming request which handles the communication.
So I have updated my name.
Rice
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: tcpmon minimal implementation.
 
Similar Threads
Unable to tcpmon remote web services
Http Request through Proxy Server
valid SOAP content-type?
Using network proxy settings in java program
tracing post parameter