From 21d1265ca5319dbe944aaff874e872f33cd8c313 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 6 Feb 2017 11:54:02 +0100 Subject: [PATCH 1/3] Show error message when there is an external storage error --- .../operations/RemoteOperationResult.java | 24 +++++++++++++++++-- .../files/ReadRemoteFolderOperation.java | 1 - 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 6c3cefd3..8256b031 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -118,7 +118,8 @@ public class RemoteOperationResult implements Serializable { INVALID_CHARACTER_DETECT_IN_SERVER, DELAYED_FOR_WIFI, LOCAL_FILE_NOT_FOUND, - MAINTENANCE_MODE + MAINTENANCE_MODE, + SPECIFIC_SERVICE_UNAVAILABLE } private boolean mSuccess = false; @@ -254,7 +255,7 @@ public class RemoteOperationResult implements Serializable { ErrorMessageParser xmlParser = new ErrorMessageParser(); try { String errorMessage = xmlParser.parseXMLResponse(is); - if (errorMessage != null && errorMessage != "") { + if (errorMessage != "" && errorMessage != null) { mCode = ResultCode.SPECIFIC_FORBIDDEN; mHttpPhrase = errorMessage; } @@ -264,6 +265,25 @@ public class RemoteOperationResult implements Serializable { } } } + + if (mHttpCode == HttpStatus.SC_SERVICE_UNAVAILABLE) { + String bodyResponse = httpMethod.getResponseBodyAsString(); + + if (bodyResponse != null && bodyResponse.length() > 0) { + InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); + ErrorMessageParser xmlParser = new ErrorMessageParser(); + try { + String errorMessage = xmlParser.parseXMLResponse(is); + if (errorMessage != "" && errorMessage != null) { + mCode = ResultCode.SPECIFIC_SERVICE_UNAVAILABLE; + mHttpPhrase = errorMessage; + } + } catch (Exception e) { + Log_OC.w(TAG, "Error reading exception from server: " + e.getMessage()); + // mCode stays as set in this(success, httpCode, headers) + } + } + } } /** diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java index 42ea3529..2b260e2f 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java @@ -96,7 +96,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation { } } else { // synchronization failed - client.exhaustResponse(query.getResponseBodyAsStream()); result = new RemoteOperationResult(false, query); } From 06f907294a85ec8c11619da2e68752027b36bc48 Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 10 Feb 2017 12:17:57 +0100 Subject: [PATCH 2/3] Change HEAD method to PROPFIND method while checking path existence before starting an upload --- .../files/DownloadRemoteFileOperation.java | 3 +- .../files/ExistenceCheckRemoteOperation.java | 36 ++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java index 0a013bee..73929687 100644 --- a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java @@ -58,6 +58,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { private static final String TAG = DownloadRemoteFileOperation.class.getSimpleName(); private static final int FORBIDDEN_ERROR = 403; + private static final int SERVICE_UNAVAILABLE_ERROR = 503; private Set mDataTransferListeners = new HashSet(); private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); @@ -162,7 +163,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { // TODO some kind of error control! } - } else if (status != FORBIDDEN_ERROR){ + } else if (status != FORBIDDEN_ERROR && status != SERVICE_UNAVAILABLE_ERROR){ client.exhaustResponse(mGet.getResponseBodyAsStream()); } // else, body read by RemoteOeprationResult constructor diff --git a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java index 38387b36..e5036104 100644 --- a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java @@ -25,7 +25,8 @@ package com.owncloud.android.lib.resources.files; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.HeadMethod; +import org.apache.jackrabbit.webdav.DavConstants; +import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; import android.content.Context; @@ -47,6 +48,9 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { public static final int TIMEOUT = 10000; private static final String TAG = ExistenceCheckRemoteOperation.class.getSimpleName(); + + private static final int FORBIDDEN_ERROR = 403; + private static final int SERVICE_UNAVAILABLE_ERROR = 503; private String mPath; private boolean mSuccessIfAbsent; @@ -83,24 +87,32 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; - HeadMethod head = null; + PropFindMethod propfind = null; boolean previousFollowRedirects = client.getFollowRedirects(); try { - head = new HeadMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath)); + propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath), + WebdavUtils.getAllPropSet(), DavConstants.DEPTH_0); client.setFollowRedirects(false); - int status = client.executeMethod(head, TIMEOUT, TIMEOUT); + int status = client.executeMethod(propfind, TIMEOUT, TIMEOUT); if (previousFollowRedirects) { - mRedirectionPath = client.followRedirection(head); + mRedirectionPath = client.followRedirection(propfind); status = mRedirectionPath.getLastStatus(); } - client.exhaustResponse(head.getResponseBodyAsStream()); - boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || + if (status != FORBIDDEN_ERROR && status != SERVICE_UNAVAILABLE_ERROR) { + client.exhaustResponse(propfind.getResponseBodyAsStream()); + } + /** + * PROPFIND method + * 404 NOT FOUND: path doesn't exist, + * 207 MULTI_STATUS: path exists. + */ + boolean success = ((status == HttpStatus.SC_OK || status == HttpStatus.SC_MULTI_STATUS) && + !mSuccessIfAbsent) || + (status == HttpStatus.SC_MULTI_STATUS && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent); result = new RemoteOperationResult( success, - status, - head.getStatusText(), - head.getResponseHeaders() + propfind ); Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + @@ -115,8 +127,8 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { result.getLogMessage(), result.getException()); } finally { - if (head != null) - head.releaseConnection(); + if (propfind != null) + propfind.releaseConnection(); client.setFollowRedirects(previousFollowRedirects); } return result; From 9854ef6f60a3a95a3303f5c635d3e95141e760fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Mon, 20 Feb 2017 09:19:48 +0100 Subject: [PATCH 3/3] Update RemoteOperationResult.java --- .../android/lib/common/operations/RemoteOperationResult.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 8256b031..36dac58a 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -255,7 +255,7 @@ public class RemoteOperationResult implements Serializable { ErrorMessageParser xmlParser = new ErrorMessageParser(); try { String errorMessage = xmlParser.parseXMLResponse(is); - if (errorMessage != "" && errorMessage != null) { + if (errorMessage != null && errorMessage != "") { mCode = ResultCode.SPECIFIC_FORBIDDEN; mHttpPhrase = errorMessage; }