Search in sources :

Example 6 with IProxyService

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);
}
Also used : IProxyService(org.eclipse.core.net.proxy.IProxyService) BundleContext(org.osgi.framework.BundleContext)

Example 7 with IProxyService

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)));
    }
}
Also used : IProxyService(org.eclipse.core.net.proxy.IProxyService) ServiceReference(org.osgi.framework.ServiceReference)

Example 8 with IProxyService

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;
}
Also used : IProxyService(org.eclipse.core.net.proxy.IProxyService) BundleContext(org.osgi.framework.BundleContext)

Example 9 with IProxyService

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;
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData) HttpHost(org.apache.http.HttpHost) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IProxyService(org.eclipse.core.net.proxy.IProxyService)

Example 10 with IProxyService

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);
        }
    }
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData) URISyntaxException(java.net.URISyntaxException) ProxyHost(org.apache.commons.httpclient.ProxyHost) URI(java.net.URI) IProxyService(org.eclipse.core.net.proxy.IProxyService) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Aggregations

IProxyService (org.eclipse.core.net.proxy.IProxyService)18 IProxyData (org.eclipse.core.net.proxy.IProxyData)11 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)7 BundleContext (org.osgi.framework.BundleContext)4 HttpHost (org.apache.http.HttpHost)3 CoreException (org.eclipse.core.runtime.CoreException)3 PasswordAuthentication (java.net.PasswordAuthentication)2 ServiceReference (org.osgi.framework.ServiceReference)2 ServiceTracker (org.osgi.util.tracker.ServiceTracker)2 IOException (java.io.IOException)1 Authenticator (java.net.Authenticator)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 UnknownHostException (java.net.UnknownHostException)1 Inject (javax.inject.Inject)1 ProxyHost (org.apache.commons.httpclient.ProxyHost)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 AuthScope (org.apache.http.auth.AuthScope)1