2015-08-31 104 views
0

在测试中,我试图以编程方式更改Eclipse代理设置而不直接影响System属性。IProxyService.setProxyData影响系统属性

我现在的尝试是这样:

httpProxyData.setHost(host) 
    httpProxyData.setPort(port) 
    httpProxyData.setUserid(userId) 
    httpProxyData.setPassword(password) 

    proxyService.setProxyData((IProxyData[]) [ 
     httpProxyData 
    ]) 

我的代理服务设置如下:

proxyService.setProxiesEnabled(true) 
    proxyService.setSystemProxiesEnabled(false) 

proxyService.setProxyData执行,System.getproperty("http.proxyHost")立即变为hostIProxyService API指出System属性不会受到影响。我希望它能使System属性只受到我在稍后或更早时间设置System.setProperty(..., ...)的影响。

我做错了什么吗?

回答

1

该文档说'不会影响系统代理的设置' - 我认为这意味着它不会更改操作系统中的设置。

查看代码,它总是调用System.setProperty(它只设置当前JVM的属性)。

+0

感谢greg-449。你指的是什么代码?我看了一下'ProxyManager',但是我找不到任何设置系统属性的东西。 – Citronen

+1

'org.eclipse.core.internal.net.ProxyType'。它实际上调用'System.getProperties'并操作返回的属性。 –

+0

有趣。在一个全新的项目中,当我在首选项(通过UI)中设置Eclipse代理设置时,然后创建一个程序来查询像'System.getProperty(“http.proxyHost”);'',它返回'null'。你碰巧知道如果使用UI调用'proxyService.setProxyData'的行吗? – Citronen