Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2010-02-27 05:37:35 -0500
committerslewis2010-02-27 05:37:35 -0500
commite91a831d06a6c73a51514fb573dd92c1e0b15ed4 (patch)
treeebb295fec9569b411c5b8a7626866b19eaa0d664 /providers/bundles/org.eclipse.ecf.provider.filetransfer
parentb555075a1c518ae0c068ad0d766eef6059b3689a (diff)
downloadorg.eclipse.ecf-e91a831d06a6c73a51514fb573dd92c1e0b15ed4.tar.gz
org.eclipse.ecf-e91a831d06a6c73a51514fb573dd92c1e0b15ed4.tar.xz
org.eclipse.ecf-e91a831d06a6c73a51514fb573dd92c1e0b15ed4.zip
Added support for request headers in options, as well as response headers in IncomingFileTransferException and incoming retrieve start event.
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.filetransfer')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/META-INF/MANIFEST.MF2
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java27
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java94
3 files changed, 102 insertions, 21 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 7e1affd0d..477c9acd1 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
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.eclipse.ecf.provider.filetransfer;singleton:=true
-Bundle-Version: 3.0.1.qualifier
+Bundle-Version: 3.1.0.qualifier
Bundle-Activator: org.eclipse.ecf.internal.provider.filetransfer.Activator
Bundle-Vendor: %plugin.provider
Bundle-Localization: plugin
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java
index 04faef5d9..c4a251e24 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java
@@ -46,6 +46,7 @@ import org.eclipse.ecf.filetransfer.IFileTransferListener;
import org.eclipse.ecf.filetransfer.IFileTransferPausable;
import org.eclipse.ecf.filetransfer.IFileTransferRunnable;
import org.eclipse.ecf.filetransfer.IIncomingFileTransfer;
+import org.eclipse.ecf.filetransfer.IRetrieveFileTransferOptions;
import org.eclipse.ecf.filetransfer.IncomingFileTransferException;
import org.eclipse.ecf.filetransfer.UserCancelledException;
import org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDataEvent;
@@ -115,6 +116,11 @@ public abstract class AbstractRetrieveFileTransfer implements IIncomingFileTrans
protected double downloadRateBytesPerSecond = 0L;
+ /**
+ * @since 3.1
+ */
+ protected Map responseHeaders;
+
public AbstractRetrieveFileTransfer() {
//
}
@@ -198,8 +204,17 @@ public abstract class AbstractRetrieveFileTransfer implements IIncomingFileTrans
int result = READ_TIMEOUT;
Map localOptions = getOptions();
if (localOptions != null) {
- // See if the property is present, if so set
- Object o = localOptions.get("org.eclipse.ecf.provider.filetransfer.retrieve.readTimeout"); //$NON-NLS-1$
+ // See if the connect timeout option is present, if so set
+ Object o = localOptions.get(IRetrieveFileTransferOptions.READ_TIMEOUT);
+ if (o != null) {
+ if (o instanceof Integer) {
+ result = ((Integer) o).intValue();
+ } else if (o instanceof String) {
+ result = new Integer(((String) o)).intValue();
+ }
+ return result;
+ }
+ o = localOptions.get("org.eclipse.ecf.provider.filetransfer.httpclient.retrieve.readTimeout"); //$NON-NLS-1$
if (o != null) {
if (o instanceof Integer) {
result = ((Integer) o).intValue();
@@ -734,6 +749,10 @@ public abstract class AbstractRetrieveFileTransfer implements IIncomingFileTrans
return sb.toString();
}
+ public Map getResponseHeaders() {
+ return responseHeaders;
+ }
+
});
}
@@ -799,6 +818,10 @@ public abstract class AbstractRetrieveFileTransfer implements IIncomingFileTrans
return sb.toString();
}
+ public Map getResponseHeaders() {
+ return responseHeaders;
+ }
+
});
}
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 9da168e87..72e8e1019 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
@@ -18,6 +18,10 @@ import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -30,6 +34,7 @@ import org.eclipse.ecf.core.security.UnsupportedCallbackException;
import org.eclipse.ecf.core.util.Proxy;
import org.eclipse.ecf.filetransfer.IFileRangeSpecification;
import org.eclipse.ecf.filetransfer.IFileTransferPausable;
+import org.eclipse.ecf.filetransfer.IRetrieveFileTransferOptions;
import org.eclipse.ecf.filetransfer.IncomingFileTransferException;
import org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException;
import org.eclipse.ecf.internal.provider.filetransfer.Activator;
@@ -112,6 +117,23 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
// set max-age for cache control to 0 for bug
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=249990
urlConnection.setRequestProperty("Cache-Control", "max-age=0"); //$NON-NLS-1$//$NON-NLS-2$
+ setRequestHeaderValuesFromOptions();
+ }
+
+ private void setRequestHeaderValuesFromOptions() {
+ Map localOptions = getOptions();
+ if (localOptions != null) {
+ Object o = localOptions.get(IRetrieveFileTransferOptions.REQUEST_HEADERS);
+ if (o != null && o instanceof Map) {
+ Map requestHeaders = (Map) o;
+ for (Iterator i = requestHeaders.keySet().iterator(); i.hasNext();) {
+ Object n = i.next();
+ Object v = requestHeaders.get(n);
+ if (n != null && n instanceof String && v != null && v instanceof String)
+ urlConnection.addRequestProperty((String) n, (String) v);
+ }
+ }
+ }
}
protected void setRequestHeaderValues() throws InvalidFileRangeSpecificationException {
@@ -135,6 +157,7 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
// set max-age for cache control to 0 for bug
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=249990
urlConnection.setRequestProperty("Cache-Control", "max-age=0"); //$NON-NLS-1$//$NON-NLS-2$
+ setRequestHeaderValuesFromOptions();
}
private void setRangeHeader(String value) {
@@ -288,19 +311,20 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
setCompressionRequestHeader();
setInputStream(getDecompressedStream());
code = getResponseCode();
+ responseHeaders = getResponseHeaders();
if (isHTTP()) {
if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) {
fireReceiveStartEvent();
} else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
- throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), code); //$NON-NLS-1$
+ throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), code, responseHeaders); //$NON-NLS-1$
} else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
- throw new IncomingFileTransferException("Unauthorized", code); //$NON-NLS-1$
+ throw new IncomingFileTransferException("Unauthorized", code, responseHeaders); //$NON-NLS-1$
} else if (code == HttpURLConnection.HTTP_FORBIDDEN) {
- throw new IncomingFileTransferException("Forbidden", code); //$NON-NLS-1$
+ throw new IncomingFileTransferException("Forbidden", code, responseHeaders); //$NON-NLS-1$
} else if (code == HttpURLConnection.HTTP_PROXY_AUTH) {
- throw new IncomingFileTransferException("Proxy authentication required", code); //$NON-NLS-1$
+ throw new IncomingFileTransferException("Proxy authentication required", code, responseHeaders); //$NON-NLS-1$
} else {
- throw new IncomingFileTransferException(NLS.bind("General connection error with response code={0}", new Integer(code)), code); //$NON-NLS-1$
+ throw new IncomingFileTransferException(NLS.bind("General connection error with response code={0}", new Integer(code)), code, responseHeaders); //$NON-NLS-1$
}
} else {
fireReceiveStartEvent();
@@ -308,12 +332,34 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
} catch (final FileNotFoundException e) {
throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), 404); //$NON-NLS-1$
} catch (final Exception e) {
- IncomingFileTransferException except = (e instanceof IncomingFileTransferException) ? (IncomingFileTransferException) e : new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e, code);
+ IncomingFileTransferException except = (e instanceof IncomingFileTransferException) ? (IncomingFileTransferException) e : new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e, code, responseHeaders);
hardClose();
throw except;
}
}
+ private Map getResponseHeaders() {
+ if (responseHeaders != null)
+ return responseHeaders;
+ if (urlConnection == null)
+ return null;
+ Map headerFields = urlConnection.getHeaderFields();
+ if (headerFields == null)
+ return null;
+ Map result = new HashMap();
+ for (Iterator i = headerFields.keySet().iterator(); i.hasNext();) {
+ String name = (String) i.next();
+ List listValue = (List) headerFields.get(name);
+ String val = null;
+ if (listValue != null && listValue.size() > 0) {
+ val = (String) ((listValue.size() > 1) ? listValue.get(listValue.size() - 1) : listValue.get(0));
+ }
+ if (name != null && val != null)
+ result.put(name, val);
+ }
+ return Collections.unmodifiableMap(result);
+ }
+
/*
* (non-Javadoc)
*
@@ -377,12 +423,23 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
String result = DEFAULT_CONNECT_TIMEOUT;
Map localOptions = getOptions();
if (localOptions != null) {
- // See if the property is present, if so set
- Object o = localOptions.get("org.eclipse.ecf.provider.filetransfer.retrieve.connectTimeout"); //$NON-NLS-1$
- if (o instanceof Integer) {
- result = ((Integer) o).toString();
- } else if (o instanceof String) {
- result = (String) o;
+ // See if the connect timeout option is present, if so set
+ Object o = localOptions.get(IRetrieveFileTransferOptions.CONNECT_TIMEOUT);
+ if (o != null) {
+ if (o instanceof Integer) {
+ result = ((Integer) o).toString();
+ } else if (o instanceof String) {
+ result = (String) o;
+ }
+ return result;
+ }
+ o = localOptions.get("org.eclipse.ecf.provider.filetransfer.httpclient.retrieve.connectTimeout"); //$NON-NLS-1$
+ if (o != null) {
+ if (o instanceof Integer) {
+ result = ((Integer) o).toString();
+ } else if (o instanceof String) {
+ result = (String) o;
+ }
}
}
return result;
@@ -414,24 +471,25 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
// Make actual GET request
setInputStream(urlConnection.getInputStream());
code = getResponseCode();
+ responseHeaders = getResponseHeaders();
if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) {
getResumeResponseHeaderValues();
this.paused = false;
fireReceiveResumedEvent();
return true;
} else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
- throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), code); //$NON-NLS-1$
+ throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), code, responseHeaders); //$NON-NLS-1$
} else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
- throw new IncomingFileTransferException("Unauthorized", code); //$NON-NLS-1$
+ throw new IncomingFileTransferException("Unauthorized", code, responseHeaders); //$NON-NLS-1$
} else if (code == HttpURLConnection.HTTP_FORBIDDEN) {
- throw new IncomingFileTransferException("Forbidden", code); //$NON-NLS-1$
+ throw new IncomingFileTransferException("Forbidden", code, responseHeaders); //$NON-NLS-1$
} else if (code == HttpURLConnection.HTTP_PROXY_AUTH) {
- throw new IncomingFileTransferException("Proxy authentication required", code); //$NON-NLS-1$
+ throw new IncomingFileTransferException("Proxy authentication required", code, responseHeaders); //$NON-NLS-1$
} else {
- throw new IncomingFileTransferException(NLS.bind("General connection error with response code={0}", new Integer(code)), code); //$NON-NLS-1$
+ throw new IncomingFileTransferException(NLS.bind("General connection error with response code={0}", new Integer(code)), code, responseHeaders); //$NON-NLS-1$
}
} catch (final Exception e) {
- this.exception = (e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e, code);
+ this.exception = (e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e, code, responseHeaders);
this.done = true;
hardClose();
fireTransferReceiveDoneEvent();

Back to the top