1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

debug and add mutex for halding requiests

This commit is contained in:
Christian Schabesberger 2021-08-24 15:47:24 +02:00
parent 39b1fce7f6
commit 2f952a3a09
2 changed files with 41 additions and 2 deletions

View File

@ -12,6 +12,7 @@ dependencies {
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion") { implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion") {
exclude module: "kotlin-reflect" exclude module: "kotlin-reflect"
} }
implementation 'org.apache.commons:commons-lang3:3.12.0'
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion" kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'

View File

@ -28,6 +28,7 @@ package com.owncloud.android.lib.common;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.accounts.AccountsException; import android.accounts.AccountsException;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import at.bitfire.dav4jvm.exception.HttpException; import at.bitfire.dav4jvm.exception.HttpException;
import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils;
@ -42,6 +43,7 @@ import com.owncloud.android.lib.common.utils.RandomUtils;
import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import okhttp3.Cookie; import okhttp3.Cookie;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import org.apache.commons.lang3.exception.ExceptionUtils;
import timber.log.Timber; import timber.log.Timber;
import java.io.IOException; import java.io.IOException;
@ -69,6 +71,8 @@ public class OwnCloudClient extends HttpClient {
private OwnCloudAccount mAccount; private OwnCloudAccount mAccount;
private ConnectionValidator mConnectionValidator; private ConnectionValidator mConnectionValidator;
private static Boolean mHoldRequests = false;
private SingleSessionManager mSingleSessionManager = null; private SingleSessionManager mSingleSessionManager = null;
private boolean mFollowRedirects; private boolean mFollowRedirects;
@ -109,7 +113,41 @@ public class OwnCloudClient extends HttpClient {
if (mCredentials.getHeaderAuth() != null && method.getRequestHeader(AUTHORIZATION_HEADER) == null) { if (mCredentials.getHeaderAuth() != null && method.getRequestHeader(AUTHORIZATION_HEADER) == null) {
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth()); method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
} }
status = method.execute(); synchronized (mHoldRequests) {
while (mHoldRequests) {
while (true) {
try {
((String) null).toString();
} catch (Exception e) {
Log.d("+++++++",
"HATL BEFORE" +
"\nThread: " + Thread.currentThread().getName() +
"\nobject: " + this.toString() +
"\nMethod: " + method.getHttpUrl() +
"\ntrace: " + ExceptionUtils.getStackTrace(e));
}
Thread.sleep(40000);
}
}
status = method.execute();
if (status == 302) {
mHoldRequests = true;
while (mHoldRequests) {
try {
((String) null).toString();
} catch (Exception e) {
Log.d("+++++++",
"HALT AFTER" +
"\nresponsecode: " + Integer.toString(status) +
"\nThread: " + Thread.currentThread().getName() +
"\nobject: " + this.toString() +
"\nMethod: " + method.getHttpUrl() +
"\ntrace: " + ExceptionUtils.getStackTrace(e));
}
Thread.sleep(40000);
}
}
}
if (mFollowRedirects) { if (mFollowRedirects) {
status = followRedirection(method).getLastStatus(); status = followRedirection(method).getLastStatus();
@ -171,7 +209,7 @@ public class OwnCloudClient extends HttpClient {
redirectionPath.addLocation(location); redirectionPath.addLocation(location);
// Release the connection to avoid reach the max number of connections per host // Release the connection to avoid reach the max number of connections per hostClientManager
// due to it will be set a different url // due to it will be set a different url
exhaustResponse(method.getResponseBodyAsStream()); exhaustResponse(method.getResponseBodyAsStream());