Skip to content

Commit 2601614

Browse files
ZetaTomtobiasKaminsky
authored andcommitted
WIP
Signed-off-by: ZetaTom <[email protected]>
1 parent 434642f commit 2601614

File tree

3 files changed

+27
-40
lines changed

3 files changed

+27
-40
lines changed

library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
*/
88
package com.owncloud.android.lib.resources.e2ee;
99

10-
import com.owncloud.android.lib.common.OwnCloudClient;
10+
import com.nextcloud.common.NextcloudClient;
11+
import com.nextcloud.operations.GetMethod;
1112
import com.owncloud.android.lib.common.operations.RemoteOperation;
1213
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
1314
import com.owncloud.android.lib.common.utils.Log_OC;
1415

15-
import org.apache.commons.httpclient.Header;
1616
import org.apache.commons.httpclient.HttpStatus;
17-
import org.apache.commons.httpclient.methods.GetMethod;
1817
import org.json.JSONObject;
1918

2019

@@ -25,8 +24,6 @@
2524
public class GetMetadataRemoteOperation extends RemoteOperation<MetadataResponse> {
2625

2726
private static final String TAG = GetMetadataRemoteOperation.class.getSimpleName();
28-
private static final int SYNC_READ_TIMEOUT = 40000;
29-
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
3027
private static final String METADATA_V1_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/meta-data/";
3128
private static final String METADATA_V2_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/";
3229

@@ -49,32 +46,29 @@ public GetMetadataRemoteOperation(long fileId) {
4946
* @param client Client object
5047
*/
5148
@Override
52-
protected RemoteOperationResult<MetadataResponse> run(OwnCloudClient client) {
53-
GetMethod getMethod = null;
49+
public RemoteOperationResult<MetadataResponse> run(NextcloudClient client) {
50+
com.nextcloud.operations.GetMethod getMethod = null;
5451
RemoteOperationResult<MetadataResponse> result;
5552

5653
try {
5754
// remote request
58-
getMethod = new GetMethod(client.getBaseUri() + METADATA_V2_URL + fileId + JSON_FORMAT);
59-
getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
55+
getMethod = new com.nextcloud.operations.GetMethod(client.getBaseUri() + METADATA_V2_URL + fileId + JSON_FORMAT, true);
6056

61-
int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
57+
int status = client.execute(getMethod);
6258

6359
if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
6460
// retry with v1
65-
getMethod = new GetMethod(client.getBaseUri() + METADATA_V1_URL + fileId + JSON_FORMAT);
66-
getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
61+
getMethod = new GetMethod(client.getBaseUri() + METADATA_V1_URL + fileId + JSON_FORMAT, true);
6762

68-
status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
63+
status = client.execute(getMethod);
6964
}
7065

7166
if (status == HttpStatus.SC_OK) {
7267
String response = getMethod.getResponseBodyAsString();
73-
Header signatureHeader = getMethod.getResponseHeader(HEADER_SIGNATURE);
68+
String signature = getMethod.getResponseHeader(HEADER_SIGNATURE);
7469

75-
String signature = "";
76-
if (signatureHeader != null) {
77-
signature = signatureHeader.getValue();
70+
if (signature == null) {
71+
signature = "";
7872
}
7973

8074
// Parse the response
@@ -90,7 +84,6 @@ protected RemoteOperationResult<MetadataResponse> run(OwnCloudClient client) {
9084
result.setResultData(metadataResponse);
9185
} else {
9286
result = new RemoteOperationResult<>(false, getMethod);
93-
client.exhaustResponse(getMethod.getResponseBodyAsStream());
9487
}
9588
} catch (Exception e) {
9689
result = new RemoteOperationResult<>(e);

library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
*/
88
package com.owncloud.android.lib.resources.e2ee;
99

10-
import com.owncloud.android.lib.common.OwnCloudClient;
10+
import com.nextcloud.common.NextcloudClient;
11+
import com.nextcloud.operations.PostMethod;
1112
import com.owncloud.android.lib.common.operations.RemoteOperation;
1213
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
1314
import com.owncloud.android.lib.common.utils.Log_OC;
1415

1516
import org.apache.commons.httpclient.HttpStatus;
16-
import org.apache.commons.httpclient.methods.Utf8PostMethod;
1717
import org.json.JSONObject;
1818

19+
import okhttp3.RequestBody;
20+
1921

2022
/**
2123
* Lock a file
2224
*/
2325
public class LockFileRemoteOperation extends RemoteOperation<String> {
2426

2527
private static final String TAG = LockFileRemoteOperation.class.getSimpleName();
26-
private static final int SYNC_READ_TIMEOUT = 40000;
27-
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
2828
private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/";
2929

3030
private static final String COUNTER_HEADER = "X-NC-E2EE-COUNTER";
@@ -52,22 +52,22 @@ public LockFileRemoteOperation(long localId) {
5252
* @param client Client object
5353
*/
5454
@Override
55-
protected RemoteOperationResult<String> run(OwnCloudClient client) {
55+
public RemoteOperationResult<String> run(NextcloudClient client) {
5656
RemoteOperationResult<String> result;
57-
Utf8PostMethod postMethod = null;
57+
PostMethod postMethod = null;
5858

5959
try {
60-
postMethod = new Utf8PostMethod(client.getBaseUri() + LOCK_FILE_URL + localId + JSON_FORMAT);
60+
RequestBody requestBody = RequestBody.create(new byte[] {});
61+
62+
postMethod = new PostMethod(client.getBaseUri() + LOCK_FILE_URL + localId + JSON_FORMAT, true, requestBody);
6163

62-
// remote request
63-
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
6464
postMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED);
6565

6666
if (counter > 0) {
6767
postMethod.addRequestHeader(COUNTER_HEADER, String.valueOf(counter));
6868
}
6969

70-
int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
70+
int status = client.execute(postMethod);
7171

7272
if (status == HttpStatus.SC_OK) {
7373
String response = postMethod.getResponseBodyAsString();
@@ -83,7 +83,6 @@ protected RemoteOperationResult<String> run(OwnCloudClient client) {
8383
result.setResultData(token);
8484
} else {
8585
result = new RemoteOperationResult<>(false, postMethod);
86-
client.exhaustResponse(postMethod.getResponseBodyAsStream());
8786
}
8887
} catch (Exception e) {
8988
result = new RemoteOperationResult<>(e);

library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
*/
88
package com.owncloud.android.lib.resources.e2ee;
99

10-
import com.owncloud.android.lib.common.OwnCloudClient;
10+
import com.nextcloud.common.NextcloudClient;
11+
import com.nextcloud.operations.DeleteMethod;
1112
import com.owncloud.android.lib.common.operations.RemoteOperation;
1213
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
1314
import com.owncloud.android.lib.common.utils.Log_OC;
1415

1516
import org.apache.commons.httpclient.HttpStatus;
16-
import org.apache.commons.httpclient.methods.DeleteMethod;
1717

1818

1919
/**
@@ -22,8 +22,6 @@
2222
public class UnlockFileRemoteOperation extends RemoteOperation<Void> {
2323

2424
private static final String TAG = UnlockFileRemoteOperation.class.getSimpleName();
25-
private static final int SYNC_READ_TIMEOUT = 40000;
26-
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
2725
private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/lock/";
2826

2927
private final long localId;
@@ -41,22 +39,19 @@ public UnlockFileRemoteOperation(long localId, String token) {
4139
* @param client Client object
4240
*/
4341
@Override
44-
protected RemoteOperationResult<Void> run(OwnCloudClient client) {
42+
public RemoteOperationResult<Void> run(NextcloudClient client) {
4543
RemoteOperationResult<Void> result;
46-
DeleteMethod deleteMethod = null;
44+
com.nextcloud.operations.DeleteMethod deleteMethod = null;
4745

4846
try {
4947
// remote request
50-
deleteMethod = new DeleteMethod(client.getBaseUri() + LOCK_FILE_URL + localId);
51-
deleteMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
48+
deleteMethod = new DeleteMethod(client.getBaseUri() + LOCK_FILE_URL + localId, true);
5249
deleteMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED);
5350
deleteMethod.addRequestHeader(E2E_TOKEN, token);
5451

55-
int status = client.executeMethod(deleteMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
52+
int status = client.execute(deleteMethod);
5653

5754
result = new RemoteOperationResult<>(status == HttpStatus.SC_OK, deleteMethod);
58-
59-
client.exhaustResponse(deleteMethod.getResponseBodyAsStream());
6055
} catch (Exception e) {
6156
result = new RemoteOperationResult<>(e);
6257
Log_OC.e(TAG, "Unlock file with id " + localId + " failed: " + result.getLogMessage(),

0 commit comments

Comments
 (0)