This is really unexpected behavior. I’m writing a simple web browser using the JavaFX WebView. To make the web requests go through a local proxy, I wrote code similar to this:
System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", "8080");
It appears to work fine if the proxy is running. However, if it isn’t, Java silently reverts to not using a proxy at all! How can I force Java to fail if the proxy is not available?
You may be able to do this with a custom
ProxySelectorwhich only allows your proxy, and doesn’t offerProxy.NO_PROXYas an alternative:You install this selector using
ProxySelector.setDefault(new AlwaysProxySelector());