2010-07-01 73 views
15

我正在研究需要連接到遠程服務器的Eclipse插件。我正在嘗試使用Eclipse網絡設置來獲取proxyHost和端口。我已經能夠使用IProxyServiceIProxyData類以及「本地」代理設置(如果在本地計算機上設置)來獲取「手動」設置代理。當proxyProvider設置爲Native並且在Eclipse設置中proxyHost和Port值顯示爲動態時,會發生此問題。有沒有辦法訪問這些值?如何從eclipse網絡設置訪問動態代理?

謝謝。

+1

是不是動態=由javascript函數計算,基於目標主機?您是否嘗試過使用IProxyService.select(URI)方法並在那裏指定目標網址? – 2011-03-30 20:38:42

回答

0

您的插件連接階段是否在Eclipse確定運行時的主機之前執行,這不是您的問題嗎?這是我在Eclipse的網絡設置的靜態和動態定義之間唯一的區別。

0

以下設置代理時一直適用於我。

System.setProperty("https.proxyHost", "myproxy.domain.com"); 
System.setProperty("https.proxyPort", "myport"); 
1

感謝您的答覆傢伙,

這可以使用Eclipse中的IProxyService類來完成。下面的代碼片段在一些可以忽略的情況下使用了反射。也看看這個鏈接(http://www.vogella.de/blog/2009/12/08/eclipse-rcp-proxy-preference/

1)獲取代理跟蹤

private ServiceTracker getProxyTracker() throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { 
    if (proxyTracker != null) 
     return proxyTracker; 

    String proxyServiceClassName = "org.eclipse.core.net.proxy.IProxyService"; 
    String bundleClassName = "org.osgi.framework.Bundle"; 
    Class bundleClass = Class.forName(bundleClassName); 
    Method getBundleContextMth = bundleClass.getMethod("getBundleContext", null); 
    getBundleContextMth.setAccessible(true); 

    BundleContext bundleCntx = (BundleContext) getBundleContextMth.invoke(bundle, null); 
    proxyTracker = new ServiceTracker(bundleCntx, proxyServiceClassName, null); 
    proxyTracker.open(); 

    return proxyTracker; 
} 

2)使用 「isProxiesEnabled」 的方法來檢查,如果代理啓用

3)根據eclipse版本使用「getProxyDataForHost」或「select」方法來訪問eclipse代理信息(主機,用戶ID,密碼等)。