Discussions

Web tier: servlets, JSP, Web frameworks: How can a servlet use a URLConnection that will use a Proxy

  1. Dear All

    How can I set up the JDK/J2EE so that URLConnections
    will make use of a Proxy. I want to create an URLConnection
    from an URL like http://www.ibm.com. But I am sitting behind
    a firewall with a proxy that can get through. How can I configure
    my Java environment so that the proxy will be used in my
    Servlet that will run in Catalina.

    Best Regards
  2. You need to set 3 system properties and the URLConnection will go through your proxy server.

    proxySet
    proxyHost
    proxyPort

    You can set them in your code...

    System.getProperties().put("proxySet", "true");
    System.getProperties().put("proxyHost", "your proxy host");
    System.getProperties().put("proxyPort", "your proxy port");

    or when you start the JVM...

    java -DproxySet=true ....

    Wes