Reputation: 11040
I'm messing around with proxy settings and the JVM. Apparently, OS X (Maverics in my case) is the only system on which the JVM (1.8_92 as of today) automagically applies whatever proxies are set in system preferences. Any other systems I tested it with (Arch Linux with openbox, no Gnome/KDE, Windows 7, some up-to-date Debian version) don't do that, it is either necessary to use '-Djava.net.useSystemProxies' (works on Windows), or explicitly set the proxies using '-Dhttp.proxyHost=...' etc.
I'm pretty sure OS X system proxies are applied, as I used a special 'marker' proxy host name in the preferences; when I change the host name, the JVM changes its proxy settings to the new host name (I need to restart the JVM, though, it doesn't change while the JVM is running, but that's OK).
I find this behavior cool (apparently, proxies just work out of the box with OS X, which is refreshing after tons of issues I had with other systems), but it seems to not be documented anywhere.
Can someone confirm that it's the JVM on OS X who does the magic? And where does it happen and by whom? I could imagine multiple ways of achieving this: the JVM for Macs could be smart and know how to look up OS X's proxy settings, or there could be some config file written whenever network settings change, and the JVM could simply read it at startup, or ... Many options, but how does it actually work?
Upvotes: 1
Views: 774
Reputation: 24050
There's a call to GetJavaProperties in libjava
which is implementation dependent; Mac OSX shares the general Unix implementation. This is used to set up any system properties such that they are then stamped on the general Java properties such as the file system's default encoding and so forth.
There's a bit down the bottom that is conditionally included for MACOSX
that calls setProxyProperties
which performs the proxy lookup using the OSX standard System Configuration framework.
Once the system proxy information is known it gets passed back up through the call chain into System.c
that says if the proxy information is found the standard Java system properties http.proxyPort
etc. are set.
So the call stack is:
Java_java_lang_System_initProperties
GetJavaProperties
setProxyProperties
SCDynamicStoreCopyProxies
<- the OSX specific callFollowed by the PUTPROP
in the initProperties
method if the above returns something.
Upvotes: 3