我正在开发一个需要连接到远程服务器的Eclipse插件。我正在尝试使用Eclipse网络设置来获取proxyHost和Port。我已经能够使用IProxyService
和IProxyData
类获取“手动”设置代理,如果在本地计算机中设置,也可以使用“本机”代理设置。当proxyProvider设置为Native并且proxyHost和Port值在Eclipse设置中显示为动态时,会发生此问题。有没有办法访问这些值?
感谢。
答案 0 :(得分: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,密码等)。
答案 1 :(得分:0)
在Eclipse在运行时确定主机之前执行插件连接阶段不是问题吗?这是我在Eclipse网络设置的静态和动态定义之间看到的唯一区别。
答案 2 :(得分:0)
设置代理时,以下内容始终适用于我。
System.setProperty("https.proxyHost", "myproxy.domain.com");
System.setProperty("https.proxyPort", "myport");