org.eclipse.core.net.proxy.IProxyData Java Examples
The following examples show how to use
org.eclipse.core.net.proxy.IProxyData.
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 |
@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 |
/** * Given proxy data, we try to convert that back into a full URL * * @param data * The {@link IProxyData} we're converting into a URL string. * @param env * The environment map. Passed in so we can flag passwords to obfuscate (in other words, we may modify * the map) * @return */ private String buildProxyURL(IProxyData data, Map<String, String> env) { StringBuilder builder = new StringBuilder(); builder.append("http://"); //$NON-NLS-1$ if (!StringUtil.isEmpty(data.getUserId())) { builder.append(data.getUserId()); builder.append(':'); String password = data.getPassword(); builder.append(password); builder.append('@'); env.put(IProcessRunner.TEXT_TO_OBFUSCATE, password); } builder.append(data.getHost()); if (data.getPort() != -1) { builder.append(':'); builder.append(data.getPort()); } return builder.toString(); }
Example #3
Source File: NodePackageManager.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * 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: HttpClientService.java From cppcheclipse with Apache License 2.0 | 6 votes |
private Proxy getProxyFromProxyData(IProxyData proxyData) throws UnknownHostException { Type proxyType; if (IProxyData.HTTP_PROXY_TYPE.equals(proxyData.getType())) { proxyType = Type.HTTP; } else if (IProxyData.SOCKS_PROXY_TYPE.equals(proxyData.getType())) { proxyType = Type.SOCKS; } else if (IProxyData.HTTPS_PROXY_TYPE.equals(proxyData.getType())) { proxyType = Type.HTTP; } else { throw new IllegalArgumentException("Invalid proxy type " + proxyData.getType()); } InetSocketAddress sockAddr = new InetSocketAddress(InetAddress.getByName(proxyData.getHost()), proxyData.getPort()); Proxy proxy = new Proxy(proxyType, sockAddr); if (!Strings.isNullOrEmpty(proxyData.getUserId())) { Authenticator.setDefault(new ProxyAuthenticator(proxyData.getUserId(), proxyData.getPassword())); } return proxy; }
Example #5
Source File: ProxyFactory.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@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 #6
Source File: PollingStatusServiceImpl.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
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 #7
Source File: ProxyFactoryTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private IProxyData createProxyData(String proxyType, String host, int port) { IProxyData proxyData = mock(IProxyData.class); when(proxyData.getType()).thenReturn(proxyType); when(proxyData.getHost()).thenReturn(host); when(proxyData.getPort()).thenReturn(port); return proxyData; }
Example #8
Source File: HttpClientService.java From cppcheclipse with Apache License 2.0 | 5 votes |
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 #9
Source File: HttpClientService.java From cppcheclipse with Apache License 2.0 | 5 votes |
private Proxy getProxy(URI uri) throws UnknownHostException { IProxyData proxyData = getProxyData(uri); if (proxyData == null) { if (!isProxiesEnabled()) { return Proxy.NO_PROXY; } return null; } return getProxyFromProxyData(proxyData); }
Example #10
Source File: XMLLanguageServer.java From wildwebdeveloper with Eclipse Public License 2.0 | 5 votes |
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: ProxyFactoryTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testCreateProxy_settingProxyServiceToNullCreatesDirectConnection() { proxyFactory.setProxyService(proxyService); IProxyData proxyData = createProxyData(IProxyData.HTTPS_PROXY_TYPE, PROXY_HOST, PROXY_PORT); when(proxyService.select(any(URI.class))).thenReturn(new IProxyData[]{ proxyData }); assertThat(proxyFactory.createProxy(exampleUri).type(), is(Proxy.Type.HTTP)); proxyFactory.setProxyService(null); assertThat(proxyFactory.createProxy(exampleUri).type(), is(Proxy.Type.DIRECT)); }
Example #12
Source File: ProxyFactoryTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testCreateProxy_ifSocksIsFirstItWillBeUsed() { proxyFactory.setProxyService(proxyService); IProxyData httpsProxyData = createProxyData(IProxyData.HTTPS_PROXY_TYPE, PROXY_HOST, PROXY_PORT); IProxyData socksProxyData = createProxyData(IProxyData.SOCKS_PROXY_TYPE, PROXY_HOST, PROXY_PORT); when(proxyService.select(any(URI.class))) .thenReturn(new IProxyData[]{ socksProxyData, httpsProxyData }); assertThat(proxyFactory.createProxy(exampleUri).type(), is(Proxy.Type.SOCKS)); }
Example #13
Source File: ProxyFactoryTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testCreateProxy_ifHttpsIsFirstItWillBeUsed() { proxyFactory.setProxyService(proxyService); IProxyData httpsProxyData = createProxyData(IProxyData.HTTPS_PROXY_TYPE, PROXY_HOST, PROXY_PORT); IProxyData socksProxyData = createProxyData(IProxyData.SOCKS_PROXY_TYPE, PROXY_HOST, PROXY_PORT); when(proxyService.select(any(URI.class))) .thenReturn(new IProxyData[]{ httpsProxyData, socksProxyData }); assertThat(proxyFactory.createProxy(exampleUri).type(), is(Proxy.Type.HTTP)); }
Example #14
Source File: ProxyFactoryTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testCreateProxy_unsupportedProxyData() { proxyFactory.setProxyService(proxyService); IProxyData proxyData = createProxyData(IProxyData.HTTP_PROXY_TYPE, PROXY_HOST, PROXY_PORT); when(proxyService.select(any(URI.class))).thenReturn(new IProxyData[]{ proxyData }); assertThat(proxyFactory.createProxy(exampleUri).type(), is(Proxy.Type.DIRECT)); }
Example #15
Source File: ProxyFactoryTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testCreateProxy_socksProxyData() { proxyFactory.setProxyService(proxyService); IProxyData proxyData = createProxyData(IProxyData.SOCKS_PROXY_TYPE, PROXY_HOST, PROXY_PORT); when(proxyService.select(any(URI.class))).thenReturn(new IProxyData[]{ proxyData }); assertThat(proxyFactory.createProxy(exampleUri).type(), is(Proxy.Type.SOCKS)); }
Example #16
Source File: ProxyFactoryTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testCreateProxy_httpsProxyData() { proxyFactory.setProxyService(proxyService); IProxyData proxyData = createProxyData(IProxyData.HTTPS_PROXY_TYPE, PROXY_HOST, PROXY_PORT); when(proxyService.select(any(URI.class))).thenReturn(new IProxyData[]{ proxyData }); assertThat(proxyFactory.createProxy(exampleUri).type(), is(Proxy.Type.HTTP)); }
Example #17
Source File: GoogleApiFactoryWithProxyServerTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testInit_ProxyChangeHandlerIsSet() { when(proxyService.select(any(URI.class))).thenReturn(new IProxyData[0]); googleApiFactory.setProxyService(proxyService); googleApiFactory.init(); verify(proxyService).addProxyChangeListener(any(IProxyChangeListener.class)); }
Example #18
Source File: ProxyFactoryTest.java From google-cloud-eclipse with Apache License 2.0 | 4 votes |
@Test public void testCreateProxy_noProxyDataCreatesDirectConnection() { proxyFactory.setProxyService(proxyService); when(proxyService.select(any(URI.class))).thenReturn(new IProxyData[0]); assertThat(proxyFactory.createProxy(exampleUri).type(), is(Proxy.Type.DIRECT)); }