我正在开发一个需要连接到远程服务器的 Eclipse 插件。我正在尝试使用 Eclipse 网络设置来获取 proxyHost 和端口。我已经能够使用 IProxyService
和 IProxyData
类获得“手动”设置代理,如果在本地计算机中设置了“ native ”代理设置。当 proxyProvider 设置为 Native 并且 proxyHost 和 Port 值在 Eclipse 设置中显示为动态时,就会出现问题。有没有办法访问这些值?
谢谢。
最佳答案
谢谢大家的回复,
这可以使用 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、密码等)。
关于java - 如何从 Eclipse 网络设置访问动态代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3160435/