Results 1 to 1 of 1
- 06-09-2008, 03:40 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 2
- Rep Power
- 0
Redirect My Client httpRequests .
i have this design
internet
|
Router(Suse) ---- Content-Filter Server
|
LAN
am using iptables to redirect client httprequests from Port 80 to my own program's port that is writen (in java) on the router now in my code i want to send ( redirect ) all client http requests to the Content-filter server's port
thanx a lot in adavance,
p.s. i have a purpose out of writing this code thats why i know i could do the whole thing by just redirecting the http traffic to the Content filter server but i have to write the code my self am lettin iptables redirect the traffic from intenal interface (lan ) on port 80 to localhost on port 1500 and then my code will redirect the http traffic to the content filter server (squid on port 3128) and here are my code but it seems am missin smt out there hope you help me ,
thanx anyways,
code :
import java.io.*;
import java.net.*;
public class Test {
public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(1406);
while(true){
System.out.println("Waiting for request");
Socket socket = serverSocket.accept();
new Thread(new SimpleHttpHandler(socket)).run();
socket.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
class SimpleHttpHandler implements Runnable{
private final static String CLRF = "\r\n";
private Socket client;
private DataOutputStream writer;
private BufferedReader reader;
public SimpleHttpHandler(Socket client){
this.client = client;
}
public void run(){
try{
this.reader = new BufferedReader(
new InputStreamReader(
this.client.getInputStream()
)
);
InetAddress ipp=InetAddress.getByName("192.168.6.29"); //192.168.6.29 ip of the proxy server
System.out.println(ipp);
StringBuffer buffer = new StringBuffer();
Socket ss=new Socket(ipp,3128);
this.writer= new DataOutputStream(ss.getOutputStream());
writer.writeBytes(this.read());
this.writer.close();
this.reader.close();
this.client.close();
}
catch(Exception e){
e.printStackTrace();
}
}
private String read() throws IOException{
String in = "";
StringBuffer buffer = new StringBuffer();
while(!(in = this.reader.readLine()).trim().equals("")){
buffer.append(in + "\n");
}
System.out.println(buffer.toString());
return buffer.toString();
}
}Last edited by Tareq85; 06-11-2008 at 12:22 AM. Reason: addin extra info
Similar Threads
-
How to redirect the output
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:36 PM -
how to redirect the output buffer of pl/sql onto a jsp
By sriavr in forum JDBCReplies: 0Last Post: 03-11-2008, 12:25 PM -
How to redirect the output
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:30 PM -
how to redirect the browser
By simon in forum Java AppletsReplies: 1Last Post: 08-02-2007, 05:24 PM -
How can I redirect in servlet?
By Heather in forum Java ServletReplies: 1Last Post: 07-14-2007, 05:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks