mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
stop validation process if failing
This commit is contained in:
parent
e878ad3931
commit
7ccb86c153
@ -5,6 +5,7 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory
|
|||||||
import com.owncloud.android.lib.common.http.HttpConstants
|
import com.owncloud.android.lib.common.http.HttpConstants
|
||||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
|
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
|
import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation
|
||||||
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation
|
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation
|
||||||
import com.owncloud.android.lib.resources.status.RemoteServerInfo
|
import com.owncloud.android.lib.resources.status.RemoteServerInfo
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils
|
import org.apache.commons.lang3.exception.ExceptionUtils
|
||||||
@ -15,7 +16,7 @@ class ConnectionValidator (
|
|||||||
val clearCookiesOnValidation: Boolean
|
val clearCookiesOnValidation: Boolean
|
||||||
){
|
){
|
||||||
|
|
||||||
fun validate(method: HttpBaseMethod, baseClient: OwnCloudClient): Boolean {
|
fun validate(baseClient: OwnCloudClient): Boolean {
|
||||||
try {
|
try {
|
||||||
var validationRetryCount = 0
|
var validationRetryCount = 0
|
||||||
val client = OwnCloudClient(baseClient.baseUri, null, false)
|
val client = OwnCloudClient(baseClient.baseUri, null, false)
|
||||||
@ -26,27 +27,28 @@ class ConnectionValidator (
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.credentials = baseClient.credentials
|
client.credentials = baseClient.credentials
|
||||||
client.setFollowRedirects(true)
|
|
||||||
while (validationRetryCount < 5) {
|
while (validationRetryCount < 5) {
|
||||||
var successCounter = 0
|
var successCounter = 0
|
||||||
var failCounter = 0
|
var failCounter = 0
|
||||||
|
|
||||||
|
client.setFollowRedirects(true)
|
||||||
if (isOnwCloudStatusOk(client)) {
|
if (isOnwCloudStatusOk(client)) {
|
||||||
successCounter++
|
successCounter++
|
||||||
} else {
|
} else {
|
||||||
failCounter++
|
failCounter++
|
||||||
}
|
}
|
||||||
|
|
||||||
val contentReply = accessRootFolder()
|
client.setFollowRedirects(false)
|
||||||
if (contentReply == HttpConstants.HTTP_OK) {
|
val contentReply = canAccessRootFolder(client)
|
||||||
if (isRootFolderOk(contentReply)) {
|
if (contentReply.httpCode == HttpConstants.HTTP_OK) {
|
||||||
|
if (contentReply.data == true) { //if data is true it means that the content reply was ok
|
||||||
successCounter++
|
successCounter++
|
||||||
} else {
|
} else {
|
||||||
failCounter++
|
failCounter++
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
failCounter++
|
failCounter++
|
||||||
if (contentReply == HttpConstants.HTTP_UNAUTHORIZED) {
|
if (contentReply.hashCode() == HttpConstants.HTTP_UNAUTHORIZED) {
|
||||||
triggerAuthRefresh()
|
triggerAuthRefresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,39 +66,24 @@ class ConnectionValidator (
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
|
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
|
||||||
//TODO: Implement me
|
|
||||||
val reply = getOwnCloudStatus(client)
|
val reply = getOwnCloudStatus(client)
|
||||||
return if (reply.httpCode == HttpConstants.HTTP_OK) {
|
return reply.httpCode == HttpConstants.HTTP_OK &&
|
||||||
isOCStatusReplyValid(reply.data)
|
!reply.isException &&
|
||||||
} else {
|
reply.data != null
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getOwnCloudStatus(client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo> {
|
private fun getOwnCloudStatus(client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo> {
|
||||||
val remoteStatusOperation = GetRemoteStatusOperation()
|
val remoteStatusOperation = GetRemoteStatusOperation()
|
||||||
//TODO: follow redirects only 5 times
|
|
||||||
return remoteStatusOperation.execute(client)
|
return remoteStatusOperation.execute(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isOCStatusReplyValid(info: RemoteServerInfo): Boolean {
|
|
||||||
//TODO: Implement me
|
|
||||||
Timber.d("owncloud version %s", info.ownCloudVersion.version)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun triggerAuthRefresh(): OwnCloudCredentials {
|
private fun triggerAuthRefresh(): OwnCloudCredentials {
|
||||||
//TODO: Implement me
|
//TODO: Implement me
|
||||||
return OwnCloudCredentialsFactory.getAnonymousCredentials()
|
return OwnCloudCredentialsFactory.getAnonymousCredentials()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun accessRootFolder(): Int {
|
private fun canAccessRootFolder(client: OwnCloudClient): RemoteOperationResult<Boolean> {
|
||||||
//TODO: Implement me
|
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation("/", true)
|
||||||
return 55
|
return checkPathExistenceRemoteOperation.execute(client)
|
||||||
}
|
|
||||||
|
|
||||||
private fun isRootFolderOk(content: Int): Boolean {
|
|
||||||
//TODO: Implement me
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -56,7 +56,6 @@ import static com.owncloud.android.lib.common.http.HttpConstants.OC_X_REQUEST_ID
|
|||||||
public class OwnCloudClient extends HttpClient {
|
public class OwnCloudClient extends HttpClient {
|
||||||
|
|
||||||
public static final String WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/";
|
public static final String WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/";
|
||||||
public static final String WEBDAV_PATH_4_0_AND_LATER = "/remote.php/dav";
|
|
||||||
public static final String STATUS_PATH = "/status.php";
|
public static final String STATUS_PATH = "/status.php";
|
||||||
private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/";
|
private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/";
|
||||||
private static final int MAX_REDIRECTIONS_COUNT = 5;
|
private static final int MAX_REDIRECTIONS_COUNT = 5;
|
||||||
@ -137,8 +136,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
|
|
||||||
if (mConnectionValidator != null &&
|
if (mConnectionValidator != null &&
|
||||||
status == HttpConstants.HTTP_MOVED_TEMPORARILY) {
|
status == HttpConstants.HTTP_MOVED_TEMPORARILY) {
|
||||||
mConnectionValidator.validate(method, this);
|
retry = mConnectionValidator.validate(this); // retry on success fail on no success
|
||||||
retry = true;
|
|
||||||
} else if (mFollowRedirects) {
|
} else if (mFollowRedirects) {
|
||||||
status = followRedirection(method).getLastStatus();
|
status = followRedirection(method).getLastStatus();
|
||||||
}
|
}
|
||||||
@ -463,4 +461,4 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
public void setFollowRedirects(boolean followRedirects) {
|
public void setFollowRedirects(boolean followRedirects) {
|
||||||
this.mFollowRedirects = followRedirects;
|
this.mFollowRedirects = followRedirects;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -98,11 +98,6 @@ class CheckPathExistenceRemoteOperation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return 'True' if the operation was executed and at least one redirection was followed.
|
|
||||||
*/
|
|
||||||
fun wasRedirected() = redirectionPath?.redirectionsCount ?: 0 > 0
|
|
||||||
|
|
||||||
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS
|
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user