Search in sources :

Example 1 with ProxyAddress

use of org.eclipse.ecf.core.util.ProxyAddress 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 2 with ProxyAddress

use of org.eclipse.ecf.core.util.ProxyAddress in project ecf by eclipse.

the class HttpClientFileSystemBrowser method setupProxy.

protected void setupProxy(Proxy proxy) {
    if (proxy.getType().equals(Proxy.Type.HTTP)) {
        final ProxyAddress address = proxy.getAddress();
        ConnRouteParams.setDefaultProxy(httpClient.getParams(), new HttpHost(address.getHostName(), address.getPort()));
    } else if (proxy.getType().equals(Proxy.Type.SOCKS)) {
        // $NON-NLS-1$
        Trace.trace(Activator.PLUGIN_ID, "brows socksproxy=" + proxy.getAddress());
        proxyHelper.setupProxy(proxy);
    }
}
Also used : ProxyAddress(org.eclipse.ecf.core.util.ProxyAddress) HttpHost(org.apache.http.HttpHost)

Example 3 with ProxyAddress

use of org.eclipse.ecf.core.util.ProxyAddress in project ecf by eclipse.

the class HttpClientRetrieveFileTransfer method setupProxy.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer#setupProxy(org.eclipse.ecf.core.util.Proxy)
	 */
protected void setupProxy(Proxy proxy) {
    // $NON-NLS-1$
    Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, HttpClientRetrieveFileTransfer.class, "setupProxy " + proxy);
    if (proxy.getType().equals(Proxy.Type.HTTP)) {
        final ProxyAddress address = proxy.getAddress();
        ConnRouteParams.setDefaultProxy(httpClient.getParams(), new HttpHost(address.getHostName(), address.getPort()));
    // getHostConfiguration().setProxy(address.getHostName(), address.getPort());
    } else if (proxy.getType().equals(Proxy.Type.SOCKS)) {
        // $NON-NLS-1$
        Trace.trace(Activator.PLUGIN_ID, "retrieve socksproxy=" + proxy.getAddress());
        proxyHelper.setupProxy(proxy);
    }
}
Also used : ProxyAddress(org.eclipse.ecf.core.util.ProxyAddress) HttpHost(org.apache.http.HttpHost)

Example 4 with ProxyAddress

use of org.eclipse.ecf.core.util.ProxyAddress in project ecf by eclipse.

the class URLRetrieveTestProxy method setUp.

// This test depends upon the setting of two system properties:
// org.eclipse.ecf.tests.filetransfer.URLRetrieveTestProxy.proxyHost=<proxy host name>
// org.eclipse.ecf.tests.filetransfer.URLRetrieveTestProxy.proxyPort=<proxy port>
// org.eclipse.ecf.tests.filetransfer.URLRetrieveTestProxy.proxyUsername=<username for proxy authentication>
// org.eclipse.ecf.tests.filetransfer.URLRetrieveTestProxy.proxyPassword=<password for proxy authentication>
// e.g.
// org.eclipse.ecf.tests.filetransfer.URLRetrieveTestProxy.proxyHost=myproxy.foo.com
// org.eclipse.ecf.tests.filetransfer.URLRetrieveTestProxy.proxyPort=8888
/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
protected void setUp() throws Exception {
    super.setUp();
    // "localhost", 909)));
    try {
        String proxyName = System.getProperty(this.getClass().getName() + ".proxyHost");
        if (proxyName != null) {
            String pPort = System.getProperty(this.getClass().getName() + ".proxyPort");
            int proxyPort = ((pPort != null) ? Integer.parseInt(pPort) : 9808);
            String username = System.getProperty(this.getClass().getName() + ".proxyUsername");
            if (username != null) {
                String password = System.getProperty(this.getClass().getName() + ".proxyPassword");
                retrieveAdapter.setProxy(new Proxy(Proxy.Type.HTTP, new ProxyAddress(proxyName, proxyPort), username, password));
            } else {
                retrieveAdapter.setProxy(new Proxy(Proxy.Type.HTTP, new ProxyAddress(proxyName, proxyPort)));
            }
        }
    } catch (Exception e) {
        // Print out problems to system err
        e.printStackTrace(System.err);
    }
}
Also used : Proxy(org.eclipse.ecf.core.util.Proxy) ProxyAddress(org.eclipse.ecf.core.util.ProxyAddress)

Aggregations

ProxyAddress (org.eclipse.ecf.core.util.ProxyAddress)4 HttpHost (org.apache.http.HttpHost)2 Proxy (org.eclipse.ecf.core.util.Proxy)2 URI (java.net.URI)1 IProxyData (org.eclipse.core.net.proxy.IProxyData)1 IProxyService (org.eclipse.core.net.proxy.IProxyService)1