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:
commit
9526038503
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user