|
7 | 7 | */ |
8 | 8 | package com.owncloud.android.lib.resources.users; |
9 | 9 |
|
10 | | -import com.owncloud.android.lib.common.OwnCloudClient; |
| 10 | +import com.google.gson.Gson; |
| 11 | +import com.nextcloud.common.NextcloudClient; |
| 12 | +import com.nextcloud.operations.PostMethod; |
11 | 13 | import com.owncloud.android.lib.common.operations.RemoteOperation; |
12 | 14 | import com.owncloud.android.lib.common.operations.RemoteOperationResult; |
13 | 15 | import com.owncloud.android.lib.common.utils.Log_OC; |
14 | 16 |
|
15 | 17 | import org.apache.commons.httpclient.HttpStatus; |
16 | | -import org.apache.commons.httpclient.methods.Utf8PostMethod; |
17 | 18 | import org.json.JSONObject; |
18 | 19 |
|
| 20 | +import java.util.HashMap; |
| 21 | + |
| 22 | +import okhttp3.MediaType; |
| 23 | +import okhttp3.RequestBody; |
| 24 | + |
19 | 25 |
|
20 | 26 | /** |
21 | 27 | * Remote operation performing check if app token is scheduled for remote wipe |
22 | 28 | */ |
23 | 29 |
|
24 | | -public class CheckRemoteWipeRemoteOperation extends RemoteOperation { |
| 30 | +public class CheckRemoteWipeRemoteOperation extends RemoteOperation<Void> { |
25 | 31 |
|
26 | 32 | private static final String TAG = CheckRemoteWipeRemoteOperation.class.getSimpleName(); |
27 | | - private static final int SYNC_READ_TIMEOUT = 40000; |
28 | | - private static final int SYNC_CONNECTION_TIMEOUT = 5000; |
29 | 33 | private static final String REMOTE_WIPE_URL = "/index.php/core/wipe/check"; |
30 | 34 |
|
31 | 35 | // JSON node names |
32 | 36 | private static final String WIPE = "wipe"; |
33 | 37 |
|
| 38 | + private String authToken; |
| 39 | + |
| 40 | + public CheckRemoteWipeRemoteOperation(String authToken) { |
| 41 | + this.authToken = authToken; |
| 42 | + } |
| 43 | + |
34 | 44 | /** |
35 | 45 | * @param client Client object |
36 | 46 | */ |
37 | 47 | @Override |
38 | | - protected RemoteOperationResult run(OwnCloudClient client) { |
39 | | - Utf8PostMethod postMethod = null; |
40 | | - RemoteOperationResult result; |
| 48 | + public RemoteOperationResult<Void> run(NextcloudClient client) { |
| 49 | + PostMethod postMethod = null; |
| 50 | + RemoteOperationResult<Void> result; |
41 | 51 |
|
42 | 52 | try { |
43 | | - postMethod = new Utf8PostMethod(client.getBaseUri() + REMOTE_WIPE_URL + JSON_FORMAT); |
| 53 | + HashMap<String, String> map = new HashMap<>(); |
| 54 | + map.put(REMOTE_WIPE_TOKEN, authToken); |
| 55 | + |
| 56 | + String jsonString = new Gson().toJson(map); |
| 57 | + |
| 58 | + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonString); |
| 59 | + postMethod = new PostMethod(client.getBaseUri() + REMOTE_WIPE_URL + JSON_FORMAT, true, requestBody); |
44 | 60 | postMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED); |
45 | | - postMethod.setParameter(REMOTE_WIPE_TOKEN, client.getCredentials().getAuthToken()); |
46 | 61 |
|
47 | | - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); |
| 62 | + int status = client.execute(postMethod); |
48 | 63 |
|
49 | 64 | if (HttpStatus.SC_OK == status) { |
50 | 65 | String response = postMethod.getResponseBodyAsString(); |
51 | 66 |
|
52 | 67 | JSONObject json = new JSONObject(response); |
53 | 68 |
|
54 | 69 | if (json.getBoolean(WIPE)) { |
55 | | - result = new RemoteOperationResult(true, postMethod); |
| 70 | + result = new RemoteOperationResult<>(true, postMethod); |
56 | 71 | } else { |
57 | | - result = new RemoteOperationResult(false, postMethod); |
| 72 | + result = new RemoteOperationResult<>(false, postMethod); |
58 | 73 | } |
59 | 74 | } else { |
60 | | - result = new RemoteOperationResult(false, postMethod); |
| 75 | + result = new RemoteOperationResult<>(false, postMethod); |
61 | 76 | } |
62 | | - |
63 | | - client.exhaustResponse(postMethod.getResponseBodyAsStream()); |
64 | 77 | } catch (Exception e) { |
65 | | - result = new RemoteOperationResult(e); |
| 78 | + result = new RemoteOperationResult<>(e); |
66 | 79 | Log_OC.e(TAG, |
67 | | - "Getting remote wipe status failed: " + result.getLogMessage(), |
68 | | - result.getException()); |
| 80 | + "Getting remote wipe status failed: " + result.getLogMessage(), |
| 81 | + result.getException()); |
69 | 82 | } finally { |
70 | 83 | if (postMethod != null) { |
71 | 84 | postMethod.releaseConnection(); |
|
0 commit comments