mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
make initial check with apm work though connection validator
This commit is contained in:
parent
7ccb86c153
commit
b2f6d7f3b1
@ -28,6 +28,7 @@ class ConnectionValidator (
|
||||
|
||||
client.credentials = baseClient.credentials
|
||||
while (validationRetryCount < 5) {
|
||||
Timber.d("+++++++++++++++++++++++++++++++++++++ validationRetryCout %d", validationRetryCount)
|
||||
var successCounter = 0
|
||||
var failCounter = 0
|
||||
|
||||
@ -38,6 +39,8 @@ class ConnectionValidator (
|
||||
failCounter++
|
||||
}
|
||||
|
||||
// Skip the part where we try to check if we can access the parts where we have to be logged in... if we are not logged in
|
||||
if(baseClient.credentials !is OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials) {
|
||||
client.setFollowRedirects(false)
|
||||
val contentReply = canAccessRootFolder(client)
|
||||
if (contentReply.httpCode == HttpConstants.HTTP_OK) {
|
||||
@ -52,6 +55,7 @@ class ConnectionValidator (
|
||||
triggerAuthRefresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (successCounter >= failCounter) {
|
||||
//update credentials in client
|
||||
return true
|
||||
@ -67,8 +71,10 @@ class ConnectionValidator (
|
||||
|
||||
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
|
||||
val reply = getOwnCloudStatus(client)
|
||||
return reply.httpCode == HttpConstants.HTTP_OK &&
|
||||
!reply.isException &&
|
||||
// dont check status code. It currently relais on the broken redirect code of the owncloud client
|
||||
// TODO: Use okhttp redirect and add this check again
|
||||
// return reply.httpCode == HttpConstants.HTTP_OK &&
|
||||
return !reply.isException &&
|
||||
reply.data != null
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,6 @@ public class OwnCloudClient extends HttpClient {
|
||||
}
|
||||
|
||||
status = method.execute();
|
||||
Timber.d("-------------------------------------");
|
||||
stacklog(status, method);
|
||||
|
||||
if (mConnectionValidator != null &&
|
||||
@ -163,7 +162,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
"\nobject: " + this.toString() +
|
||||
"\nMethod: " + method.toString() +
|
||||
"\nUrl: " + method.getHttpUrl() +
|
||||
"\nCookeis: " + getCookiesString() +
|
||||
"\nCookeis: " + getCookiesForBaseUri().toString() +
|
||||
"\ntrace: " + ExceptionUtils.getStackTrace(e) +
|
||||
"---------------------------");
|
||||
}
|
||||
@ -329,19 +328,6 @@ public class OwnCloudClient extends HttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
public String getCookiesString() {
|
||||
StringBuilder cookiesString = new StringBuilder();
|
||||
List<Cookie> cookieList = getCookiesForBaseUri();
|
||||
|
||||
if (cookieList != null) {
|
||||
for (Cookie cookie : cookieList) {
|
||||
cookiesString.append(cookie.toString()).append(";");
|
||||
}
|
||||
}
|
||||
|
||||
return cookiesString.toString();
|
||||
}
|
||||
|
||||
public void setCookiesForBaseUri(List<Cookie> cookies) {
|
||||
getOkHttpClient().cookieJar().saveFromResponse(
|
||||
HttpUrl.parse(mBaseUri.toString()),
|
||||
|
@ -57,6 +57,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public class HttpClient {
|
||||
private static OkHttpClient sOkHttpClient;
|
||||
private static Context sContext;
|
||||
private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>();
|
||||
private static LogInterceptor sLogInterceptor;
|
||||
private static Interceptor sDebugInterceptor;
|
||||
|
||||
@ -67,10 +68,11 @@ public class HttpClient {
|
||||
NetworkUtils.getKnownServersStore(sContext));
|
||||
final SSLSocketFactory sslSocketFactory = getNewSslSocketFactory(trustManager);
|
||||
// Automatic cookie handling, NOT PERSISTENT
|
||||
final CookieJar cookieJar = new CookieJarImpl(sCookieStore);
|
||||
|
||||
// TODO: Not verifying the hostname against certificate. ask owncloud security human if this is ok.
|
||||
//.hostnameVerifier(new BrowserCompatHostnameVerifier());
|
||||
sOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager);
|
||||
sOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager, cookieJar);
|
||||
|
||||
} catch (Exception e) {
|
||||
Timber.e(e, "Could not setup SSL system.");
|
||||
@ -107,7 +109,8 @@ public class HttpClient {
|
||||
return sslContext.getSocketFactory();
|
||||
}
|
||||
|
||||
private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager){
|
||||
private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager,
|
||||
CookieJar cookieJar) {
|
||||
return new OkHttpClient.Builder()
|
||||
.addNetworkInterceptor(getLogInterceptor())
|
||||
.addNetworkInterceptor(DebugInterceptorFactory.INSTANCE.getInterceptor())
|
||||
@ -118,6 +121,7 @@ public class HttpClient {
|
||||
.followRedirects(false)
|
||||
.sslSocketFactory(sslSocketFactory, trustManager)
|
||||
.hostnameVerifier((asdf, usdf) -> true)
|
||||
.cookieJar(cookieJar)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user