开发者

system proxy setting detection fails

开发者 https://www.devze.com 2023-03-22 05:37 出处:网络
I have some misterious problem with system proxy detection: Actually, I have the right code to detect system proxy settings at r开发者_高级运维untime, it can handle pac files and http proxy settings a

I have some misterious problem with system proxy detection: Actually, I have the right code to detect system proxy settings at r开发者_高级运维untime, it can handle pac files and http proxy settings as well. It works absolutely correct, when I store and execute everything on the target station.

BUT: I run one little piece of code on the target station and store anything else (jars) on another station, on which apache webserver runs. From the main I load the classes with URLClassloader, so that piece of code loaded via network, which responsible for the proxy detection as well. And in this way the default proxy selector give DIRECT all time, it is not able to find the right settings.

I think, the problem is that I want to set the

System.setProperty("java.net.useSystemProxies","true");

In the loaded class and somehow this does not work...But when I sysout the property value, it is true.

I wrote a little test program and the only difference is that:

A)

Class.forname("a"); -> a is in the classpath

B)

URL[] url = new URL[1];
url[0] = new URL("http://1.2.3.4/dtfw");
URLClassloader u = new URLClassloader(url);
Class.forname("a", true, u);

Both piece of code work, the only different is in the output. Does anyone have some idea?

Thanks in advance!!

Zsomi


I found the root cause of the problem:

The DefaultProxySelector is singleton per JVM and the behavior of it based on if System.setProperty("java.net.useSystemProxies","true"); is set or not.

As the URLClassloader uses it, this value is false, when it is instantiated. And when in the "a" class I try to use it, it is not able to find system proxy settings, since at instatiation this property was not set.

So I have the cause, but no solution yet.

Regards, Zsomi

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号