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