How to retrieve proxy settings within Eclipse

This class helps to retrieve the proxy settings stored in the preferences of Eclipse.
It automatically retrieves such settings using an IProxyService instance provided by the Eclipse RCP platform.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public class ProxyManager { private final static ServiceTracker<IProxyService, IProxyService> proxyTracker; protected static Logger log = Logger.getLogger(ProxyManager.class); static { proxyTracker = new ServiceTracker<IProxyService, IProxyService>(FrameworkUtil.getBundle(ProxyManager.class).getBundleContext(), IProxyService.class.getName(), null);; } private static IProxyService getProxyService() { return proxyTracker.getService(); } public static void setProxy() { IProxyService proxyService = getProxyService(); IProxyData[] proxyDataForHost = null; try { proxyDataForHost = URI(AppConfig.get().getSiteBasePath())); } catch (URISyntaxException e) { log.error("CAnnot find url for proxy service due to " + e, e); return; } if (proxyDataForHost != null) { for (IProxyData data : proxyDataForHost) { if (data.getHost() != null) { WebConnector.setProxySettings(data.getHost(), data.getPort()); } } } // Close the service and close the service tracker proxyService = null; } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus