use of org.eclipse.core.net.proxy.IProxyService in project egit by eclipse.
the class TestUtil method disableProxy.
/**
* Disables usage of proxy servers
*/
public static void disableProxy() {
BundleContext context = Activator.getDefault().getBundle().getBundleContext();
ServiceReference<IProxyService> serviceReference = context.getServiceReference(IProxyService.class);
IProxyService proxyService = context.getService(serviceReference);
proxyService.setSystemProxiesEnabled(false);
proxyService.setProxiesEnabled(false);
}
use of org.eclipse.core.net.proxy.IProxyService in project egit by eclipse.
the class Activator method setupProxy.
@SuppressWarnings("unchecked")
private void setupProxy(final BundleContext context) {
final ServiceReference proxy;
proxy = context.getServiceReference(IProxyService.class.getName());
if (proxy != null) {
ProxySelector.setDefault(new EclipseProxySelector((IProxyService) context.getService(proxy)));
Authenticator.setDefault(new EclipseAuthenticator((IProxyService) context.getService(proxy)));
}
}
use of org.eclipse.core.net.proxy.IProxyService in project webtools.sourceediting by eclipse.
the class HttpClientProvider method getProxyService.
public static IProxyService getProxyService() {
BundleContext bc = JSONPlugin.getDefault().getBundle().getBundleContext();
ServiceReference<?> serviceReference = bc.getServiceReference(IProxyService.class.getName());
IProxyService service = (IProxyService) bc.getService(serviceReference);
return service;
}
use of org.eclipse.core.net.proxy.IProxyService in project webtools.sourceediting by eclipse.
the class HttpClientProvider method getProxy.
private static HttpHost getProxy(HttpHost target) {
final IProxyService proxyService = getProxyService();
IProxyData[] select = null;
try {
select = proxyService.select(new URI(target.toURI()));
} catch (URISyntaxException e) {
logWarning(e);
return null;
}
String type = target.getSchemeName();
for (IProxyData proxyData : select) {
if (proxyData.getType().equals(type)) {
return new HttpHost(proxyData.getHost(), proxyData.getPort());
}
}
return null;
}
use of org.eclipse.core.net.proxy.IProxyService in project tdq-studio-se by Talend.
the class EcosystemProxyAdapter method adapt.
/**
* DOC bZhou Comment method "adapt".
*
* @param httpclient
* @param url
*/
public static void adapt(HttpClient httpclient, String url) {
IProxyService proxyService = EcosPlugin.getDefault().getProxyService();
IProxyData proxyData = null;
try {
IProxyData[] proxyDatas = proxyService.select(new URI(url));
if (proxyDatas != null && proxyDatas.length > 0) {
proxyData = proxyDatas[0];
}
} catch (URISyntaxException e) {
log.error(e, e);
}
if (proxyData == null) {
proxyData = proxyService.getProxyData(IProxyData.HTTP_PROXY_TYPE);
}
if (proxyData != null & StringUtils.isNotEmpty(proxyData.getHost())) {
// use proxy to connect
ProxyHost host = new ProxyHost(proxyData.getHost(), proxyData.getPort());
httpclient.getHostConfiguration().setProxyHost(host);
httpclient.getParams().setAuthenticationPreemptive(true);
String userId = proxyData.getUserId();
if (StringUtils.isNotEmpty(userId)) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userId, proxyData.getPassword());
httpclient.getState().setProxyCredentials(AuthScope.ANY, credentials);
}
}
}
Aggregations