org.eclipse.core.net.proxy.IProxyService Java Examples

The following examples show how to use org.eclipse.core.net.proxy.IProxyService. 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: HttpUtil.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("restriction")
private static CachingHttpClientBuilder setupProxy(CachingHttpClientBuilder builder, URI url){
	final IProxyService proxyService = HybridCore.getDefault().getProxyService();
	if(proxyService != null ){
		IProxyData[] proxies = proxyService.select(url);
		if(proxies != null && proxies.length > 0){
			IProxyData proxy = proxies[0];
			CredentialsProvider credsProvider = new BasicCredentialsProvider();
			if(proxy.isRequiresAuthentication()){
				credsProvider.setCredentials(new AuthScope(proxy.getHost(), proxy.getPort()), 
						new UsernamePasswordCredentials(proxy.getUserId(), proxy.getPassword()));
			}
			builder.setDefaultCredentialsProvider(credsProvider);
			builder.setProxy(new HttpHost(proxy.getHost(), proxy.getPort()));
		}
	}
	return builder;
	
}
 
Example #2
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 #3
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 #4
Source File: GoogleApiFactoryTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsetDifferentProxyService() {
  googleApiFactory.setProxyService(proxyService);
  googleApiFactory.unsetProxyService(mock(IProxyService.class));

  verify(proxyService, never()).removeProxyChangeListener(any(IProxyChangeListener.class));
  verify(proxyFactory, never()).setProxyService(null);
  // called once when setProxyService() is called
  verify(transportCache).invalidateAll();
}
 
Example #5
Source File: JSCorePlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void start(BundleContext context) throws Exception // $codepro.audit.disable declaredExceptions
{
	super.start(context);
	PLUGIN = this;

	// Load JS Metadata in background
	new JSMetadataLoader().schedule();

	// Hook up tracker to proxy service
	proxyTracker = new ServiceTracker(getBundle().getBundleContext(), IProxyService.class.getName(), null);
	proxyTracker.open();
}
 
Example #6
Source File: HttpClientService.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
private IProxyData getProxyData(URI uri) {
	IProxyService proxyService = getProxyService();
	if (proxyService != null && proxyService.isProxiesEnabled()) {
		if (!proxyService.isSystemProxiesEnabled()) {
			IProxyData[] proxies = proxyService.select(uri);
			if (proxies.length > 0) {
				return proxies[0];
			}
		}
	}
	return null;
}
 
Example #7
Source File: JavaLanguageServerPlugin.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public IProxyService getProxyService() {
	try {
		if (proxyServiceTracker == null) {
			proxyServiceTracker = new ServiceTracker<>(context, IProxyService.class.getName(), null);
			proxyServiceTracker.open();
		}
		return proxyServiceTracker.getService();
	} catch (Exception e) {
		logException(e.getMessage(), e);
	}
	return null;
}
 
Example #8
Source File: GoogleApiFactory.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
public void unsetProxyService(IProxyService proxyService) {
  if (this.proxyService == proxyService) {
    proxyService.removeProxyChangeListener(proxyChangeListener);
    this.proxyService = null;
    proxyFactory.setProxyService(null);
    if (transportCache != null) {
      transportCache.invalidateAll();
    }
  }
}
 
Example #9
Source File: GoogleApiFactory.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL)
public void setProxyService(IProxyService proxyService) {
  this.proxyService = proxyService;
  this.proxyService.addProxyChangeListener(proxyChangeListener);
  proxyFactory.setProxyService(this.proxyService);
  if (transportCache != null) {
    transportCache.invalidateAll();
  }
}
 
Example #10
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());
}
 
Example #11
Source File: ProxyFactory.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public void setProxyService(IProxyService proxyService) {
  this.proxyService = proxyService;
}
 
Example #12
Source File: HttpClientService.java    From cppcheclipse with Apache License 2.0 4 votes vote down vote up
private boolean isProxiesEnabled() {
	IProxyService proxyService = getProxyService();
	if (proxyService != null && proxyService.isProxiesEnabled())
		return true;
	return false;
}
 
Example #13
Source File: PollingStatusServiceImpl.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
public void unsetProxyService(IProxyService service) {
  if (proxyService == service) {
    proxyService = null;
  }
}
 
Example #14
Source File: PollingStatusServiceImpl.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL)
public void setProxyService(IProxyService proxyService) {
  this.proxyService = proxyService;
}
 
Example #15
Source File: JSCorePlugin.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public IProxyService getProxyService()
{
	return (IProxyService) proxyTracker.getService();
}
 
Example #16
Source File: HybridCore.java    From thym with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Get the proxyservice
 * @return
 */
public IProxyService getProxyService(){
	ServiceReference<IProxyService> sr = context.getServiceReference(IProxyService.class);
	return context.getService(sr);
}
 
Example #17
Source File: HttpClientService.java    From cppcheclipse with Apache License 2.0 2 votes vote down vote up
/**
		 * Binds the {@link IProxyService} service reference.
		 *
		 * @param proxyService the {@link IProxyService} service reference to bind
		 */
protected void bindProxyService(IProxyService proxyService) {
	this.proxyService = proxyService;
}
 
Example #18
Source File: HttpClientService.java    From cppcheclipse with Apache License 2.0 2 votes vote down vote up
/**
 * Unbinds the {@link IProxyService} service reference.
 * 
 * @param proxyService
 *            the {@link IProxyService} service reference to unbind
 */
protected void unbindProxyService(IProxyService proxyService) {
	this.proxyService = null;
}
 
Example #19
Source File: HttpClientService.java    From cppcheclipse with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the {@link IProxyService} instance.
 * 
 * @return the {@link IProxyService} instance
 */
protected IProxyService getProxyService() {
	return proxyService;
}