How to create Proxy Server in Java

Hello I need to create Proxy server on port number 80. Does enybody knows how to do that.??? ThX

A proxy for what?
I assume that you mean a web proxy since you want to run port 80.
I would recomend that you start with an existing proxy like mine.
http://www.khelekore.org/rabbit/
It is free and fully HTTP/1.1 compliant.

Similar Messages

  • How to set proxy authentication using java properties at run time

    Hi All,
    How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
    => Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
    import java.io.*;
    import java.net.*;
    public class DnldURLWithoutUsingProxy {
       public static void main (String[] args) {
          URL u;
          InputStream is = null;
          DataInputStream dis;
          String s;
          try {
              u = new URL("http://www.yahoo.com.au/index.html");
             is = u.openStream();         // throws an IOException
             dis = new DataInputStream(new BufferedInputStream(is));
             BufferedReader br = new BufferedReader(new InputStreamReader(dis));
          String strLine;
          //Read File Line By Line
          while ((strLine = br.readLine()) != null)      {
          // Print the content on the console
              System.out.println (strLine);
          //Close the input stream
          dis.close();
          } catch (MalformedURLException mue) {
             System.out.println("Ouch - a MalformedURLException happened.");
             mue.printStackTrace();
             System.exit(1);
          } catch (IOException ioe) {
             System.out.println("Oops- an IOException happened.");
             ioe.printStackTrace();
             System.exit(1);
          } finally {
             try {
                is.close();
             } catch (IOException ioe) {
    }However, it generated the following message when run behind the firewall:
    cd C:\Documents and Settings\abc\DnldURL\build\classes
    java -cp . DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
    at java.net.Socket.connect(Socket.java:452)
    at java.net.Socket.connect(Socket.java:402)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:320)
    at sun.net.www.http.HttpClient.New(HttpClient.java:315)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    I have also tried the command without much luck either:
    java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
    There is no problem pinging www.yahoo.com from this system.
    I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
    I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
    Java Control Panel - Use browser settings without success.
    Thanks,
    George

    Hi All,
    How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
    => Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
    import java.io.*;
    import java.net.*;
    public class DnldURLWithoutUsingProxy {
       public static void main (String[] args) {
          URL u;
          InputStream is = null;
          DataInputStream dis;
          String s;
          try {
              u = new URL("http://www.yahoo.com.au/index.html");
             is = u.openStream();         // throws an IOException
             dis = new DataInputStream(new BufferedInputStream(is));
             BufferedReader br = new BufferedReader(new InputStreamReader(dis));
          String strLine;
          //Read File Line By Line
          while ((strLine = br.readLine()) != null)      {
          // Print the content on the console
              System.out.println (strLine);
          //Close the input stream
          dis.close();
          } catch (MalformedURLException mue) {
             System.out.println("Ouch - a MalformedURLException happened.");
             mue.printStackTrace();
             System.exit(1);
          } catch (IOException ioe) {
             System.out.println("Oops- an IOException happened.");
             ioe.printStackTrace();
             System.exit(1);
          } finally {
             try {
                is.close();
             } catch (IOException ioe) {
    }However, it generated the following message when run behind the firewall:
    cd C:\Documents and Settings\abc\DnldURL\build\classes
    java -cp . DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
    at java.net.Socket.connect(Socket.java:452)
    at java.net.Socket.connect(Socket.java:402)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:320)
    at sun.net.www.http.HttpClient.New(HttpClient.java:315)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    I have also tried the command without much luck either:
    java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
    There is no problem pinging www.yahoo.com from this system.
    I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
    I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
    Java Control Panel - Use browser settings without success.
    Thanks,
    George

  • How to create web services in java?

    Hi,
    I am a newbie to java webservices. Can anybody tell me how to create web services in java?
    Any tutorial link or step by step doc would be useful.
    Appreciate your help in this regard.
    Thanks in advance.
    naymo01.

    Creating web services in Java appears to depend highly upon the server you intend to use.
    Here's a tutorial: http://java.sun.com/webservices/docs/1.6/tutorial/doc/index.html

  • How to clear proxy-server authorization form in Firefox?

    How to clear proxy-server authorization form in Firefox?

    Click Tools | Options | Advanced and then click the Network tab.
    Then click the Settings button and choose "No Proxy" in the next menu. See also: [https://support.mozilla.com/en-US/kb/Options%20window%20-%20Advanced%20panel?as=u#w_network-tab Network Settings]
    Incidentally, your Java installation is very old and exposes your system to attack. Update via http://www.java.com/en/<br><br>
    Please also visit to the [http://www.mozilla.com/en-US/plugincheck/ Plugins Check] page and update where necessary.

  • HELP!!! - About creating a server in java

    Is it possible to create a server in java, that if i connect to someone(a server or not) i'll still remain the server and the other side will become my client ?
    If that's possible so please tell me how to do it please!

    Is it possible to create a server in java, that if i
    connect to someone(a server or not) i'll still remain
    the server and the other side will become my client ?
    If that's possible so please tell me how to do it
    please!I am not too sure if I fully understand your request. But you can create a server which handles requests from clients. Also in a separate thread you can create your own client to communicate with the other server.
    Check this tutorial from IBM's site, it may help you.
    http://www-106.ibm.com/developerworks/edu/j-dw-javasocks-i.html
    Good Luck

  • How to create sub domain using java ?

    how to create sub domain using java ?
    for example:
    name1.domainname.com
    name2.domainname.com
    is it possibe ?

    You don't do that using Java.
    Consult the documentation of the application server in question how to configure it. If you're using for example Tomcat 6.0, then you should be consulting this document: [http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html].

  • How to configure Proxy server on Solaris 10 - SPARC

    Hi All
    Please guide on how to configure Proxy server on Solaris 10 - SPARC ?
    What tool should be used?

    Proxy configurations are most often done within the application software that needs that function and not necessarily done in the OS.   That permits you to make very specific settings and not just generic global settings that could conflict with other software.
    Can you tell us what research you have done on the topic? 
    For example, have you glanced through a Google search on "solaris web proxy" ?
    If you are hoping to use a specific web server application your forum post might be better placed in a forum space for that software instead of in a general OS forum space.   What application software will you be using?

  • How to Create adf table from java bean

    Hi,
    How to Create adf table from java class (Not from ADF BC).
    Thanks
    Satya

    @vlsn -- you have to follow what shay said.
    Do the following in Model layer ::
    create a table property java class with your columns setters and getters like :
    *public class gridProps {*
    private int sno;
    private String orderNum;
    *public void setSno(int sno) {*
    this.sno = sno;
    *public int getSno() {*
    return sno;
    *public void setOrderNum(String orderNum) {*
    this.orderNum = orderNum;
    *public String getOrderNum() {*
    return orderNum;
    Create another table java class which will populate the values to your column values and return the collection :
    *public class gridPopulate {*
    private  List<gridProps> gridValues ;
    *public List<gridProps> setToGrid(ArrayList<ArrayList> valuesToSet) {*
    *if (valuesToSet == null) {*
    return gridValues;
    gridValues = new ArrayList<gridProps>();
    if(btnValue.equals("completeBtn"))
    return gridValues;
    for(ArrayList<String> tempArr:valuesToSet)
    gridProps gp = new gridProps();
    gp.setSno(Integer.valueOf(tempArr.get(0)));
    gp.setOrderNum(tempArr.get(1));
    return gridValues;
    Right click gridPopulate class and create this as data control.This class will be seen in Data control list.Under this data control,Drag the grid property collection(created earlier) to your page.Then execute your binding(gridPopulate) according to your logic.
    Thanks.(My jdev version 11.1.1.5.0)

  • How to run .jar on linux & how to create .jar file using java?

    hi, may i know how to run .jar on linux & how to create .jar file using java? Can u provide the steps on doing it.
    thanks in advance.

    Look at the manual page for jar:
    # man jar
    Also you can run them by doing:
    # java -jar Prog.jar

  • How does create a server with multiple Clients ?

    Any people can lead me .
    How does create a server with multiple Clients ?
    Thanks

    For a multithreaded server you will need a thread to listen and at least one thread per client. If the conversation is half duplex, one thread per client works very well, if it's full duplex you will find one thread to send and one to receive much easier to program.
    I posted a Simple Socket Server that uses 1+2*clients threads.

  • How to create a server through WLST  ( Weblogic Scripting Tool ) ?

    How to create a server through WLST ( Weblogic Scripting Tool ) ?
    Thanks in advance...
    Sanjay

    Hi Murugesh,
    Thanks a lot for you reply..
    I was able to create a server using create(). Is it possible to clone a server ?
    When i create a server following tags is added to config.xml
    <server>
    <name>testServer_lab1</name>
    <listen-port>43000</listen-port>
    </server>
    And if i do a clone through admin console, following is added to config.xml
    <server>
    <name>testServer2_lab1</name>
    <machine xsi:nil="true"></machine>
    <listen-port>7001</listen-port>
    <cluster xsi:nil="true"></cluster>
    <listen-address></listen-address>
    <graceful-shutdown-timeout>120</graceful-shutdown-timeout>
    </server>
    If incase, cloning is not possible through WLST, can i add following
    <machine xsi:nil="true"></machine>
    <listen-port>7001</listen-port>
    <cluster xsi:nil="true"></cluster>
    <listen-address></listen-address>
    <graceful-shutdown-timeout>120</graceful-shutdown-timeout>
    under <server> tag which is created through WLST ?
    I am using 9.2 version.
    Regards
    Sanjay

  • How to create webservice in Webdynpro java

    Hi Experts,
          I need to develop one application in Visual Composer.Since VC doesn't support coding so i need to create Webservice in webdynpro java and use that webservice in VC.Can any one of you please suggest how to create Webservice in Webdynpro Java.
    Regards,
    Prasanna.

    Hi prasanna,
    Refer this links.
    /people/sridhar.k2/blog/2006/09/12/creating-and-exposing-bapi-as-web-service-and-using-it-in-web-dynpro
    BAPI Exposed as Web Service
    Connect R/3 from Java web application
    Web Dynpro integration with R/3
    http://help.sap.com/saphelp_nw04s/helpdata/en/82/6a0e7bbe744276bf393654b9b576ed/frameset.htm
    Regards,
    karthik.

  • How to create ejbbean in wd-java

    Hi,
    Iam new to Wd-java area.Iam doing the defecttracking application in Webdynpro for java,in that backend is sql server.I want to retrive login details through ejb bean. give me step-by-step coding procedure.i don't know how to create ejb application also.please give me step-by-step.

    Ram,
    Below tutorial may be of some help :- https://www.sdn.sap.com/irj/sdn/webdynpro?rid=/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d#20
    Chintan

  • How to create dynamic images in java servlets?

    I want to create dynamic images in java servlet. Can servlet create dynamic images that based on the input data files? The results can be displayed in GIF, JPG..format? how can this be done? any example in internet?
    What OS do I need to install and what other requirements needed if i want to build up a servlet server?
    Thanks a lot!

    Also worth having a look at SVG http://www.w3.org/TR/2001/REC-SVG-20010904/, you can get a viewer at http://www.adobe.com/svg/ or you can use Batik http://xml.apache.org/batik/index.html to convert SVG to other formats such as JPEG.
    HH

  • Creating proxy server

    hi harmmeijer,
    do u have any experience regarding writing proxy serve.
    if u could give me starting code.
    i will be thankful to u.
    i wanna make proxy server which get request on behalf of web browser.

    I have once wrote a proxy server which can handle GET and POST requests but it cant handle HTTP Errors yet
    This is also has some other limitations It only allows one request per connection
    and I havent tested this with HTTP authentication
    And this do not realy cache the data so you cant realy call this a usefull proxy.
    Actual the purpose that I wrote this was once there was a problem in my DNS resolution system so I wrote this Proxy and put it in another PC in the network to work as a middle man.
    Here is the Logic of My ProxyServer....
    Accept the Client Connection
    Read The Client Request.
    Extract the URL Path, Host and Method from the Client Request
    Extract All the headers from the Client request
    Create a Socket to the Host and send the Get/Post request with all the headers
    Read the Responce of the Host (Web server) and write them to the Client Socket
    Close Both Sockets (Client and Web Server)
    Recomended Logic For Professional ProxyServers
    Accept the Client Request.
    If the client like to accept cached responce look in the cache and if found send the responce to client.
    other wise connect web server and get the response and send it to the client and it should also be saved in the cache
    If client has send Proxy-Connection: keep-alive header keep the connection open to accept more requests.
    Proxy can also keep a list of open connection to freaquantly acced web servers.
    Here Is the code of my proxy:-
    //File 1 Sava this as Proxy.java
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    public class Proxy extends Thread {
        ServerSocket ss;
        int portNumber;
        boolean keepRunning = true;
        public Proxy(int port){
            this.portNumber = port;
            try {
                ss = new ServerSocket(this.portNumber);
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
        public void stopIt(){
            this.keepRunning = false;
        public void startIt(){
            this.keepRunning = true;
            start();
        public void run(){
            try {
                ss.setSoTimeout(10000);
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            while (this.keepRunning) {
                try {
                    Socket s = ss.accept();
                    ClientHandler ch = new ClientHandler(s);
                } catch (Exception e) {
                    System.out.println(e);
        public static void main (String args[]) {
            Proxy p = new Proxy(9999);
            p.startIt();
            JOptionPane.showMessageDialog(null, "Stop???", "Server Is Running", JOptionPane.INFORMATION_MESSAGE);
            p.stopIt();
            System.exit(0);
    //Should be saved in  ClientHandler.java
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class ClientHandler extends Thread {
        Socket client;
        DataInputStream dis;
        DataOutputStream dos;
        public ClientHandler(Socket s){
            client= s;
            this.start();
        public synchronized void run(){
            System.out.println("Starting Thread");
            PrintStream ps=null;
            InputStream remote=null;
            try {
                dis = new DataInputStream(client.getInputStream());
                dos = new DataOutputStream(client.getOutputStream());
                byte b[];
                String line;
                String req = "";
                System.out.println("---------------Start Of Request---------------");
                while ((line = dis.readLine()).length()>0) {
                    req +=line + "\n";
                System.out.println(req);
                System.out.println("---------------End Of Request---------------");
                URL u= this.GetURL(req);
                URLConnection c = u.openConnection();
                String myHost = u.getHost();
                String myPath = u.getPath();
                int myPort = ((u.getPort()==-1)?80:u.getPort());
                Socket s = new Socket(myHost, myPort);
                ps = new PrintStream(s.getOutputStream());
                String request = (this.isPost(req)?"POST":"GET") + " " + myPath + " HTTP/1.0";
                ps.println(request);
                StringTokenizer tok = new StringTokenizer(req, "\n");
                tok.nextToken();
                while (tok.hasMoreTokens()) {
                    ps.println(tok.nextToken());
                ps.println("Connection: Close");
                ps.println();
                System.out.println("Host :" + u.getHost());
                System.out.println("Port :" + ((u.getPort()==-1)?80:u.getPort()));
                System.out.println("Path :" + u.getPath());
                remote =s.getInputStream();
                if (this.isPost(req)) {
                    sleep(200);
                    if (dis.available()>0) {
                        byte ba[] = new byte[dis.available()];
                        dis.read(ba);
                        ps.write(ba);
                int id=1;
                b=new byte[10240];
                int i;
                //FileOutputStream f = new FileOutputStream("log\\" + new Date().getTime() + ".txt");
                while ((i = remote.read(b))>-1) {
                    dos.write(b,0,i);
                    //f.write(b,0,i);
                //f.close();
                dis.close();
                dos.close();
                remote.close();
                ps.close();
            } catch (java.net.UnknownHostException e) {
                try {
                    dos.writeChars("HTTP/1.1 404 ERROR\n\n");
                } catch (Exception ex) {
                    ex.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            System.out.println("End Thread.");
        public URL GetURL(String r) throws Exception{
            StringTokenizer tok1  = new StringTokenizer(r, "\n");
            String line1 = tok1.nextToken();
            StringTokenizer tok  = new StringTokenizer(line1, " ");
            line1 = tok.nextToken();
            line1 = tok.nextToken();
            URL u= new URL(line1);
            return u;
        public boolean isPost(String r){
            StringTokenizer tok  = new StringTokenizer(r, "\n");
            String line1 = tok.nextToken();
            tok  = new StringTokenizer(line1, " ");
            line1 = tok.nextToken();
            return line1.toUpperCase().equals("POST");
    }

Maybe you are looking for

  • Can't find jsp app to test with 10g as partner

    Hi, I'm trying to find a small jsp application that I can set up to test the partner application single sign on. I've found references to a MonthCalendar application, but I can't find it anywhere. I'm running 10g. Does anyone have the MonthCalendar.z

  • How to crate a new database

    I have installed the XE edition and the home page and all works. What I would like to do is create a simple database and have an application talk to it via OLEDB. Two problems with that: 1) If you want to create a new database, the simplest option is

  • Unable to choose save as feature in pages

    Hello, I have pages for macbook pro and it doesn't give me the save as option to choose from the file menu.  Any suggestions? MacDeven

  • FTP (Sender) Adapter - Polling Problem

    Hello everyone! I'm trying to pick up an XML file using the FTP Adapter (Sender). Weird thing is that I have set the "polling interval" for 60secs, but the FTP adapter doesn't seem to want to repeat polling at the said time interval. It only picks up

  • Send form like pdf

    Hi, I have form and I need to send form in PDF format to specific mail ... in the start user must select check box :      when user select 1 check box option subject mail is Name 1 + address2 ....      when user select 2 check box option subject mail