Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-05-05 01:28:25 -0400
committerslewis2009-05-05 01:28:25 -0400
commit09859595c7ad26b2a6dadb8db88deb92a9bc8964 (patch)
tree81acf9722400077a3e2523928dbf42ddedb421c8 /providers/bundles/org.eclipse.ecf.provider.filetransfer
parent8021db14ce3252147852783b604b4cd262bd7107 (diff)
downloadorg.eclipse.ecf-09859595c7ad26b2a6dadb8db88deb92a9bc8964.tar.gz
org.eclipse.ecf-09859595c7ad26b2a6dadb8db88deb92a9bc8964.tar.xz
org.eclipse.ecf-09859595c7ad26b2a6dadb8db88deb92a9bc8964.zip
https://bugs.eclipse.org/bugs/show_bug.cgi?id=274821Modifications for bug
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.java71
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/UrlConnectionRetrieveFileTransfer.java58
2 files changed, 89 insertions, 40 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 9d468972b..52ae5acd5 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
@@ -24,6 +24,7 @@ import org.eclipse.ecf.core.security.NameCallback;
import org.eclipse.ecf.core.security.ObjectCallback;
import org.eclipse.ecf.core.security.UnsupportedCallbackException;
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.identity.IFileID;
@@ -31,6 +32,7 @@ import org.eclipse.ecf.internal.provider.filetransfer.Activator;
import org.eclipse.ecf.internal.provider.filetransfer.IURLConnectionModifier;
import org.eclipse.ecf.internal.provider.filetransfer.Messages;
import org.eclipse.ecf.provider.filetransfer.util.JREProxyHelper;
+import org.eclipse.osgi.util.NLS;
/**
*
@@ -77,29 +79,56 @@ public class URLFileSystemBrowser extends AbstractFileSystemBrowser {
* @see org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser#runRequest()
*/
protected void runRequest() throws Exception {
- setupProxies();
- setupAuthentication();
- setupTimeouts();
- 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);
+ int code = -1;
+ try {
+ setupProxies();
+ setupAuthentication();
+ setupTimeouts();
+ 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);
+ }
+ // Add http 1.1 'Connection: close' header in order to potentially avoid
+ // server issue described here https://bugs.eclipse.org/bugs/show_bug.cgi?id=234916#c13
+ // See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247197
+ // also see http 1.1 rfc section 14-10 in http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
+ urlConnection.setRequestProperty("Connection", "close"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ IURLConnectionModifier connectionModifier = Activator.getDefault().getURLConnectionModifier();
+ if (connectionModifier != null) {
+ connectionModifier.setSocketFactoryForConnection(urlConnection);
+ }
+ InputStream ins = urlConnection.getInputStream();
+ code = getResponseCode(urlConnection);
+ ins.close();
+ remoteFiles = new IRemoteFile[1];
+ remoteFiles[0] = new URLRemoteFile(urlConnection.getLastModified(), urlConnection.getContentLength(), fileID);
+ } catch (Exception e) {
+ throw new BrowseFileTransferException(NLS.bind("Could not connect to {0}", directoryOrFile), e, code); //$NON-NLS-1$
}
- // Add http 1.1 'Connection: close' header in order to potentially avoid
- // server issue described here https://bugs.eclipse.org/bugs/show_bug.cgi?id=234916#c13
- // See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247197
- // also see http 1.1 rfc section 14-10 in http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
- urlConnection.setRequestProperty("Connection", "close"); //$NON-NLS-1$ //$NON-NLS-2$
-
- IURLConnectionModifier connectionModifier = Activator.getDefault().getURLConnectionModifier();
- if (connectionModifier != null) {
- connectionModifier.setSocketFactoryForConnection(urlConnection);
+ }
+
+ private int getResponseCode(URLConnection urlConnection) {
+ int responseCode = -1;
+ String response = urlConnection.getHeaderField(0);
+ if (response == null) {
+ responseCode = -1;
+ return responseCode;
}
- InputStream ins = urlConnection.getInputStream();
- ins.close();
- remoteFiles = new IRemoteFile[1];
- remoteFiles[0] = new URLRemoteFile(urlConnection.getLastModified(), urlConnection.getContentLength(), fileID);
+ if (!response.startsWith("HTTP/")) //$NON-NLS-1$
+ return -1;
+ response = response.trim();
+ final int mark = response.indexOf(" ") + 1; //$NON-NLS-1$
+ if (mark == 0)
+ return -1;
+ int last = mark + 3;
+ if (last > response.length())
+ last = response.length();
+ responseCode = Integer.parseInt(response.substring(mark, last));
+ return responseCode;
+
}
protected void setupAuthentication() throws IOException, UnsupportedCallbackException {
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 b2029eb8d..9e26bcb24 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
@@ -9,10 +9,12 @@
******************************************************************************/
package org.eclipse.ecf.provider.filetransfer.retrieve;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.Authenticator;
import java.net.ConnectException;
+import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
@@ -275,6 +277,7 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
* #openStreams()
*/
protected void openStreams() throws IncomingFileTransferException {
+ int code = -1;
try {
setupAuthentication();
connect();
@@ -283,10 +286,23 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
// need to get response header about encoding before setting stream
setCompressionRequestHeader();
setInputStream(getDecompressedStream());
- getResponseHeaderValues();
- fireReceiveStartEvent();
+ code = getResponseCode();
+ if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) {
+ getResponseHeaderValues();
+ fireReceiveStartEvent();
+ } else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
+ throw new FileNotFoundException(getRemoteFileName());
+ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
+ throw new IncomingFileTransferException("Unauthorized", code); //$NON-NLS-1$
+ } else if (code == HttpURLConnection.HTTP_FORBIDDEN) {
+ throw new IncomingFileTransferException("Forbidden", code); //$NON-NLS-1$
+ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) {
+ throw new IncomingFileTransferException("Proxy authentication required", code); //$NON-NLS-1$
+ } else {
+ throw new IOException(NLS.bind("General connection error with response code={0}", new Integer(code))); //$NON-NLS-1$
+ }
} catch (final Exception e) {
- IncomingFileTransferException except = 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, code);
hardClose();
throw except;
}
@@ -368,6 +384,7 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
*/
private boolean openStreamsForResume() {
final URL theURL = getRemoteFileURL();
+ int code = -1;
try {
remoteFileURL = new URL(theURL.toString());
setupAuthentication();
@@ -375,12 +392,25 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
setResumeRequestHeaderValues();
// Make actual GET request
setInputStream(urlConnection.getInputStream());
- getResumeResponseHeaderValues();
- this.paused = false;
- fireReceiveResumedEvent();
- return true;
+ code = getResponseCode();
+ 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 FileNotFoundException(getRemoteFileName());
+ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
+ throw new IncomingFileTransferException("Unauthorized", code); //$NON-NLS-1$
+ } else if (code == HttpURLConnection.HTTP_FORBIDDEN) {
+ throw new IncomingFileTransferException("Forbidden", code); //$NON-NLS-1$
+ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) {
+ throw new IncomingFileTransferException("Proxy authentication required", code); //$NON-NLS-1$
+ } else {
+ throw new IOException(NLS.bind("General connection error with response code={0}", new Integer(code))); //$NON-NLS-1$
+ }
} catch (final Exception e) {
- this.exception = e;
+ this.exception = new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e, code);
this.done = true;
hardClose();
fireTransferReceiveDoneEvent();
@@ -388,19 +418,11 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
}
}
- // private static final String APPLICATION_X_GZIP = "application/x-gzip"; //$NON-NLS-1$
- // private static final String CONTENT_TYPE = "Content-Type"; //$NON-NLS-1$
- // private static final String CONTENT_ENCODING = "Content-Encoding"; //$NON-NLS-1$
private static final String ACCEPT_ENCODING = "Accept-encoding"; //$NON-NLS-1$
private static final String CONTENT_ENCODING_GZIP = "gzip"; //$NON-NLS-1$
- // private static final String CONTENT_ENCODING_DEFLATE = "deflate"; //$NON-NLS-1$
private static final String CONTENT_ENCODING_ACCEPTED = CONTENT_ENCODING_GZIP; // +
- // ","
- // +
- // CONTENT_ENCODING_DEFLATE;
-
private static class Compression {
private String type;
@@ -413,8 +435,6 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
static Compression GZIP = new Compression("gzip"); //$NON-NLS-1$
- // static Compression DEFLATE = new Compression("deflate"); //$NON-NLS-1$
-
public String toString() {
return type;
}
@@ -427,7 +447,6 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
private Compression getCompressionResponseHeader() {
String encoding = urlConnection.getContentEncoding();
-
if (null == encoding) {
return Compression.NONE;
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=269018
@@ -439,6 +458,7 @@ public class UrlConnectionRetrieveFileTransfer extends AbstractRetrieveFileTrans
private InputStream getDecompressedStream() throws IOException {
InputStream input = urlConnection.getInputStream();
+ getResponseHeaderValues();
Compression type = getCompressionResponseHeader();
if (Compression.GZIP == type) {

Back to the top