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

Merge pull request #195 from owncloud/feature/request_id

Use UUID v4 to represent request ids and log it
This commit is contained in:
David González Verdugo 2018-10-22 14:42:43 +02:00 committed by GitHub
commit 9526038503
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 9 deletions

View File

@ -29,7 +29,6 @@ import android.accounts.AccountManager;
import android.accounts.AccountsException;
import android.net.Uri;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials;
@ -116,22 +115,16 @@ public class OwnCloudClient extends HttpClient {
}
public int executeHttpMethod (HttpBaseMethod method) throws Exception {
boolean repeatWithFreshCredentials;
int repeatCounter = 0;
int status;
do {
// Clean previous request id. This is a bit hacky but is the only way to add request headers in WebDAV
// methods by using Dav4Android
deleteHeaderForAllRequests(OC_X_REQUEST_ID);
// Header to allow tracing requests in apache and ownCloud logs
addHeaderForAllRequests(OC_X_REQUEST_ID,
RandomUtils.generateRandomString(RandomUtils.generateRandomInteger(20, 200)));
setRequestId(method);
status = method.execute();
checkFirstRedirection(method);
if(mFollowRedirects && !isIdPRedirection()) {
status = followRedirection(method).getLastStatus();
}
@ -158,6 +151,8 @@ public class OwnCloudClient extends HttpClient {
int status;
do {
setRequestId(method);
status = method.execute();
repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter);
@ -169,6 +164,19 @@ public class OwnCloudClient extends HttpClient {
return status;
}
private void setRequestId(HttpBaseMethod method) {
// Clean previous request id. This is a bit hacky but is the only way to add request headers in WebDAV
// methods by using Dav4Android
deleteHeaderForAllRequests(OC_X_REQUEST_ID);
String requestId = RandomUtils.generateRandomUUID();
// Header to allow tracing requests in apache and ownCloud logs
addHeaderForAllRequests(OC_X_REQUEST_ID, RandomUtils.generateRandomUUID());
Log_OC.d(TAG, "Executing " + method.getClass().getSimpleName() + " in request with id " + requestId);
}
public RedirectionPath followRedirection(HttpBaseMethod method) throws Exception {
int redirectionsCount = 0;
int status = method.getStatusCode();

View File

@ -25,6 +25,7 @@
package com.owncloud.android.lib.common.utils;
import java.util.Random;
import java.util.UUID;
/**
* Class with methods to generate random values
@ -60,4 +61,11 @@ public class RandomUtils {
Random r = new Random();
return r.nextInt(max-min) + min;
}
/**
* @return random UUID
*/
public static String generateRandomUUID() {
return UUID.randomUUID().toString();
}
}