For local networks within an organization, access to the public-domain Internet is often via a HTTP Proxy. This article talks about the HTTP proxy settings for the Java environment. I did not find a good document on the Web to describe these settings; Had to discover many of them by trial-and-error. Hence this article.
HTTP Proxy, Java Proxy Settings, Tomcat, Application Server, Servlets, HTTP Proxy Authentication for Java, Java Application Proxy Settings
Use one of the methods below for your JVM proxy settings. Try an alternate method if any particular method does not work. In most cases, you should not require any change the pre-compiled Java code for proxy settings. JVM's environment settings should be enough to fix this problem.
The proxy settings are given to the JVM via command line arguments:
$ java -Dhttp.proxyHost=proxyhostURL -Dhttp.proxyPort=proxyPortNumber -Dhttp.proxyUser=someUserName -Dhttp.proxyPassword=somePassword javaClassToRun
Add the following lines in your Java code so that JVM uses the proxy to make HTTP calls. This would, of course, require you to recompile your Java source. (The other methods do not require any recompilation.):
System.getProperties().put("http.proxyHost", "someProxyURL");
System.getProperties().put("http.proxyPort", "someProxyPort");
System.getProperties().put("http.proxyUser", "someUserName");
System.getProperties().put("http.proxyPassword", "somePassword");
Don't hardcode the proxy settings in your source. Read these settings from a configurable text file, so your users can configure them. You might also need to set this property:
System.getProperties().put("proxySet", "true");
Or
System.getProperties().put("http.proxySet", "true");
Append these properties to the catalina.properties file in Tomcat: ${CATALINA_OME}/conf/catalina.properties file:
http.proxyHost=yourProxyURL http.proxyPort=yourProxyPort http.proxyUser=yourUserName http.proxyPassword=yourPassword
JAVA_OPTS="-Dhttp.proxyHost=yourProxyURL ..."(Each option is seperated by spaces.)