Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-08-25 16:54:44 -0400
committerslewis2009-08-25 16:54:44 -0400
commita1e44bda1282a62cd401b6db5bedfde2e761ad53 (patch)
tree9822d6aa9a86264cec397455fdd50e9e3149af10 /providers/bundles/org.eclipse.ecf.provider.filetransfer
parent0e2a8b82a252a61247c0adf3d95539cc48cf7c1d (diff)
downloadorg.eclipse.ecf-a1e44bda1282a62cd401b6db5bedfde2e761ad53.tar.gz
org.eclipse.ecf-a1e44bda1282a62cd401b6db5bedfde2e761ad53.tar.xz
org.eclipse.ecf-a1e44bda1282a62cd401b6db5bedfde2e761ad53.zip
Corrected file not found behavior to be same as httpclient. Also changed URLFileSystemBrowser to use HEAD method rather than GET to improve efficiency.
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.filetransfer')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/URLFileSystemBrowser.java17
1 files changed, 14 insertions, 3 deletions
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
index 06e9802bc..b0b55a9e4 100644
--- 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
@@ -11,6 +11,7 @@
package org.eclipse.ecf.provider.filetransfer.browse;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.Authenticator;
@@ -18,6 +19,7 @@ import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
+import javax.microedition.io.HttpConnection;
import org.eclipse.ecf.core.security.Callback;
import org.eclipse.ecf.core.security.CallbackHandler;
import org.eclipse.ecf.core.security.IConnectContext;
@@ -28,6 +30,7 @@ import org.eclipse.ecf.core.util.Proxy;
import org.eclipse.ecf.filetransfer.BrowseFileTransferException;
import org.eclipse.ecf.filetransfer.IRemoteFile;
import org.eclipse.ecf.filetransfer.IRemoteFileSystemListener;
+import org.eclipse.ecf.filetransfer.IncomingFileTransferException;
import org.eclipse.ecf.filetransfer.identity.IFileID;
import org.eclipse.ecf.internal.provider.filetransfer.Activator;
import org.eclipse.ecf.internal.provider.filetransfer.IURLConnectionModifier;
@@ -85,7 +88,7 @@ public class URLFileSystemBrowser extends AbstractFileSystemBrowser {
setupProxies();
setupAuthentication();
setupTimeouts();
- URLConnection urlConnection = directoryOrFile.openConnection();
+ URLConnection 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$
@@ -101,9 +104,15 @@ public class URLFileSystemBrowser extends AbstractFileSystemBrowser {
if (connectionModifier != null) {
connectionModifier.setSocketFactoryForConnection(urlConnection);
}
- InputStream ins = urlConnection.getInputStream();
+ if (urlConnection instanceof HttpURLConnection) {
+ HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
+ httpConnection.setRequestMethod("HEAD"); //$NON-NLS-1$
+ httpConnection.connect();
+ } else {
+ InputStream ins = urlConnection.getInputStream();
+ ins.close();
+ }
code = getResponseCode(urlConnection);
- ins.close();
if (isHTTP()) {
if (code == HttpURLConnection.HTTP_OK) {
// do nothing
@@ -121,6 +130,8 @@ public class URLFileSystemBrowser extends AbstractFileSystemBrowser {
}
remoteFiles = new IRemoteFile[1];
remoteFiles[0] = new URLRemoteFile(urlConnection.getLastModified(), urlConnection.getContentLength(), fileID);
+ } catch (final FileNotFoundException e) {
+ throw new IncomingFileTransferException(NLS.bind("File not found: {0}", directoryOrFile.toString()), HttpConnection.HTTP_NOT_FOUND); //$NON-NLS-1$
} catch (Exception e) {
Exception except = (e instanceof BrowseFileTransferException) ? e : new BrowseFileTransferException(NLS.bind("Could not connect to {0}", directoryOrFile), e, code); //$NON-NLS-1$
throw except;

Back to the top