Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-03-04 01:26:26 +0000
committerslewis2008-03-04 01:26:26 +0000
commit0850308fe3ddad0a4fa4f68fe04d81aa74787632 (patch)
tree173f7bab0ac42e67df5301ddfbde792c6b2da54a /providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient
parent3bc09f96fa1197be2ac6f87052be6ddb64418515 (diff)
downloadorg.eclipse.ecf-0850308fe3ddad0a4fa4f68fe04d81aa74787632.tar.gz
org.eclipse.ecf-0850308fe3ddad0a4fa4f68fe04d81aa74787632.tar.xz
org.eclipse.ecf-0850308fe3ddad0a4fa4f68fe04d81aa74787632.zip
API addition and provider implementation changes for bug 221177. Also added GetRemoteFileNameTest.
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientRetrieveFileTransfer.java33
1 files changed, 32 insertions, 1 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientRetrieveFileTransfer.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientRetrieveFileTransfer.java
index 7a044fd64..307ab787f 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientRetrieveFileTransfer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient/src/org/eclipse/ecf/provider/filetransfer/httpclient/HttpClientRetrieveFileTransfer.java
@@ -17,7 +17,7 @@ import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.util.DateUtil;
-import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.*;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.security.*;
import org.eclipse.ecf.core.util.Proxy;
@@ -27,6 +27,7 @@ import org.eclipse.ecf.filetransfer.identity.IFileID;
import org.eclipse.ecf.internal.provider.filetransfer.httpclient.Messages;
import org.eclipse.ecf.provider.filetransfer.identity.FileTransferID;
import org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer;
+import org.eclipse.ecf.provider.filetransfer.retrieve.HttpHelper;
import org.eclipse.ecf.provider.filetransfer.util.JREProxyHelper;
import org.eclipse.osgi.util.NLS;
@@ -62,6 +63,8 @@ public class HttpClientRetrieveFileTransfer extends AbstractRetrieveFileTransfer
private int responseCode = -1;
+ private String remoteFileName;
+
protected int httpVersion = 1;
protected IFileID fileid = null;
@@ -76,6 +79,13 @@ public class HttpClientRetrieveFileTransfer extends AbstractRetrieveFileTransfer
proxyHelper = new JREProxyHelper();
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer#getRemoteFileName()
+ */
+ public String getRemoteFileName() {
+ return remoteFileName;
+ }
+
/*
* (non-Javadoc)
*
@@ -199,6 +209,27 @@ public class HttpClientRetrieveFileTransfer extends AbstractRetrieveFileTransfer
}
setFileLength(getMethod.getResponseContentLength());
fileid = new FileTransferID(getRetrieveNamespace(), getRemoteFileURL());
+
+ // Get content disposition header and get remote file name from it if possible.
+ Header contentDispositionHeader = getMethod.getResponseHeader(HttpHelper.CONTENT_DISPOSITION_HEADER);
+ if (contentDispositionHeader != null) {
+ remoteFileName = HttpHelper.getRemoteFileNameFromContentDispositionHeader(contentDispositionHeader.getValue());
+ }
+ // If still null, get the path from httpclient.getMethod()
+ if (remoteFileName == null) {
+ // No name could be extracted using Content-Disposition. Let's try the
+ // path from the getMethod.
+ String pathStr = getMethod.getPath();
+ if (pathStr != null && pathStr.length() > 0) {
+ IPath path = Path.fromPortableString(pathStr);
+ if (path.segmentCount() > 0)
+ remoteFileName = path.lastSegment();
+ }
+ // If still null, use the input file name
+ if (remoteFileName == null)
+ // Last resort. Use the path of the initial URL request
+ remoteFileName = super.getRemoteFileName();
+ }
}
/* (non-Javadoc)

Back to the top