Abhishek Rakshit
Abhishek Rakshit

Reputation: 691

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.

Upvotes: 15

Views: 3718

Answers (3)

Abhishek Rakshit
Abhishek Rakshit

Reputation: 691

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

Upvotes: 1

Jake Sankey
Jake Sankey

Reputation: 5137

The following has always worked for me when setting a proxy.

System.setProperty("https.proxyHost", "myproxy.domain.com");
System.setProperty("https.proxyPort", "myport");

Upvotes: 0

Gepsens
Gepsens

Reputation: 673

Isn't your problem that your plug-in connect phase is executed prior to Eclipse determining the host at runtime ? That's the only difference I see between the static and dynamic definitions of Eclipse's network settings.

Upvotes: 0

Related Questions