Results 1 to 1 of 1
  1. #1
    Tareq85 is offline Member
    Join Date
    Jun 2008
    Posts
    2
    Rep Power
    0

    Default 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 01:22 AM. Reason: addin extra info

Similar Threads

  1. How to redirect the output
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-04-2008, 03:36 PM
  2. Replies: 0
    Last Post: 03-11-2008, 01:25 PM
  3. How to redirect the output
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 10:30 PM
  4. how to redirect the browser
    By simon in forum Java Applets
    Replies: 1
    Last Post: 08-02-2007, 06:24 PM
  5. How can I redirect in servlet?
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-14-2007, 06:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •