Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 7ccb86c

Browse files
committed
stop validation process if failing
1 parent e878ad3 commit 7ccb86c

File tree

3 files changed

+16
-36
lines changed

3 files changed

+16
-36
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/ConnectionValidator.kt

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory
55
import com.owncloud.android.lib.common.http.HttpConstants
66
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
77
import com.owncloud.android.lib.common.operations.RemoteOperationResult
8+
import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation
89
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation
910
import com.owncloud.android.lib.resources.status.RemoteServerInfo
1011
import org.apache.commons.lang3.exception.ExceptionUtils
@@ -15,7 +16,7 @@ class ConnectionValidator (
1516
val clearCookiesOnValidation: Boolean
1617
){
1718

18-
fun validate(method: HttpBaseMethod, baseClient: OwnCloudClient): Boolean {
19+
fun validate(baseClient: OwnCloudClient): Boolean {
1920
try {
2021
var validationRetryCount = 0
2122
val client = OwnCloudClient(baseClient.baseUri, null, false)
@@ -26,27 +27,28 @@ class ConnectionValidator (
2627
}
2728

2829
client.credentials = baseClient.credentials
29-
client.setFollowRedirects(true)
3030
while (validationRetryCount < 5) {
3131
var successCounter = 0
3232
var failCounter = 0
3333

34+
client.setFollowRedirects(true)
3435
if (isOnwCloudStatusOk(client)) {
3536
successCounter++
3637
} else {
3738
failCounter++
3839
}
3940

40-
val contentReply = accessRootFolder()
41-
if (contentReply == HttpConstants.HTTP_OK) {
42-
if (isRootFolderOk(contentReply)) {
41+
client.setFollowRedirects(false)
42+
val contentReply = canAccessRootFolder(client)
43+
if (contentReply.httpCode == HttpConstants.HTTP_OK) {
44+
if (contentReply.data == true) { //if data is true it means that the content reply was ok
4345
successCounter++
4446
} else {
4547
failCounter++
4648
}
4749
} else {
4850
failCounter++
49-
if (contentReply == HttpConstants.HTTP_UNAUTHORIZED) {
51+
if (contentReply.hashCode() == HttpConstants.HTTP_UNAUTHORIZED) {
5052
triggerAuthRefresh()
5153
}
5254
}
@@ -64,39 +66,24 @@ class ConnectionValidator (
6466
}
6567

6668
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
67-
//TODO: Implement me
6869
val reply = getOwnCloudStatus(client)
69-
return if (reply.httpCode == HttpConstants.HTTP_OK) {
70-
isOCStatusReplyValid(reply.data)
71-
} else {
72-
false
73-
}
70+
return reply.httpCode == HttpConstants.HTTP_OK &&
71+
!reply.isException &&
72+
reply.data != null
7473
}
7574

7675
private fun getOwnCloudStatus(client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo> {
7776
val remoteStatusOperation = GetRemoteStatusOperation()
78-
//TODO: follow redirects only 5 times
7977
return remoteStatusOperation.execute(client)
8078
}
8179

82-
private fun isOCStatusReplyValid(info: RemoteServerInfo): Boolean {
83-
//TODO: Implement me
84-
Timber.d("owncloud version %s", info.ownCloudVersion.version)
85-
return true
86-
}
87-
8880
private fun triggerAuthRefresh(): OwnCloudCredentials {
8981
//TODO: Implement me
9082
return OwnCloudCredentialsFactory.getAnonymousCredentials()
9183
}
9284

93-
private fun accessRootFolder(): Int {
94-
//TODO: Implement me
95-
return 55
96-
}
97-
98-
private fun isRootFolderOk(content: Int): Boolean {
99-
//TODO: Implement me
100-
return true
85+
private fun canAccessRootFolder(client: OwnCloudClient): RemoteOperationResult<Boolean> {
86+
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation("/", true)
87+
return checkPathExistenceRemoteOperation.execute(client)
10188
}
10289
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
public class OwnCloudClient extends HttpClient {
5757

5858
public static final String WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/";
59-
public static final String WEBDAV_PATH_4_0_AND_LATER = "/remote.php/dav";
6059
public static final String STATUS_PATH = "/status.php";
6160
private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/";
6261
private static final int MAX_REDIRECTIONS_COUNT = 5;
@@ -137,8 +136,7 @@ private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
137136

138137
if (mConnectionValidator != null &&
139138
status == HttpConstants.HTTP_MOVED_TEMPORARILY) {
140-
mConnectionValidator.validate(method, this);
141-
retry = true;
139+
retry = mConnectionValidator.validate(this); // retry on success fail on no success
142140
} else if (mFollowRedirects) {
143141
status = followRedirection(method).getLastStatus();
144142
}
@@ -463,4 +461,4 @@ public boolean getFollowRedirects() {
463461
public void setFollowRedirects(boolean followRedirects) {
464462
this.mFollowRedirects = followRedirects;
465463
}
466-
}
464+
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ class CheckPathExistenceRemoteOperation(
9898
}
9999
}
100100

101-
/**
102-
* @return 'True' if the operation was executed and at least one redirection was followed.
103-
*/
104-
fun wasRedirected() = redirectionPath?.redirectionsCount ?: 0 > 0
105-
106101
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS
107102

108103
companion object {

0 commit comments

Comments
 (0)