Java Code Examples for org.eclipse.core.net.proxy.IProxyData#getHost()

The following examples show how to use org.eclipse.core.net.proxy.IProxyData#getHost() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PollingStatusServiceImpl.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private Proxy getProxy(URI uri) {
  if (proxyService == null) {
    return Proxy.NO_PROXY;
  }
  IProxyData[] proxies = proxyService.select(uri);
  for (IProxyData proxyData : proxies) {
    switch (proxyData.getType()) {
      case IProxyData.HTTPS_PROXY_TYPE:
      case IProxyData.HTTP_PROXY_TYPE:
        return new Proxy(
            Type.HTTP, new InetSocketAddress(proxyData.getHost(), proxyData.getPort()));
      case IProxyData.SOCKS_PROXY_TYPE:
        return new Proxy(
            Type.SOCKS, new InetSocketAddress(proxyData.getHost(), proxyData.getPort()));
      default:
        logger.warning("Unknown proxy-data type: " + proxyData.getType()); //$NON-NLS-1$
        break;
    }
  }
  return Proxy.NO_PROXY;
}
 
Example 2
Source File: ProxyFactory.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public Proxy createProxy(URI uri) {
  Preconditions.checkNotNull(uri, "uri is null");
  Preconditions.checkArgument(!"http".equals(uri.getScheme()), "http is not a supported schema");

  IProxyService proxyServiceCopy = proxyService;
  if (proxyServiceCopy == null) {
    return Proxy.NO_PROXY;
  }

  IProxyData[] proxyDataForUri = proxyServiceCopy.select(uri);
  for (final IProxyData iProxyData : proxyDataForUri) {
    switch (iProxyData.getType()) {
      case IProxyData.HTTPS_PROXY_TYPE:
        return new Proxy(Type.HTTP, new InetSocketAddress(iProxyData.getHost(),
                                                          iProxyData.getPort()));
      case IProxyData.SOCKS_PROXY_TYPE:
        return new Proxy(Type.SOCKS, new InetSocketAddress(iProxyData.getHost(),
                                                           iProxyData.getPort()));
      default:
        logger.warning("Unsupported proxy type: " + iProxyData.getType());
        break;
    }
  }
  return Proxy.NO_PROXY;
}
 
Example 3
Source File: NodePackageManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This will return a list of arguments for proxy settings (if we have any, otherwise an empty list).
 * 
 * @param env
 *            The environment map. Passed in so we can flag passwords to obfuscate (in other words, we may modify
 *            the map)
 */
private List<String> proxySettings(Map<String, String> env)
{
	IProxyService service = JSCorePlugin.getDefault().getProxyService();
	if (service == null || !service.isProxiesEnabled())
	{
		return Collections.emptyList();
	}

	List<String> proxyArgs = new ArrayList<String>(4);
	IProxyData httpData = service.getProxyData(IProxyData.HTTP_PROXY_TYPE);
	if (httpData != null && httpData.getHost() != null)
	{
		CollectionsUtil.addToList(proxyArgs, "--proxy", buildProxyURL(httpData, env)); //$NON-NLS-1$
	}
	IProxyData httpsData = service.getProxyData(IProxyData.HTTPS_PROXY_TYPE);
	if (httpsData != null && httpsData.getHost() != null)
	{
		CollectionsUtil.addToList(proxyArgs, "--https-proxy", buildProxyURL(httpsData, env)); //$NON-NLS-1$
	}
	return proxyArgs;
}
 
Example 4
Source File: XMLLanguageServer.java    From wildwebdeveloper with Eclipse Public License 2.0 5 votes vote down vote up
private Collection<? extends String> getProxySettings() {
	Map<String, String> res = new HashMap<>();
	for (Entry<Object, Object> entry : System.getProperties().entrySet()) {
		if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
			String property = (String) entry.getKey();
			if (property.toLowerCase().contains("proxy") || property.toLowerCase().contains("proxies")) {
				res.put(property, (String) entry.getValue());
			}
		}
	}
	BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();
	ServiceReference<IProxyService> serviceRef = bundleContext.getServiceReference(IProxyService.class);
	if (serviceRef != null) {
		IProxyService service = bundleContext.getService(serviceRef);
		if (service != null) {
			for (IProxyData data : service.getProxyData()) {
				if (data.getHost() != null) {
					res.put(data.getType().toLowerCase() + ".proxyHost", data.getHost());
					res.put(data.getType().toLowerCase() + ".proxyPort", Integer.toString(data.getPort()));
				}
			}
			String nonProxiedHosts = String.join("|", service.getNonProxiedHosts());
			if (!nonProxiedHosts.isEmpty()) {
				res.put("http.nonProxyHosts", nonProxiedHosts);
				res.put("https.nonProxyHosts", nonProxiedHosts);
			}
		}
	}
	return res.entrySet().stream().map(entry -> "-D" + entry.getKey() + '=' + entry.getValue())
			.collect(Collectors.toSet());
}