【问题标题】:How to access dynamic proxies from eclipse network settings?如何从 Eclipse 网络设置中访问动态代理?
【发布时间】:2011-03-10 18:43:46
【问题描述】:

我正在开发一个需要连接到远程服务器的 Eclipse 插件。我正在尝试使用 Eclipse 网络设置来获取 proxyHost 和 Port。我已经能够使用IProxyServiceIProxyData 类获得“手动”设置代理,如果在本地计算机中设置,还可以获得“本机”代理设置。当 proxyProvider 设置为 Native 并且 proxyHost 和 Port 值在 Eclipse 设置中显示为动态时,就会出现问题。有没有办法访问这些值?

谢谢。

【问题讨论】:

  • 动态=不是由javascript函数计算的,基于目标主机吗?您是否尝试过使用 IProxyService.select(URI) 方法并在那里指定您的目标网址?

标签: java eclipse proxy


【解决方案1】:

您的插件连接阶段是在 Eclipse 在运行时确定主机之前执行的,这不是您的问题吗?这是我看到的 Eclipse 网络设置的静态和动态定义之间的唯一区别。

【讨论】:

    【解决方案2】:

    在设置代理时,以下内容一直对我有用。

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

    【讨论】:

      【解决方案3】:

      感谢大家的回复,

      这可以使用 Eclipse 中的 IProxyService 类来完成。下面的代码 sn-ps 在某些情况下使用了反射,您可以忽略。也看看这个链接(http://www.vogella.de/blog/2009/12/08/eclipse-rcp-proxy-preference/)

      1) 获取代理跟踪器

      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) 使用“isProxiesEnabled”方法检查代理是否开启

      3) 根据 eclipse 版本,使用“getProxyDataForHost”或“select”方法访问 eclipse 代理信息(主机、用户 ID、密码等)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-04-28
        • 1970-01-01
        • 1970-01-01
        • 2017-09-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多