diff options
author | slewis | 2008-08-20 20:09:23 +0000 |
---|---|---|
committer | slewis | 2008-08-20 20:09:23 +0000 |
commit | 667b23675a882b01aa998b379ed983169d62df8d (patch) | |
tree | 25f3bc3da605abbbefc97c6052c765524c3e9846 | |
parent | 042dad543633b4020b461e448768e50adcc09228 (diff) | |
download | org.eclipse.ecf-667b23675a882b01aa998b379ed983169d62df8d.tar.gz org.eclipse.ecf-667b23675a882b01aa998b379ed983169d62df8d.tar.xz org.eclipse.ecf-667b23675a882b01aa998b379ed983169d62df8d.zip |
Fixes for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=235933
3 files changed, 209 insertions, 14 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF index ea56261a3..1e1765cd0 100644 --- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF +++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF @@ -1,15 +1,30 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: ECF Filetransfer Provider +Bundle-Name: %plugin.name Bundle-SymbolicName: org.eclipse.ecf.provider.filetransfer;singleton:=true -Bundle-Version: 0.9.3 -Bundle-Activator: org.eclipse.ecf.provider.internal.filetransfer.Activator -Bundle-Vendor: Eclipse.org -Require-Bundle: org.eclipse.core.runtime, +Bundle-Version: 2.0.1.qualifier +Bundle-Activator: org.eclipse.ecf.internal.provider.filetransfer.Activator +Bundle-Vendor: %plugin.provider +Bundle-Localization: plugin +Require-Bundle: org.eclipse.equinox.common, org.eclipse.ecf, org.eclipse.ecf.filetransfer, - org.eclipse.ecf.sharedobject, - org.eclipse.ecf.provider + org.eclipse.equinox.registry Eclipse-LazyStart: true -Bundle-RequiredExecutionEnvironment: J2SE-1.4, - CDC-1.1/Foundation-1.1 +Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0, + J2SE-1.3 +Import-Package: org.eclipse.core.net.proxy;resolution:=optional, + org.eclipse.core.runtime.jobs, + org.eclipse.osgi.util;version="1.0.0", + org.osgi.framework;version="1.3.0", + org.osgi.service.log;version="1.3.0", + org.osgi.service.url;version="1.0.0", + org.osgi.util.tracker;version="1.3.2" +Bundle-ClassPath: . +Export-Package: org.eclipse.ecf.internal.provider.filetransfer;x-internal:=true, + org.eclipse.ecf.provider.filetransfer.browse, + org.eclipse.ecf.provider.filetransfer.identity;x-internal:=false, + org.eclipse.ecf.provider.filetransfer.outgoing, + org.eclipse.ecf.provider.filetransfer.retrieve;x-internal:=false, + org.eclipse.ecf.provider.filetransfer.util +Bundle-ActivationPolicy: lazy diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/URLFileSystemBrowser.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/URLFileSystemBrowser.java new file mode 100644 index 000000000..49d5a376e --- /dev/null +++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/URLFileSystemBrowser.java @@ -0,0 +1,177 @@ +/**************************************************************************** + * Copyright (c) 2008 Composent, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Composent, Inc. - initial API and implementation + *****************************************************************************/ + +package org.eclipse.ecf.provider.filetransfer.browse; + +import java.io.IOException; +import java.io.InputStream; +import java.net.*; +import org.eclipse.core.net.proxy.IProxyData; +import org.eclipse.core.net.proxy.IProxyService; +import org.eclipse.ecf.core.security.*; +import org.eclipse.ecf.core.util.Proxy; +import org.eclipse.ecf.core.util.ProxyAddress; +import org.eclipse.ecf.filetransfer.IRemoteFile; +import org.eclipse.ecf.filetransfer.IRemoteFileSystemListener; +import org.eclipse.ecf.filetransfer.identity.IFileID; +import org.eclipse.ecf.internal.provider.filetransfer.*; +import org.eclipse.ecf.provider.filetransfer.util.JREProxyHelper; + +/** + * + */ +public class URLFileSystemBrowser extends AbstractFileSystemBrowser { + + private static final String USERNAME_PREFIX = Messages.UrlConnectionRetrieveFileTransfer_USERNAME_PROMPT; + + URL directoryOrFile; + + IConnectContext connectContext; + Proxy proxy; + + private JREProxyHelper proxyHelper = null; + + protected String username = null; + + protected String password = null; + + /** + * @param directoryOrFileID + * @param listener + */ + public URLFileSystemBrowser(IFileID directoryOrFileID, IRemoteFileSystemListener listener, URL directoryOrFileURL, IConnectContext connectContext, Proxy proxy) { + super(directoryOrFileID, listener); + this.directoryOrFile = directoryOrFileURL; + this.connectContext = connectContext; + this.proxy = proxy; + proxyHelper = new JREProxyHelper(); + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser#runRequest() + */ + protected void runRequest() throws Exception { + setupProxies(); + setupAuthentication(); + URLConnection urlConnection = directoryOrFile.openConnection(); + // set cache to off if using jar protocol + // this is for addressing bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=235933 + if (directoryOrFile.getProtocol().equalsIgnoreCase("jar")) { //$NON-NLS-1$ + urlConnection.setUseCaches(false); + } + IURLConnectionModifier connectionModifier = Activator.getDefault().getURLConnectionModifier(); + if (connectionModifier != null) { + connectionModifier.setSocketFactoryForConnection(urlConnection); + } + InputStream ins = urlConnection.getInputStream(); + ins.close(); + remoteFiles = new IRemoteFile[1]; + remoteFiles[0] = new URLRemoteFile(urlConnection, fileID); + } + + protected void setupAuthentication() throws IOException, UnsupportedCallbackException { + if (connectContext == null) + return; + final CallbackHandler callbackHandler = connectContext.getCallbackHandler(); + if (callbackHandler == null) + return; + final NameCallback usernameCallback = new NameCallback(USERNAME_PREFIX); + final ObjectCallback passwordCallback = new ObjectCallback(); + // Call callback with username and password callbacks + callbackHandler.handle(new Callback[] {usernameCallback, passwordCallback}); + username = usernameCallback.getName(); + Object o = passwordCallback.getObject(); + if (!(o instanceof String)) + throw new UnsupportedCallbackException(passwordCallback, Messages.UrlConnectionRetrieveFileTransfer_UnsupportedCallbackException); + password = (String) passwordCallback.getObject(); + // Now set authenticator to our authenticator with user and password + Authenticator.setDefault(new UrlConnectionAuthenticator()); + } + + class UrlConnectionAuthenticator extends Authenticator { + /* (non-Javadoc) + * @see java.net.Authenticator#getPasswordAuthentication() + */ + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password.toCharArray()); + } + } + + protected void setupProxy(final Proxy proxy2) { + proxyHelper.setupProxy(proxy2); + } + + /** + * Select a single proxy from a set of proxies available for the given host. This implementation + * selects in the following manner: 1) If proxies provided is null or array of 0 length, null + * is returned. If only one proxy is available (array of length 1) then the entry is returned. + * If proxies provided is length > 1, then if the type of a proxy in the array matches the given + * protocol (e.g. http, https), then the first matching proxy is returned. If the protocol does + * not match any of the proxies, then the *first* proxy (i.e. proxies[0]) is returned. Subclasses may + * override if desired. + * + * @param protocol the target protocol (e.g. http, https, scp, etc). Will not be <code>null</code>. + * @param proxies the proxies to select from. May be <code>null</code> or array of length 0. + * @return proxy data selected from the proxies provided. + */ + protected IProxyData selectProxyFromProxies(String protocol, IProxyData[] proxies) { + if (proxies == null || proxies.length == 0) + return null; + // If only one proxy is available, then use that + if (proxies.length == 1) + return proxies[0]; + // If more than one proxy is available, then if http/https protocol then look for that + // one...if not found then use first + if (protocol.equalsIgnoreCase("http")) { //$NON-NLS-1$ + for (int i = 0; i < proxies.length; i++) { + if (proxies[i].getType().equals(IProxyData.HTTP_PROXY_TYPE)) + return proxies[i]; + } + } else if (protocol.equalsIgnoreCase("https")) { //$NON-NLS-1$ + for (int i = 0; i < proxies.length; i++) { + if (proxies[i].getType().equals(IProxyData.HTTPS_PROXY_TYPE)) + return proxies[i]; + } + } + // If we haven't found it yet, then return the first one. + return proxies[0]; + } + + protected void setupProxies() { + // If it's been set directly (via ECF API) then this overrides platform settings + if (proxy == null) { + try { + IProxyService proxyService = Activator.getDefault().getProxyService(); + // Only do this if platform service exists + if (proxyService != null) { + // Setup via proxyService entry + URL target = directoryOrFile; + final IProxyData[] proxies = proxyService.getProxyDataForHost(target.getHost()); + IProxyData selectedProxy = selectProxyFromProxies(target.getProtocol(), 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); + } + } + if (proxy != null) + setupProxy(proxy); + + } + +} diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java index 20d2b0369..0d2ce7497 100644 --- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java +++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java @@ -66,14 +66,15 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans protected void connect() throws IOException { setupTimeouts(); urlConnection = getRemoteFileURL().openConnection(); + // set cache to off if using jar protocol + // this is for addressing bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=235933 + if (getRemoteFileURL().getProtocol().equalsIgnoreCase("jar")) { //$NON-NLS-1$ + urlConnection.setUseCaches(false); + } IURLConnectionModifier connectionModifier = Activator.getDefault().getURLConnectionModifier(); if (connectionModifier != null) { connectionModifier.setSocketFactoryForConnection(urlConnection); } - // set cache to off if using jar protocol - if (getRemoteFileURL().getProtocol().equals("jar")) { //$NON-NLS-1$ - urlConnection.setUseCaches(false); - } } protected boolean isConnected() { @@ -242,7 +243,9 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans getResponseHeaderValues(); fireReceiveStartEvent(); } catch (final Exception e) { - throw new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e); + IncomingFileTransferException except = new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e, getResponseCode()); + hardClose(); + throw except; } } |