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
@ -14,7 +14,7 @@ import java.lang.Exception
|
|||||||
|
|
||||||
class ConnectionValidator (
|
class ConnectionValidator (
|
||||||
val clearCookiesOnValidation: Boolean
|
val clearCookiesOnValidation: Boolean
|
||||||
){
|
){
|
||||||
|
|
||||||
fun validate(baseClient: OwnCloudClient): Boolean {
|
fun validate(baseClient: OwnCloudClient): Boolean {
|
||||||
try {
|
try {
|
||||||
@ -28,6 +28,7 @@ class ConnectionValidator (
|
|||||||
|
|
||||||
client.credentials = baseClient.credentials
|
client.credentials = baseClient.credentials
|
||||||
while (validationRetryCount < 5) {
|
while (validationRetryCount < 5) {
|
||||||
|
Timber.d("+++++++++++++++++++++++++++++++++++++ validationRetryCout %d", validationRetryCount)
|
||||||
var successCounter = 0
|
var successCounter = 0
|
||||||
var failCounter = 0
|
var failCounter = 0
|
||||||
|
|
||||||
@ -38,21 +39,24 @@ class ConnectionValidator (
|
|||||||
failCounter++
|
failCounter++
|
||||||
}
|
}
|
||||||
|
|
||||||
client.setFollowRedirects(false)
|
// 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
|
||||||
val contentReply = canAccessRootFolder(client)
|
if(baseClient.credentials !is OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials) {
|
||||||
if (contentReply.httpCode == HttpConstants.HTTP_OK) {
|
client.setFollowRedirects(false)
|
||||||
if (contentReply.data == true) { //if data is true it means that the content reply was ok
|
val contentReply = canAccessRootFolder(client)
|
||||||
successCounter++
|
if (contentReply.httpCode == HttpConstants.HTTP_OK) {
|
||||||
|
if (contentReply.data == true) { //if data is true it means that the content reply was ok
|
||||||
|
successCounter++
|
||||||
|
} else {
|
||||||
|
failCounter++
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
failCounter++
|
failCounter++
|
||||||
}
|
if (contentReply.hashCode() == HttpConstants.HTTP_UNAUTHORIZED) {
|
||||||
} else {
|
triggerAuthRefresh()
|
||||||
failCounter++
|
}
|
||||||
if (contentReply.hashCode() == HttpConstants.HTTP_UNAUTHORIZED) {
|
|
||||||
triggerAuthRefresh()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(successCounter >= failCounter) {
|
if (successCounter >= failCounter) {
|
||||||
//update credentials in client
|
//update credentials in client
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -67,8 +71,10 @@ class ConnectionValidator (
|
|||||||
|
|
||||||
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
|
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
|
||||||
val reply = getOwnCloudStatus(client)
|
val reply = getOwnCloudStatus(client)
|
||||||
return reply.httpCode == HttpConstants.HTTP_OK &&
|
// dont check status code. It currently relais on the broken redirect code of the owncloud client
|
||||||
!reply.isException &&
|
// TODO: Use okhttp redirect and add this check again
|
||||||
|
// return reply.httpCode == HttpConstants.HTTP_OK &&
|
||||||
|
return !reply.isException &&
|
||||||
reply.data != null
|
reply.data != null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,6 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
status = method.execute();
|
status = method.execute();
|
||||||
Timber.d("-------------------------------------");
|
|
||||||
stacklog(status, method);
|
stacklog(status, method);
|
||||||
|
|
||||||
if (mConnectionValidator != null &&
|
if (mConnectionValidator != null &&
|
||||||
@ -163,7 +162,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
"\nobject: " + this.toString() +
|
"\nobject: " + this.toString() +
|
||||||
"\nMethod: " + method.toString() +
|
"\nMethod: " + method.toString() +
|
||||||
"\nUrl: " + method.getHttpUrl() +
|
"\nUrl: " + method.getHttpUrl() +
|
||||||
"\nCookeis: " + getCookiesString() +
|
"\nCookeis: " + getCookiesForBaseUri().toString() +
|
||||||
"\ntrace: " + ExceptionUtils.getStackTrace(e) +
|
"\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) {
|
public void setCookiesForBaseUri(List<Cookie> cookies) {
|
||||||
getOkHttpClient().cookieJar().saveFromResponse(
|
getOkHttpClient().cookieJar().saveFromResponse(
|
||||||
HttpUrl.parse(mBaseUri.toString()),
|
HttpUrl.parse(mBaseUri.toString()),
|
||||||
|
@ -57,6 +57,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class HttpClient {
|
public class HttpClient {
|
||||||
private static OkHttpClient sOkHttpClient;
|
private static OkHttpClient sOkHttpClient;
|
||||||
private static Context sContext;
|
private static Context sContext;
|
||||||
|
private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>();
|
||||||
private static LogInterceptor sLogInterceptor;
|
private static LogInterceptor sLogInterceptor;
|
||||||
private static Interceptor sDebugInterceptor;
|
private static Interceptor sDebugInterceptor;
|
||||||
|
|
||||||
@ -67,10 +68,11 @@ public class HttpClient {
|
|||||||
NetworkUtils.getKnownServersStore(sContext));
|
NetworkUtils.getKnownServersStore(sContext));
|
||||||
final SSLSocketFactory sslSocketFactory = getNewSslSocketFactory(trustManager);
|
final SSLSocketFactory sslSocketFactory = getNewSslSocketFactory(trustManager);
|
||||||
// Automatic cookie handling, NOT PERSISTENT
|
// 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.
|
// TODO: Not verifying the hostname against certificate. ask owncloud security human if this is ok.
|
||||||
//.hostnameVerifier(new BrowserCompatHostnameVerifier());
|
//.hostnameVerifier(new BrowserCompatHostnameVerifier());
|
||||||
sOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager);
|
sOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager, cookieJar);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Timber.e(e, "Could not setup SSL system.");
|
Timber.e(e, "Could not setup SSL system.");
|
||||||
@ -107,7 +109,8 @@ public class HttpClient {
|
|||||||
return sslContext.getSocketFactory();
|
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()
|
return new OkHttpClient.Builder()
|
||||||
.addNetworkInterceptor(getLogInterceptor())
|
.addNetworkInterceptor(getLogInterceptor())
|
||||||
.addNetworkInterceptor(DebugInterceptorFactory.INSTANCE.getInterceptor())
|
.addNetworkInterceptor(DebugInterceptorFactory.INSTANCE.getInterceptor())
|
||||||
@ -118,6 +121,7 @@ public class HttpClient {
|
|||||||
.followRedirects(false)
|
.followRedirects(false)
|
||||||
.sslSocketFactory(sslSocketFactory, trustManager)
|
.sslSocketFactory(sslSocketFactory, trustManager)
|
||||||
.hostnameVerifier((asdf, usdf) -> true)
|
.hostnameVerifier((asdf, usdf) -> true)
|
||||||
|
.cookieJar(cookieJar)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user