From 21121e018961157fa6bfa945b7f728de6f9eb45c Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 25 Jan 2017 13:42:43 +0100 Subject: [PATCH 1/8] Added forbidden exception parser --- .../operations/ForbiddenExceptionParser.java | 143 ++++++++++++++++++ .../InvalidCharacterExceptionParser.java | 2 - .../operations/RemoteOperationResult.java | 75 +++++---- 3 files changed, 189 insertions(+), 31 deletions(-) create mode 100644 src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java diff --git a/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java b/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java new file mode 100644 index 00000000..c6d9124f --- /dev/null +++ b/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java @@ -0,0 +1,143 @@ + +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2016 ownCloud GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.owncloud.android.lib.common.operations; + +import android.util.Xml; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlPullParserFactory; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Parser for forbidden server exception + * @author masensio + */ +public class ForbiddenExceptionParser { + + private static final String EXCEPTION_STRING = "OCA\\DAV\\Connector\\Sabre\\Exception\\Forbidden"; + + // No namespaces + private static final String ns = null; + + // Nodes for XML Parser + private static final String NODE_ERROR = "d:error"; + private static final String NODE_MESSAGE = "s:message"; + + /** + * Parse is as an forbidden exception + * @param is + * @return reason for forbidden exception + * @throws XmlPullParserException + * @throws IOException + */ + public String parseXMLResponse(InputStream is) throws XmlPullParserException, + IOException { + String errorMessage = ""; + + try { + // XMLPullParser + XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); + factory.setNamespaceAware(true); + + XmlPullParser parser = Xml.newPullParser(); + parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); + parser.setInput(is, null); + parser.nextTag(); + errorMessage = readError(parser); + + } finally { + is.close(); + } + return errorMessage; + } + + /** + * Parse OCS node + * @param parser + * @return reason for forbidden exception + * @throws XmlPullParserException + * @throws IOException + */ + private String readError (XmlPullParser parser) throws XmlPullParserException, IOException { + String message = ""; + parser.require(XmlPullParser.START_TAG, ns , NODE_ERROR); + while (parser.next() != XmlPullParser.END_TAG) { + if (parser.getEventType() != XmlPullParser.START_TAG) { + continue; + } + String name = parser.getName(); + // read NODE_MESSAGE + if (name.equalsIgnoreCase(NODE_MESSAGE)) { + message = readText(parser); + } else { + skip(parser); + } + + } + return message; + } + + /** + * Skip tags in parser procedure + * @param parser + * @throws XmlPullParserException + * @throws IOException + */ + private void skip(XmlPullParser parser) throws XmlPullParserException, IOException { + if (parser.getEventType() != XmlPullParser.START_TAG) { + throw new IllegalStateException(); + } + int depth = 1; + while (depth != 0) { + switch (parser.next()) { + case XmlPullParser.END_TAG: + depth--; + break; + case XmlPullParser.START_TAG: + depth++; + break; + } + } + } + + /** + * Read the text from a node + * @param parser + * @return Text of the node + * @throws IOException + * @throws XmlPullParserException + */ + private String readText(XmlPullParser parser) throws IOException, XmlPullParserException { + String result = ""; + if (parser.next() == XmlPullParser.TEXT) { + result = parser.getText(); + parser.nextTag(); + } + return result; + } +} diff --git a/src/com/owncloud/android/lib/common/operations/InvalidCharacterExceptionParser.java b/src/com/owncloud/android/lib/common/operations/InvalidCharacterExceptionParser.java index 4629a6a1..a7cc9cc6 100644 --- a/src/com/owncloud/android/lib/common/operations/InvalidCharacterExceptionParser.java +++ b/src/com/owncloud/android/lib/common/operations/InvalidCharacterExceptionParser.java @@ -101,8 +101,6 @@ public class InvalidCharacterExceptionParser { } return exception.equalsIgnoreCase(EXCEPTION_STRING) || exception.equalsIgnoreCase(EXCEPTION_UPLOAD_STRING); - - } /** diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 6c9c6ffd..7008cc07 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -63,7 +63,9 @@ import javax.net.ssl.SSLException; */ public class RemoteOperationResult implements Serializable { - /** Generated - should be refreshed every time the class changes!! */ + /** + * Generated - should be refreshed every time the class changes!! + */ private static final long serialVersionUID = 4968939884332372230L; private static final String TAG = RemoteOperationResult.class.getSimpleName(); @@ -131,10 +133,10 @@ public class RemoteOperationResult implements Serializable { /** * Public constructor from result code. - * + *

* To be used when the caller takes the responsibility of interpreting the result of a {@link RemoteOperation} * - * @param code {@link ResultCode} decided by the caller. + * @param code {@link ResultCode} decided by the caller. */ public RemoteOperationResult(ResultCode code) { mCode = code; @@ -146,12 +148,12 @@ public class RemoteOperationResult implements Serializable { /** * Public constructor from exception. - * + *

* To be used when an exception prevented the end of the {@link RemoteOperation}. - * + *

* Determines a {@link ResultCode} depending on the type of the exception. * - * @param e Exception that interrupted the {@link RemoteOperation} + * @param e Exception that interrupted the {@link RemoteOperation} */ public RemoteOperationResult(Exception e) { mException = e; @@ -205,28 +207,28 @@ public class RemoteOperationResult implements Serializable { /** * Public constructor from separate elements of an HTTP or DAV response. - * + *

* To be used when the result needs to be interpreted from the response of an HTTP/DAV method. - * + *

* Determines a {@link ResultCode} from the already executed method received as a parameter. Generally, * will depend on the HTTP code and HTTP response headers received. In some cases will inspect also the * response body. * - * @param success The operation was considered successful or not. - * @param httpMethod HTTP/DAV method already executed which response will be examined to interpret the - * result. + * @param success The operation was considered successful or not. + * @param httpMethod HTTP/DAV method already executed which response will be examined to interpret the + * result. */ public RemoteOperationResult(boolean success, HttpMethod httpMethod) throws IOException { this( - success, - httpMethod.getStatusCode(), - httpMethod.getStatusText(), - httpMethod.getResponseHeaders() + success, + httpMethod.getStatusCode(), + httpMethod.getStatusText(), + httpMethod.getResponseHeaders() ); if (mHttpCode == HttpStatus.SC_BAD_REQUEST) { // 400 String bodyResponse = httpMethod.getResponseBodyAsString(); - // do not get for other HTTP codes!; could not be available + // do not get for other HTTP codes!; could not be available if (bodyResponse != null && bodyResponse.length() > 0) { InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); @@ -242,23 +244,38 @@ public class RemoteOperationResult implements Serializable { } } } + + if (mHttpCode == HttpStatus.SC_FORBIDDEN) { + String bodyResponse = httpMethod.getResponseBodyAsString(); + + if (bodyResponse != null && bodyResponse.length() > 0) { + InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); + ForbiddenExceptionParser xmlParser = new ForbiddenExceptionParser(); + try { + mHttpPhrase = xmlParser.parseXMLResponse(is); + } catch (Exception e) { + Log_OC.w(TAG, "Error reading exception from server: " + e.getMessage()); + // mCode stays as set in this(success, httpCode, headers) + } + } + } } /** * Public constructor from separate elements of an HTTP or DAV response. - * + *

* To be used when the result needs to be interpreted from HTTP response elements that could come from * different requests (WARNING: black magic, try to avoid). - * + *

* If all the fields come from the same HTTP/DAV response, {@link #RemoteOperationResult(boolean, HttpMethod)} * should be used instead. - * + *

* Determines a {@link ResultCode} depending on the HTTP code and HTTP response headers received. * - * @param success The operation was considered successful or not. - * @param httpCode HTTP status code returned by an HTTP/DAV method. - * @param httpPhrase HTTP status line phrase returned by an HTTP/DAV method - * @param httpHeaders HTTP response header returned by an HTTP/DAV method + * @param success The operation was considered successful or not. + * @param httpCode HTTP status code returned by an HTTP/DAV method. + * @param httpPhrase HTTP status line phrase returned by an HTTP/DAV method + * @param httpHeaders HTTP response header returned by an HTTP/DAV method */ public RemoteOperationResult(boolean success, int httpCode, String httpPhrase, Header[] httpHeaders) { this(success, httpCode, httpPhrase); @@ -283,12 +300,12 @@ public class RemoteOperationResult implements Serializable { /** * Private constructor for results built interpreting a HTTP or DAV response. - * + *

* Determines a {@link ResultCode} depending of the type of the exception. * - * @param success Operation was successful or not. - * @param httpCode HTTP status code returned by the HTTP/DAV method. - * @param httpPhrase HTTP status line phrase returned by the HTTP/DAV method + * @param success Operation was successful or not. + * @param httpCode HTTP status code returned by the HTTP/DAV method. + * @param httpPhrase HTTP status line phrase returned by the HTTP/DAV method */ private RemoteOperationResult(boolean success, int httpCode, String httpPhrase) { mSuccess = success; @@ -324,8 +341,8 @@ public class RemoteOperationResult implements Serializable { default: mCode = ResultCode.UNHANDLED_HTTP_CODE; // UNKNOWN ERROR Log_OC.d(TAG, - "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + - mHttpCode + " " + mHttpPhrase + "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + + mHttpCode + " " + mHttpPhrase ); } } From 1aba54d0f9cb0abce7235c1586dcdb69aa8e620d Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 26 Jan 2017 10:24:47 +0100 Subject: [PATCH 2/8] Handle specific forbidden error --- .../operations/ForbiddenExceptionParser.java | 44 +++++++++---------- .../operations/RemoteOperationResult.java | 7 ++- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java b/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java index c6d9124f..27d11aad 100644 --- a/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java +++ b/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java @@ -38,17 +38,14 @@ import java.io.InputStream; * @author masensio */ public class ForbiddenExceptionParser { - - private static final String EXCEPTION_STRING = "OCA\\DAV\\Connector\\Sabre\\Exception\\Forbidden"; - - // No namespaces + // No namespaces private static final String ns = null; - // Nodes for XML Parser - private static final String NODE_ERROR = "d:error"; + // Nodes for XML Parser + private static final String NODE_ERROR = "d:error"; private static final String NODE_MESSAGE = "s:message"; - /** + /** * Parse is as an forbidden exception * @param is * @return reason for forbidden exception @@ -56,8 +53,8 @@ public class ForbiddenExceptionParser { * @throws IOException */ public String parseXMLResponse(InputStream is) throws XmlPullParserException, - IOException { - String errorMessage = ""; + IOException { + String errorMessage = ""; try { // XMLPullParser @@ -68,7 +65,7 @@ public class ForbiddenExceptionParser { parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); parser.setInput(is, null); parser.nextTag(); - errorMessage = readError(parser); + errorMessage = readError(parser); } finally { is.close(); @@ -84,7 +81,7 @@ public class ForbiddenExceptionParser { * @throws IOException */ private String readError (XmlPullParser parser) throws XmlPullParserException, IOException { - String message = ""; + String errorMessage = ""; parser.require(XmlPullParser.START_TAG, ns , NODE_ERROR); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { @@ -92,14 +89,13 @@ public class ForbiddenExceptionParser { } String name = parser.getName(); // read NODE_MESSAGE - if (name.equalsIgnoreCase(NODE_MESSAGE)) { - message = readText(parser); - } else { + if (name.equalsIgnoreCase(NODE_MESSAGE)) { + errorMessage = readText(parser); + } else { skip(parser); } - } - return message; + return errorMessage; } /** @@ -115,17 +111,17 @@ public class ForbiddenExceptionParser { int depth = 1; while (depth != 0) { switch (parser.next()) { - case XmlPullParser.END_TAG: - depth--; - break; - case XmlPullParser.START_TAG: - depth++; - break; + case XmlPullParser.END_TAG: + depth--; + break; + case XmlPullParser.START_TAG: + depth++; + break; } } } - /** + /** * Read the text from a node * @param parser * @return Text of the node @@ -140,4 +136,4 @@ public class ForbiddenExceptionParser { } return result; } -} +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 7008cc07..b14efdb7 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -107,6 +107,7 @@ public class RemoteOperationResult implements Serializable { LOCAL_STORAGE_NOT_REMOVED, FORBIDDEN, SHARE_FORBIDDEN, + SPECIFIC_FORBIDDEN, OK_REDIRECT_TO_NON_SECURE_CONNECTION, INVALID_MOVE_INTO_DESCENDANT, INVALID_COPY_INTO_DESCENDANT, @@ -252,7 +253,11 @@ public class RemoteOperationResult implements Serializable { InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); ForbiddenExceptionParser xmlParser = new ForbiddenExceptionParser(); try { - mHttpPhrase = xmlParser.parseXMLResponse(is); + String errorMessage = xmlParser.parseXMLResponse(is); + if (errorMessage != "" && errorMessage != null) { + mCode = ResultCode.SPECIFIC_FORBIDDEN; + 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) From 67e5ccd4afb16dcc365f6fe798a1a575b8f0863e Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 26 Jan 2017 17:01:48 +0100 Subject: [PATCH 3/8] Exhaust response if status is different from 403 --- .../lib/resources/files/DownloadRemoteFileOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java index 45515943..7f49ce97 100644 --- a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java @@ -160,7 +160,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { // TODO some kind of error control! } - } else { + } else if (status != 403){ client.exhaustResponse(mGet.getResponseBodyAsStream()); } From d7a707293d6f590e811f3d315ed827ad3c351ff1 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Fri, 27 Jan 2017 10:37:41 +0100 Subject: [PATCH 4/8] Prevent that connection manager cleans up response buffer of failed downloads --- .../files/DownloadRemoteFileOperation.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java index 7f49ce97..5ba1b618 100644 --- a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java @@ -82,8 +82,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { /// perform the download try { tmpFile.getParentFile().mkdirs(); - int status = downloadFile(client, tmpFile); - result = new RemoteOperationResult(isSuccess(status), mGet); + result = downloadFile(client, tmpFile); Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + result.getLogMessage()); @@ -97,8 +96,10 @@ public class DownloadRemoteFileOperation extends RemoteOperation { } - protected int downloadFile(OwnCloudClient client, File targetFile) throws HttpException, + private RemoteOperationResult downloadFile(OwnCloudClient client, File targetFile) throws IOException, OperationCancelledException { + + RemoteOperationResult result; int status = -1; boolean savedFile = false; mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); @@ -162,7 +163,10 @@ public class DownloadRemoteFileOperation extends RemoteOperation { } else if (status != 403){ client.exhaustResponse(mGet.getResponseBodyAsStream()); - } + + } // else, body read by RemoteOeprationResult constructor + + result = new RemoteOperationResult(isSuccess(status), mGet); } finally { if (fos != null) fos.close(); @@ -171,7 +175,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { } mGet.releaseConnection(); // let the connection available for other methods } - return status; + return result; } private boolean isSuccess(int status) { From 6a3d97a4748d51859b9820eb97c9ecf3fde93e8b Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 25 Jan 2017 13:42:43 +0100 Subject: [PATCH 5/8] Added forbidden exception parser --- .../android/lib/common/operations/ForbiddenExceptionParser.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java b/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java index 27d11aad..df9bdab3 100644 --- a/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java +++ b/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java @@ -1,4 +1,3 @@ - /* ownCloud Android Library is available under MIT license * Copyright (C) 2016 ownCloud GmbH. * From 12e7af8af5a1586bae55bfffa5a014a411cac8d9 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 6 Feb 2017 12:13:22 +0100 Subject: [PATCH 6/8] Reformat code --- ...tionParser.java => ErrorMessageParser.java} | 12 ++++++------ .../operations/RemoteOperationResult.java | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) rename src/com/owncloud/android/lib/common/operations/{ForbiddenExceptionParser.java => ErrorMessageParser.java} (94%) diff --git a/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java b/src/com/owncloud/android/lib/common/operations/ErrorMessageParser.java similarity index 94% rename from src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java rename to src/com/owncloud/android/lib/common/operations/ErrorMessageParser.java index df9bdab3..35fdf94a 100644 --- a/src/com/owncloud/android/lib/common/operations/ForbiddenExceptionParser.java +++ b/src/com/owncloud/android/lib/common/operations/ErrorMessageParser.java @@ -33,10 +33,10 @@ import java.io.IOException; import java.io.InputStream; /** - * Parser for forbidden server exception - * @author masensio + * Parser for server exceptions + * @author davidgonzalez */ -public class ForbiddenExceptionParser { +public class ErrorMessageParser { // No namespaces private static final String ns = null; @@ -45,9 +45,9 @@ public class ForbiddenExceptionParser { private static final String NODE_MESSAGE = "s:message"; /** - * Parse is as an forbidden exception + * Parse exception response * @param is - * @return reason for forbidden exception + * @return errorMessage for an exception * @throws XmlPullParserException * @throws IOException */ @@ -75,7 +75,7 @@ public class ForbiddenExceptionParser { /** * Parse OCS node * @param parser - * @return reason for forbidden exception + * @return reason for exception * @throws XmlPullParserException * @throws IOException */ diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index b14efdb7..e4b2c67e 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -1,22 +1,22 @@ /* ownCloud Android Library is available under MIT license * Copyright (C) 2016 ownCloud GmbH. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * @@ -251,7 +251,7 @@ public class RemoteOperationResult implements Serializable { if (bodyResponse != null && bodyResponse.length() > 0) { InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); - ForbiddenExceptionParser xmlParser = new ForbiddenExceptionParser(); + ErrorMessageParser xmlParser = new ErrorMessageParser(); try { String errorMessage = xmlParser.parseXMLResponse(is); if (errorMessage != "" && errorMessage != null) { From 626e2f0efa79abd714f7bf56f6cfe38c2fbb5c61 Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 7 Feb 2017 08:53:14 +0100 Subject: [PATCH 7/8] Added changes requested in PR --- .../android/lib/common/operations/RemoteOperationResult.java | 2 +- .../lib/resources/files/DownloadRemoteFileOperation.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index e4b2c67e..6c3cefd3 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -254,7 +254,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; } diff --git a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java index 5ba1b618..0a013bee 100644 --- a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java @@ -57,6 +57,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; public class DownloadRemoteFileOperation extends RemoteOperation { private static final String TAG = DownloadRemoteFileOperation.class.getSimpleName(); + private static final int FORBIDDEN_ERROR = 403; private Set mDataTransferListeners = new HashSet(); private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); @@ -161,7 +162,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { // TODO some kind of error control! } - } else if (status != 403){ + } else if (status != FORBIDDEN_ERROR){ client.exhaustResponse(mGet.getResponseBodyAsStream()); } // else, body read by RemoteOeprationResult constructor From 1f58cfc941c6d6754fec93f4f180e5a40ec91bcd Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 7 Feb 2017 13:11:06 +0100 Subject: [PATCH 8/8] Update comment --- .../android/lib/common/operations/ErrorMessageParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/owncloud/android/lib/common/operations/ErrorMessageParser.java b/src/com/owncloud/android/lib/common/operations/ErrorMessageParser.java index 35fdf94a..68b43984 100644 --- a/src/com/owncloud/android/lib/common/operations/ErrorMessageParser.java +++ b/src/com/owncloud/android/lib/common/operations/ErrorMessageParser.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2017 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal