Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access dynamic proxies from eclipse network settings?

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.

like image 311
Abhishek Rakshit Avatar asked Jul 01 '10 18:07

Abhishek Rakshit


1 Answers

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).

like image 160
Abhishek Rakshit Avatar answered Sep 19 '22 07:09

Abhishek Rakshit