2010-07-01 74 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,密码等)。