2015-08-31 107 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