I am working on an Eclipse plugin which needs to connect to a remote server. I am trying to use the Eclipse network settings to get the proxyHost and Port. I have been able to get the "Manual" settings proxy using the IProxyService
and IProxyData
classes and also "Native" proxy settings if set in the local machine. The problem occurs when the proxyProvider is set to Native and the proxyHost and Port values are shown as dynamic in the Eclipse settings. Is there a way to access those values?
Thanks.
Thanks for the responses guys,
This can be done using the IProxyService class in eclipse. The code snippets below have used reflection in some cases which you can ignore. Also take a look at this link(http://www.vogella.de/blog/2009/12/08/eclipse-rcp-proxy-preference/)
1) Get the proxy tracker
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) Use the "isProxiesEnabled" method to check if proxy is enabled
3) Depending on the eclipse version use the "getProxyDataForHost" or "select" method to access the eclipse proxy information(host, userID, password etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With