|
28 | 28 | import android.accounts.AccountManager;
|
29 | 29 | import android.accounts.AccountsException;
|
30 | 30 | import android.net.Uri;
|
| 31 | +import android.util.Log; |
31 | 32 |
|
32 | 33 | import at.bitfire.dav4jvm.exception.HttpException;
|
33 | 34 | import com.owncloud.android.lib.common.accounts.AccountUtils;
|
|
42 | 43 | import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
43 | 44 | import okhttp3.Cookie;
|
44 | 45 | import okhttp3.HttpUrl;
|
| 46 | +import org.apache.commons.lang3.exception.ExceptionUtils; |
45 | 47 | import timber.log.Timber;
|
46 | 48 |
|
47 | 49 | import java.io.IOException;
|
@@ -69,6 +71,8 @@ public class OwnCloudClient extends HttpClient {
|
69 | 71 | private OwnCloudAccount mAccount;
|
70 | 72 | private ConnectionValidator mConnectionValidator;
|
71 | 73 |
|
| 74 | + private static Boolean mHoldRequests = false; |
| 75 | + |
72 | 76 | private SingleSessionManager mSingleSessionManager = null;
|
73 | 77 |
|
74 | 78 | private boolean mFollowRedirects;
|
@@ -109,7 +113,41 @@ public int executeHttpMethod(HttpBaseMethod method) throws Exception {
|
109 | 113 | if (mCredentials.getHeaderAuth() != null && method.getRequestHeader(AUTHORIZATION_HEADER) == null) {
|
110 | 114 | method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
|
111 | 115 | }
|
112 |
| - status = method.execute(); |
| 116 | + synchronized (mHoldRequests) { |
| 117 | + while (mHoldRequests) { |
| 118 | + while (true) { |
| 119 | + try { |
| 120 | + ((String) null).toString(); |
| 121 | + } catch (Exception e) { |
| 122 | + Log.d("+++++++", |
| 123 | + "HATL BEFORE" + |
| 124 | + "\nThread: " + Thread.currentThread().getName() + |
| 125 | + "\nobject: " + this.toString() + |
| 126 | + "\nMethod: " + method.getHttpUrl() + |
| 127 | + "\ntrace: " + ExceptionUtils.getStackTrace(e)); |
| 128 | + } |
| 129 | + Thread.sleep(40000); |
| 130 | + } |
| 131 | + } |
| 132 | + status = method.execute(); |
| 133 | + if (status == 302) { |
| 134 | + mHoldRequests = true; |
| 135 | + while (mHoldRequests) { |
| 136 | + try { |
| 137 | + ((String) null).toString(); |
| 138 | + } catch (Exception e) { |
| 139 | + Log.d("+++++++", |
| 140 | + "HALT AFTER" + |
| 141 | + "\nresponsecode: " + Integer.toString(status) + |
| 142 | + "\nThread: " + Thread.currentThread().getName() + |
| 143 | + "\nobject: " + this.toString() + |
| 144 | + "\nMethod: " + method.getHttpUrl() + |
| 145 | + "\ntrace: " + ExceptionUtils.getStackTrace(e)); |
| 146 | + } |
| 147 | + Thread.sleep(40000); |
| 148 | + } |
| 149 | + } |
| 150 | + } |
113 | 151 |
|
114 | 152 | if (mFollowRedirects) {
|
115 | 153 | status = followRedirection(method).getLastStatus();
|
@@ -171,7 +209,7 @@ public RedirectionPath followRedirection(HttpBaseMethod method) throws Exception
|
171 | 209 |
|
172 | 210 | redirectionPath.addLocation(location);
|
173 | 211 |
|
174 |
| - // Release the connection to avoid reach the max number of connections per host |
| 212 | + // Release the connection to avoid reach the max number of connections per hostClientManager |
175 | 213 | // due to it will be set a different url
|
176 | 214 | exhaustResponse(method.getResponseBodyAsStream());
|
177 | 215 |
|
|
0 commit comments