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

Commit 09375ce

Browse files
theScrabiabelgardep
authored andcommitted
rebase okhttp_signleton fix on top of connection validator
fix token oauth token refresh error pleasure the linter
1 parent fc4ae27 commit 09375ce

File tree

9 files changed

+49
-45
lines changed

9 files changed

+49
-45
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2016 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
*/
24+
125
package com.owncloud.android.lib.common
226

327
import android.accounts.AccountManager
@@ -15,6 +39,11 @@ import timber.log.Timber
1539
import java.io.IOException
1640
import java.lang.Exception
1741

42+
/**
43+
* ConnectionValidator
44+
*
45+
* @author Christian Schabesberger
46+
*/
1847
class ConnectionValidator(
1948
val context: Context,
2049
val clearCookiesOnValidation: Boolean

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,15 @@ private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
150150
}
151151

152152
private boolean shouldConnectionValidatorBeCalled(HttpBaseMethod method, int status) {
153-
return !mFollowRedirects &&
154-
!method.getFollowRedirects() &&
155-
mConnectionValidator != null &&
156-
(status == HttpConstants.HTTP_MOVED_TEMPORARILY ||
157-
(!(mCredentials instanceof OwnCloudAnonymousCredentials) &&
158-
status == HttpConstants.HTTP_UNAUTHORIZED));
153+
154+
return mConnectionValidator != null && (
155+
(!(mCredentials instanceof OwnCloudAnonymousCredentials) &&
156+
status == HttpConstants.HTTP_UNAUTHORIZED
157+
) || (!mFollowRedirects &&
158+
!method.getFollowRedirects() &&
159+
status == HttpConstants.HTTP_MOVED_TEMPORARILY
160+
)
161+
);
159162
}
160163

