Hello everyone:
For our previous topic about "Proxy Server in Java" I want to add the following futurities
The web proxy server to filters out and blocks requests for undesirable URLs, using HTTP redirection to display an error page.
I want the user to select the proxy port (i.e. the port number should not be hard coded)
The proxy should be smart in selection of what HTTP content should be searched for the forbidden keywords. For example, you probably agree that it is not wise to search inside compressed or other non-text-based HTTP content such as graphic files, etc.
Also i want to make sure it is compatible with all major browsers (e.g. Internet Explorer, Mozilla Firefox, Google Chrome, etc.)
Here is the code;
package ProxyServer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class MyProxyServer
{
public static final int portNumber = 8888;
public static void main(
String[] args)
{
MyProxyServer myProxyServer = new MyProxyServer();
myProxyServer.start();
}
public void start()
{
System.out.println("Starting the MyProxyServer ...");
try
{
ServerSocket serverSocket = new ServerSocket(MyProxyServer.portNumber,1);
/*File file = new File("test.txt");
FileOutputStream fileOutputStream = new FileOutputStream(file);
PrintStream printStream = new PrintStream(fileOutputStream);*/
while(true)
{
System.out.println("Inside while loop ");
Socket clientSocket = serverSocket.accept();
System.out.println("Connection to MyProxyServer is "+clientSocket.isConnected());
InputStreamReader inputStreamReader = new InputStreamReader(clientSocket.getInputStream());
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String command = bufferedReader.readLine();
//printStream.print(command);
//bufferedReader.close();
System.out.println("Client has asked to ....\n"+command);
if(command.equals("Cancel"))
{
System.out.println("Shutting down the server ...");
break;
}
// iterate over all the lines following the GET/POST request
String meta = null;
while((meta = bufferedReader.readLine()).length() > 0)
{
System.out.println(meta);
}
bufferedReader.close();
/*printStream.close();
fileOutputStream.close();*/
}
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
With my best regards;