mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
rebase okhttp_signleton fix on top of connection validator
fix token oauth token refresh error pleasure the linter
This commit is contained in:
parent
fc4ae27bbe
commit
09375ce053
@ -1,3 +1,27 @@
|
||||
/* 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
|
||||
|
||||
import android.accounts.AccountManager
|
||||
@ -15,6 +39,11 @@ import timber.log.Timber
|
||||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
|
||||
/**
|
||||
* ConnectionValidator
|
||||
*
|
||||
* @author Christian Schabesberger
|
||||
*/
|
||||
class ConnectionValidator(
|
||||
val context: Context,
|
||||
val clearCookiesOnValidation: Boolean
|
||||
|
@ -150,12 +150,15 @@ public class OwnCloudClient extends HttpClient {
|
||||
}
|
||||
|
||||
private boolean shouldConnectionValidatorBeCalled(HttpBaseMethod method, int status) {
|
||||
return !mFollowRedirects &&
|
||||
!method.getFollowRedirects() &&
|
||||
mConnectionValidator != null &&
|
||||
(status == HttpConstants.HTTP_MOVED_TEMPORARILY ||
|
||||
(!(mCredentials instanceof OwnCloudAnonymousCredentials) &&
|
||||
status == HttpConstants.HTTP_UNAUTHORIZED));
|
||||
|
||||
return mConnectionValidator != null && (
|
||||
(!(mCredentials instanceof OwnCloudAnonymousCredentials) &&
|
||||
status == HttpConstants.HTTP_UNAUTHORIZED
|
||||
) || (!mFollowRedirects &&
|
||||
!method.getFollowRedirects() &&
|
||||
status == HttpConstants.HTTP_MOVED_TEMPORARILY
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,12 +40,12 @@ import java.util.concurrent.TimeUnit
|
||||
abstract class HttpBaseMethod constructor(url: URL) {
|
||||
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
||||
var request: Request
|
||||
private var _followPermanentRedirects = false
|
||||
var followPermanentRedirects = false
|
||||
abstract var response: Response
|
||||
var call: Call? = null
|
||||
|
||||
var followRedirects: Boolean? = true
|
||||
var retryOnConnectionFailure: Boolean? = false
|
||||
var followRedirects: Boolean = true
|
||||
var retryOnConnectionFailure: Boolean = false
|
||||
var connectionTimeoutVal: Long? = null
|
||||
var connectionTimeoutUnit: TimeUnit? = null
|
||||
var readTimeoutVal: Long? = null
|
||||
|
@ -62,10 +62,8 @@ class CheckPathExistenceRemoteOperation(
|
||||
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
propFindMethod.followRedirects = false
|
||||
>>>>>>> 27ecf79c (remove redundant intercept of httpclient with httpmethod)
|
||||
|
||||
var status = client.executeHttpMethod(propFindMethod)
|
||||
/* PROPFIND method
|
||||
* 404 NOT FOUND: path doesn't exist,
|
||||
|
@ -55,7 +55,7 @@ class GetOIDCDiscoveryRemoteOperation : RemoteOperation<OIDCDiscoveryResponse>()
|
||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||
}
|
||||
|
||||
getMethod.setFollowRedirects(true)
|
||||
getMethod.followRedirects = true
|
||||
val status = client.executeHttpMethod(getMethod)
|
||||
|
||||
val responseBody = getMethod.getResponseBodyAsString()
|
||||
|
@ -25,7 +25,6 @@
|
||||
package com.owncloud.android.lib.resources.status
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.common.http.HttpClient
|
||||
import com.owncloud.android.lib.common.http.HttpConstants
|
||||
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
@ -64,7 +63,7 @@ internal class StatusRequester {
|
||||
return URL(oldLocationURL.protocol, oldLocationURL.host, oldLocationURL.port, redirectedLocation).toString()
|
||||
}
|
||||
|
||||
private fun getGetMethod(client: HttpClient, url: String): GetMethod {
|
||||
private fun getGetMethod(url: String): GetMethod {
|
||||
return GetMethod(URL(url)).apply {
|
||||
setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||
setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||
@ -80,15 +79,10 @@ internal class StatusRequester {
|
||||
fun request(baseLocation: String, client: OwnCloudClient): RequestResult {
|
||||
val currentLocation = baseLocation + OwnCloudClient.STATUS_PATH
|
||||
var status: Int
|
||||
|
||||
<<<<<<< HEAD
|
||||
val getMethod = getGetMethod(currentLocation)
|
||||
getMethod.setFollowPermanentRedirects(true)
|
||||
|
||||
getMethod.followPermanentRedirects = true
|
||||
status = client.executeHttpMethod(getMethod)
|
||||
=======
|
||||
while (true) {
|
||||
val getMethod = getGetMethod(client, currentLocation)
|
||||
>>>>>>> 530f8644 (apply required fixes)
|
||||
|
||||
return RequestResult(getMethod, status, getMethod.getFinalUrl().toString())
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.lib.resources.status.RemoteServerInfo
|
||||
|
||||
interface ServerInfoService {
|
||||
fun checkPathExistence(path: String, isUserLogged: Boolean, client: OwnCloudClient): RemoteOperationResult<Boolean>
|
||||
fun checkPathExistence(path: String, isUserLoggedIn: Boolean, client: OwnCloudClient): RemoteOperationResult<Boolean>
|
||||
|
||||
fun getRemoteStatus(path: String, client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo>
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class OCServerInfoService : ServerInfoService {
|
||||
|
||||
override fun checkPathExistence(
|
||||
path: String,
|
||||
isUserLogged: Boolean,
|
||||
isUserLoggedIn: Boolean,
|
||||
client: OwnCloudClient
|
||||
): RemoteOperationResult<Boolean> =
|
||||
CheckPathExistenceRemoteOperation(
|
||||
|
@ -37,14 +37,9 @@ import android.view.View;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
<<<<<<< HEAD
|
||||
import com.owncloud.android.lib.common.ConnectionValidator;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
=======
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
|
||||
import com.owncloud.android.lib.common.SingleSessionManager;
|
||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
|
||||
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
||||
@ -55,13 +50,8 @@ import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
|
||||
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
|
||||
import com.owncloud.android.lib.resources.files.RemoteFile;
|
||||
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
|
||||
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
import info.hannes.timber.DebugTree;
|
||||
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -84,30 +74,20 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
<<<<<<< HEAD
|
||||
Timber.plant();
|
||||
=======
|
||||
Timber.plant(new DebugTree());
|
||||
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
|
||||
mHandler = new Handler();
|
||||
|
||||
final Uri serverUri = Uri.parse(getString(R.string.server_base_url));
|
||||
|
||||
SingleSessionManager.setUserAgent(getUserAgent());
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
SingleSessionManager.setConnectionValidator(new ConnectionValidator(this, false));
|
||||
mClient = new OwnCloudClient(serverUri,
|
||||
SingleSessionManager.getConnectionValidator(),
|
||||
true,
|
||||
SingleSessionManager.getDefaultSingleton());
|
||||
=======
|
||||
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, true);
|
||||
=======
|
||||
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
|
||||
>>>>>>> 530f8644 (apply required fixes)
|
||||
|
||||
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
|
||||
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
|
||||
|
||||
mClient.setCredentials(
|
||||
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||
getString(R.string.username),
|
||||
|
Loading…
x
Reference in New Issue
Block a user