Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-09-2008, 04:40 PM
Member
 
Join Date: Jun 2008
Posts: 2
Tareq85 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to redirect the output Java Tip java.io 0 04-04-2008 03:36 PM
how to redirect the output buffer of pl/sql onto a jsp sriavr Database 0 03-11-2008 01:25 PM
How to redirect the output JavaBean Java Tips 0 10-04-2007 10:30 PM
how to redirect the browser simon Java Applets 1 08-02-2007 06:24 PM
How can I redirect in servlet? Heather Java Servlet 1 07-14-2007 06:52 PM


All times are GMT +3. The time now is 04:29 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org