Lines 12-23
Link Here
|
12 |
|
12 |
|
13 |
package org.eclipse.ecf.provider.filetransfer.browse; |
13 |
package org.eclipse.ecf.provider.filetransfer.browse; |
14 |
|
14 |
|
15 |
import java.net.URI; |
|
|
16 |
import java.net.URL; |
15 |
import java.net.URL; |
17 |
import java.util.Arrays; |
16 |
import java.util.Arrays; |
18 |
import java.util.List; |
17 |
import java.util.List; |
19 |
import org.eclipse.core.net.proxy.IProxyData; |
|
|
20 |
import org.eclipse.core.net.proxy.IProxyService; |
21 |
import org.eclipse.core.runtime.Assert; |
18 |
import org.eclipse.core.runtime.Assert; |
22 |
import org.eclipse.core.runtime.IProgressMonitor; |
19 |
import org.eclipse.core.runtime.IProgressMonitor; |
23 |
import org.eclipse.core.runtime.IStatus; |
20 |
import org.eclipse.core.runtime.IStatus; |
Lines 25-31
Link Here
|
25 |
import org.eclipse.core.runtime.jobs.Job; |
22 |
import org.eclipse.core.runtime.jobs.Job; |
26 |
import org.eclipse.ecf.core.security.IConnectContext; |
23 |
import org.eclipse.ecf.core.security.IConnectContext; |
27 |
import org.eclipse.ecf.core.util.Proxy; |
24 |
import org.eclipse.ecf.core.util.Proxy; |
28 |
import org.eclipse.ecf.core.util.ProxyAddress; |
|
|
29 |
import org.eclipse.ecf.filetransfer.IRemoteFile; |
25 |
import org.eclipse.ecf.filetransfer.IRemoteFile; |
30 |
import org.eclipse.ecf.filetransfer.IRemoteFileSystemListener; |
26 |
import org.eclipse.ecf.filetransfer.IRemoteFileSystemListener; |
31 |
import org.eclipse.ecf.filetransfer.IRemoteFileSystemRequest; |
27 |
import org.eclipse.ecf.filetransfer.IRemoteFileSystemRequest; |
Lines 33-40
Link Here
|
33 |
import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemBrowseEvent; |
29 |
import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemBrowseEvent; |
34 |
import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemEvent; |
30 |
import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemEvent; |
35 |
import org.eclipse.ecf.filetransfer.identity.IFileID; |
31 |
import org.eclipse.ecf.filetransfer.identity.IFileID; |
36 |
import org.eclipse.ecf.internal.provider.filetransfer.Activator; |
|
|
37 |
import org.eclipse.ecf.internal.provider.filetransfer.Messages; |
32 |
import org.eclipse.ecf.internal.provider.filetransfer.Messages; |
|
|
33 |
import org.eclipse.ecf.provider.filetransfer.ProxySetupHelper; |
38 |
|
34 |
|
39 |
/** |
35 |
/** |
40 |
* Abstract class for browsing an efs file system. |
36 |
* Abstract class for browsing an efs file system. |
Lines 197-260
Link Here
|
197 |
|
193 |
|
198 |
protected abstract void setupProxy(Proxy proxy); |
194 |
protected abstract void setupProxy(Proxy proxy); |
199 |
|
195 |
|
200 |
/** |
|
|
201 |
* Select a single proxy from a set of proxies available for the given host. This implementation |
202 |
* selects in the following manner: 1) If proxies provided is null or array of 0 length, null |
203 |
* is returned. If only one proxy is available (array of length 1) then the entry is returned. |
204 |
* If proxies provided is length > 1, then if the type of a proxy in the array matches the given |
205 |
* protocol (e.g. http, https), then the first matching proxy is returned. If the protocol does |
206 |
* not match any of the proxies, then the *first* proxy (i.e. proxies[0]) is returned. Subclasses may |
207 |
* override if desired. |
208 |
* |
209 |
* @param protocol the target protocol (e.g. http, https, scp, etc). Will not be <code>null</code>. |
210 |
* @param proxies the proxies to select from. May be <code>null</code> or array of length 0. |
211 |
* @return proxy data selected from the proxies provided. |
212 |
*/ |
213 |
protected IProxyData selectProxyFromProxies(String protocol, IProxyData[] proxies) { |
214 |
if (proxies == null || proxies.length == 0) |
215 |
return null; |
216 |
// If only one proxy is available, then use that |
217 |
if (proxies.length == 1) |
218 |
return proxies[0]; |
219 |
// If more than one proxy is available, then if http/https protocol then look for that |
220 |
// one...if not found then use first |
221 |
if (protocol.equalsIgnoreCase("http")) { //$NON-NLS-1$ |
222 |
for (int i = 0; i < proxies.length; i++) { |
223 |
if (proxies[i].getType().equals(IProxyData.HTTP_PROXY_TYPE)) |
224 |
return proxies[i]; |
225 |
} |
226 |
} else if (protocol.equalsIgnoreCase("https")) { //$NON-NLS-1$ |
227 |
for (int i = 0; i < proxies.length; i++) { |
228 |
if (proxies[i].getType().equals(IProxyData.HTTPS_PROXY_TYPE)) |
229 |
return proxies[i]; |
230 |
} |
231 |
} |
232 |
// If we haven't found it yet, then return the first one. |
233 |
return proxies[0]; |
234 |
} |
235 |
|
236 |
protected void setupProxies() { |
196 |
protected void setupProxies() { |
237 |
// If it's been set directly (via ECF API) then this overrides platform settings |
197 |
// If it's been set directly (via ECF API) then this overrides platform settings |
238 |
if (proxy == null) { |
198 |
if (proxy == null) { |
239 |
try { |
199 |
proxy = ProxySetupHelper.getProxy(directoryOrFile.toExternalForm()); |
240 |
IProxyService proxyService = Activator.getDefault().getProxyService(); |
|
|
241 |
// Only do this if platform service exists |
242 |
if (proxyService != null && proxyService.isProxiesEnabled()) { |
243 |
// Setup via proxyService entry |
244 |
URI target = new URI(directoryOrFile.toExternalForm()); |
245 |
final IProxyData[] proxies = proxyService.select(target); |
246 |
IProxyData selectedProxy = selectProxyFromProxies(target.getScheme(), proxies); |
247 |
if (selectedProxy != null) { |
248 |
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()); |
249 |
} |
250 |
} |
251 |
} catch (Exception e) { |
252 |
// If we don't even have the classes for this (i.e. the org.eclipse.core.net plugin not available) |
253 |
// then we simply log and ignore |
254 |
Activator.logNoProxyWarning(e); |
255 |
} catch (NoClassDefFoundError e) { |
256 |
Activator.logNoProxyWarning(e); |
257 |
} |
258 |
} |
200 |
} |
259 |
if (proxy != null) |
201 |
if (proxy != null) |
260 |
setupProxy(proxy); |
202 |
setupProxy(proxy); |