Search in sources :

Example 6 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData 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)

Example 7 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData in project ecf by eclipse.

the class ProxySetupHelper method getProxy.

public static Proxy getProxy(String url) {
    Proxy proxy = null;
    try {
        IProxyService proxyService = Activator.getDefault().getProxyService();
        // Only do this if platform service exists
        if (proxyService != null && proxyService.isProxiesEnabled()) {
            // Setup via proxyService entry
            URI uri = new URI(url);
            final IProxyData[] proxies = proxyService.select(uri);
            IProxyData selectedProxy = selectProxyFromProxies(uri.getScheme(), proxies);
            if (selectedProxy != null) {
                proxy = new Proxy(((selectedProxy.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) ? Proxy.Type.SOCKS : Proxy.Type.HTTP), new ProxyAddress(selectedProxy.getHost(), selectedProxy.getPort()), selectedProxy.getUserId(), selectedProxy.getPassword());
            }
        }
    } catch (Exception e) {
        // If we don't even have the classes for this (i.e. the org.eclipse.core.net plugin not available)
        // then we simply log and ignore
        Activator.logNoProxyWarning(e);
    } catch (NoClassDefFoundError e) {
        Activator.logNoProxyWarning(e);
    }
    return proxy;
}
Also used : Proxy(org.eclipse.ecf.core.util.Proxy) IProxyData(org.eclipse.core.net.proxy.IProxyData) ProxyAddress(org.eclipse.ecf.core.util.ProxyAddress) URI(java.net.URI) IProxyService(org.eclipse.core.net.proxy.IProxyService)

Example 8 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData in project ecf by eclipse.

the class AbstractRetrieveTestCase method addProxy.

protected void addProxy(final String proxyHost, final int port, final String username, final String password) throws Exception {
    IProxyService proxyService = Activator.getDefault().getProxyService();
    proxyService.setProxiesEnabled(true);
    proxyService.setSystemProxiesEnabled(false);
    IProxyData proxyData = new IProxyData() {

        public void disable() {
        }

        public String getHost() {
            return proxyHost;
        }

        public String getPassword() {
            return password;
        }

        public int getPort() {
            return port;
        }

        public String getType() {
            return "HTTP";
        }

        public String getUserId() {
            return username;
        }

        public boolean isRequiresAuthentication() {
            return (username != null);
        }

        public void setHost(String host) {
        }

        public void setPassword(String password) {
        }

        public void setPort(int port) {
        }

        public void setUserid(String userid) {
        }

        // TODO: What is the current expected target
        public String getSource() {
            // TODO Auto-generated method stub
            return null;
        }

        public void setSource(String source) {
        // TODO Auto-generated method stub
        }
    };
    proxyService.setProxyData(new IProxyData[] { proxyData });
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData) IProxyService(org.eclipse.core.net.proxy.IProxyService)

Example 9 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData in project portfolio by buchen.

the class ProxyAddon method setupProxy.

private void setupProxy(IProxyService proxyService, String proxyHost, int proxyPort) {
    try {
        IProxyData[] proxyData = proxyService.getProxyData();
        for (IProxyData data : proxyData) {
            if (IProxyData.HTTP_PROXY_TYPE.equals(data.getType()) || IProxyData.HTTPS_PROXY_TYPE.equals(data.getType())) {
                data.setHost(proxyHost);
                data.setPort(proxyHost == null ? -1 : proxyPort);
                // $NON-NLS-1$
                data.setUserid(proxyHost == null ? null : System.getProperty("name.abuchen.portfolio.proxyUser"));
                data.setPassword(proxyHost == null ? null : // $NON-NLS-1$
                System.getProperty("name.abuchen.portfolio.proxyPassword"));
            }
        }
        proxyService.setProxyData(proxyData);
        proxyService.setSystemProxiesEnabled(false);
        proxyService.setProxiesEnabled(true);
    } catch (CoreException e) {
        PortfolioPlugin.log(e);
    }
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData) CoreException(org.eclipse.core.runtime.CoreException)

Example 10 with IProxyData

use of org.eclipse.core.net.proxy.IProxyData in project gemoc-studio by eclipse.

the class Activator method prepareProxySettings.

public void prepareProxySettings(String uriString) {
    URI uri;
    try {
        uri = new URI(uriString);
        IProxyService proxyService = Activator.getDefault().getProxyService();
        IProxyData[] proxyDataForHost = proxyService.select(uri);
        for (IProxyData data : proxyDataForHost) {
            if (data.getHost() != null) {
                System.setProperty("http.proxySet", "true");
                System.setProperty("http.proxyHost", data.getHost());
            }
            if (data.getHost() != null) {
                System.setProperty("http.proxyPort", String.valueOf(data.getPort()));
            }
        }
        // Close the service and close the service tracker
        proxyService = null;
    } catch (URISyntaxException e) {
        getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, e.getMessage(), e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProxyData(org.eclipse.core.net.proxy.IProxyData) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IProxyService(org.eclipse.core.net.proxy.IProxyService)

Aggregations

IProxyData (org.eclipse.core.net.proxy.IProxyData)18 IProxyService (org.eclipse.core.net.proxy.IProxyService)11 URI (java.net.URI)8 URISyntaxException (java.net.URISyntaxException)8 HttpHost (org.apache.http.HttpHost)5 CoreException (org.eclipse.core.runtime.CoreException)4 AuthScope (org.apache.http.auth.AuthScope)3 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)3 PasswordAuthentication (java.net.PasswordAuthentication)2 Authenticator (java.net.Authenticator)1 InetAddress (java.net.InetAddress)1 Proxy (java.net.Proxy)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 ProxyHost (org.apache.commons.httpclient.ProxyHost)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 NTCredentials (org.apache.http.auth.NTCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1