Surprisingly I couldn't find a working solution for such a trivial question.
In a Java servlet I need to connect to external web site and in doGet method I'm using
URL website = new URL(websiteUrl);
for this.
This code works on my PC but fails to connect when running on production Linux application server.
I checked Firefox network settings on the server and it is set to use system proxy.
Using echo $http_proxy
command in Linux terminal I read the proxy settings and changed my code to:
URL website = new URL("http", proxy, Integer.parseInt(proxyPort), websiteUrl);
setting proxy settings hard coded.
Now it works but obviously I wouldn't like to hard-code the proxy settings but to read it dynamically.
That is where I stumbled as none of the methods I found on the Internet worked for me.
System.getProperty("http.proxyHost")
System.getProperty("http_proxy")
ProxySelector methods or adding
System.setProperty("java.net.useSystemProxies", "true");
brought no result.
Is there a working solution? Any idea why those common solutions do not work in my case?
I'm running WebLogic 10.3.5/JRockit on RHEL 6. Thanks.