161164
/**

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ import java.util.concurrent.TimeUnit
4040
abstract class HttpBaseMethod constructor(url: URL) {
4141
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
4242
var request: Request
43-
private var _followPermanentRedirects = false
43+
var followPermanentRedirects = false
4444
abstract var response: Response
4545
var call: Call? = null
4646

47-
var followRedirects: Boolean? = true
48-
var retryOnConnectionFailure: Boolean? = false
47+
var followRedirects: Boolean = true
48+
var retryOnConnectionFailure: Boolean = false
4949
var connectionTimeoutVal: Long? = null
5050
var connectionTimeoutUnit: TimeUnit? = null
5151
var readTimeoutVal: Long? = null

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ class CheckPathExistenceRemoteOperation(
6262
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
6363
}
6464

65-
<<<<<<< HEAD
66-
=======
6765
propFindMethod.followRedirects = false
68-
>>>>>>> 27ecf79c (remove redundant intercept of httpclient with httpmethod)
66+
6967
var status = client.executeHttpMethod(propFindMethod)
7068
/* PROPFIND method
7169
* 404 NOT FOUND: path doesn't exist,

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/oauth/GetOIDCDiscoveryRemoteOperation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class GetOIDCDiscoveryRemoteOperation : RemoteOperation<OIDCDiscoveryResponse>()
5555
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
5656
}
5757

58-
getMethod.setFollowRedirects(true)
58+
getMethod.followRedirects = true
5959
val status = client.executeHttpMethod(getMethod)
6060

6161
val responseBody = getMethod.getResponseBodyAsString()

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/StatusRequester.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package com.owncloud.android.lib.resources.status
2626

2727
import com.owncloud.android.lib.common.OwnCloudClient
28-
import com.owncloud.android.lib.common.http.HttpClient
2928
import com.owncloud.android.lib.common.http.HttpConstants
3029
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
3130
import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -64,7 +63,7 @@ internal class StatusRequester {
6463
return URL(oldLocationURL.protocol, oldLocationURL.host, oldLocationURL.port, redirectedLocation).toString()
6564
}
6665

67-
private fun getGetMethod(client: HttpClient, url: String): GetMethod {
66+
private fun getGetMethod(url: String): GetMethod {
6867
return GetMethod(URL(url)).apply {
6968
setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
7069
setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
@@ -80,15 +79,10 @@ internal class StatusRequester {
8079
fun request(baseLocation: String, client: OwnCloudClient): RequestResult {
8180
val currentLocation = baseLocation + OwnCloudClient.STATUS_PATH
8281
var status: Int
83-
84-
<<<<<<< HEAD
8582
val getMethod = getGetMethod(currentLocation)
86-
getMethod.setFollowPermanentRedirects(true)
83+
84+
getMethod.followPermanentRedirects = true
8785
status = client.executeHttpMethod(getMethod)
88-
=======
89-
while (true) {
90-
val getMethod = getGetMethod(client, currentLocation)
91-
>>>>>>> 530f8644 (apply required fixes)
9286

9387
return RequestResult(getMethod, status, getMethod.getFinalUrl().toString())
9488
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/ServerInfoService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult
2929
import com.owncloud.android.lib.resources.status.RemoteServerInfo
3030

3131
interface ServerInfoService {
32-
fun checkPathExistence(path: String, isUserLogged: Boolean, client: OwnCloudClient): RemoteOperationResult<Boolean>
32+
fun checkPathExistence(path: String, isUserLoggedIn: Boolean, client: OwnCloudClient): RemoteOperationResult<Boolean>
3333

3434
fun getRemoteStatus(path: String, client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo>
3535
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCServerInfoService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class OCServerInfoService : ServerInfoService {
3838

3939
override fun checkPathExistence(
4040
path: String,
41-
isUserLogged: Boolean,
41+
isUserLoggedIn: Boolean,
4242
client: OwnCloudClient
4343
): RemoteOperationResult<Boolean> =
4444
CheckPathExistenceRemoteOperation(

sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,9 @@
3737
import android.widget.ListView;
3838
import android.widget.TextView;
3939
import android.widget.Toast;
40-
41-
<<<<<<< HEAD
4240
import com.owncloud.android.lib.common.ConnectionValidator;
4341
import com.owncloud.android.lib.common.OwnCloudClient;
44-
=======
45-
import com.owncloud.android.lib.common.OwnCloudClient;
4642
import com.owncloud.android.lib.common.OwnCloudClientFactory;
47-
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
4843
import com.owncloud.android.lib.common.SingleSessionManager;
4944
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
5045
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
@@ -55,13 +50,8 @@
5550
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
5651
import com.owncloud.android.lib.resources.files.RemoteFile;
5752
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
58-
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
59-
<<<<<<< HEAD
60-
=======
6153
import info.hannes.timber.DebugTree;
62-
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
6354
import timber.log.Timber;
64-
6555
import java.io.File;
6656
import java.io.FileOutputStream;
6757
import java.io.IOException;
@@ -84,30 +74,20 @@ public void onCreate(Bundle savedInstanceState) {
8474
super.onCreate(savedInstanceState);
8575
setContentView(R.layout.main);
8676

87-
<<<<<<< HEAD
88-
Timber.plant();
89-
=======
9077
Timber.plant(new DebugTree());
91-
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
9278
mHandler = new Handler();
9379

9480
final Uri serverUri = Uri.parse(getString(R.string.server_base_url));
9581

9682
SingleSessionManager.setUserAgent(getUserAgent());
97-
<<<<<<< HEAD
98-
<<<<<<< HEAD
9983
SingleSessionManager.setConnectionValidator(new ConnectionValidator(this, false));
10084
mClient = new OwnCloudClient(serverUri,
10185
SingleSessionManager.getConnectionValidator(),
10286
true,
10387
SingleSessionManager.getDefaultSingleton());
104-
=======
105-
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, true);
106-
=======
88+
10789
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
108-
>>>>>>> 530f8644 (apply required fixes)
10990

110-
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
11191
mClient.setCredentials(
11292
OwnCloudCredentialsFactory.newBasicCredentials(
11393
getString(R.string.username),

0 commit comments

Comments
 (0)