I am developing a Java application that makes HTTP requests, and half of my development time is behind a proxy. So I have the following block in my code:
if (BEHIND_PROXY) {
java.util.Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost", PROXY_HOST);
systemProperties.setProperty("http.proxyPort", PROXY_PORT);
}
The idea is that I change the value of BEHIND_PROXY
based on where I am. I was working today, not behind a proxy, and forgot to set BEHIND_PROXY
to false
. However, the connection was still made successfully and my application received the data it requested. How is this possible? Is there something built into this, that if the proxy server cannot be reached, it simply tries again but bypasses the proxy on this retry?
And a second question, I have been trying to find a complete list of system properties. I have found many posts like THIS one, but not one of them lists http.proxyHost
or http.proxyPort
, which makes me think they are clearly not very complete. Am I searching wrong somehow? Do these http.x
properties belong in these other lists? Is there a more complete list somewhere?
Yes.
I was surprised to see this, but here it is in the source of the internal connection: sun.net.www.protocol.http.HttpURLConnection. On line 760, if we've tried all the available proxies and failed to connect, we try a non-proxied connection.
Maybe. Right or wrong, the Java philosophy seems to be that system properties are ad-hoc things and the only way to know that one exists is to read the documentation for the thing that it affects. In this case, HttpURLConnection links to a page on Networking Properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With