Java system Properties, http.proxyHost, two questions
Asked Answered
F

1

9

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?

Frequentative answered 6/12, 2012 at 11:9 Comment(0)
M
11

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.

Mertiemerton answered 8/3, 2013 at 17:10 Comment(1)
Awesome, much thanks for answering a presumed dead question! Good to see proof of my suspicions.Frequentative

© 2022 - 2024 — McMap. All rights reserved.