开发者

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 clas开发者_如何学Pythonses 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).


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.


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