Java Code Examples for org.eclipse.core.net.proxy.IProxyService#getProxyData()

The following examples show how to use org.eclipse.core.net.proxy.IProxyService#getProxyData() . 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: 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 2
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());
}