Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java processes using proxy server, hosing up everything

Tags:

java

proxy

I am doing some web sevices work on Java 5 on a mac (10.6.2)....

Ever since IT made us start using a proxy server, life has gotten a lot harder. Java appears to be pulling in the system proxy server settings, but not the exclude list. This means when I try to call a web service for "localhost", java tries to his the proxy server instead and my call blows up. Same for my hostname or IP.

So to work in the office, I have to go to System Settings and remove the proxy configuration. Then it's all good, except I can't hit the internet. No matter what I do in my system settings with the exclude list, it has no effect on Java.

I have tried -Djava.net.useSystemProxies=false and it didn't seem to do anything.

thanks for any help!

like image 270
phil swenson Avatar asked Mar 03 '10 21:03

phil swenson


1 Answers

The definitive reference for network proxy configuration in Java 5 is this Java Networking and Proxies page. From this page, it seems that Java 5 pays no attention to the system settings from the host environment. But even if it is supposed to pay attention to them, the fact that this is (apparently) not working for you means that you should not be relying on this ... at least for now.

In order to explicitly configure a Java 5 JVM to use a default proxy for HTTP you need to set the Java system properties:

  • http.proxyHost - the DNS or IP address of the proxy
  • http.proxyPort - the port number for the proxy
  • http.nonProxyHosts - a list of hosts or domains to connect to directly, separated by the "pipe" character |.

If you are using HTTPS as well, you also need to configure https.proxyHost and https.proxyPort.

And, I think you have to set http.proxyHost for http.nonProxyHosts to have any effect. Setting the latter by itself may have no effect.

More details are in the page linked above. I'd recommending using "-D" options in the command script that you use to launch the app. Maybe you could make this script pull the proxy parameters from the system settings.

Note that in Java 6 and later, network proxy support changes (again) and a Java 6 JVM will pick up and use system settings from the host environment under certain circumstances.

like image 121
Stephen C Avatar answered Oct 24 '22 01:10

Stephen C