Java system Properties, http.proxyHost, two questions
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?
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.
Am I searching wrong somehow?
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.
The111
Prior open source work: www.gpxcreator.com Click here to learn about recursion!
Updated on July 25, 2022Comments
-
The111 almost 2 years
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 setBEHIND_PROXY
tofalse
. 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
orhttp.proxyPort
, which makes me think they are clearly not very complete. Am I searching wrong somehow? Do thesehttp.x
properties belong in these other lists? Is there a more complete list somewhere? -
The111 about 11 yearsAwesome, much thanks for answering a presumed dead question! Good to see proof of my suspicions.