7
7
*/
8
8
package com .owncloud .android .lib .resources .e2ee ;
9
9
10
- import com .owncloud .android .lib .common .OwnCloudClient ;
10
+ import com .nextcloud .common .NextcloudClient ;
11
+ import com .nextcloud .operations .GetMethod ;
11
12
import com .owncloud .android .lib .common .operations .RemoteOperation ;
12
13
import com .owncloud .android .lib .common .operations .RemoteOperationResult ;
13
14
import com .owncloud .android .lib .common .utils .Log_OC ;
14
15
15
- import org .apache .commons .httpclient .Header ;
16
16
import org .apache .commons .httpclient .HttpStatus ;
17
- import org .apache .commons .httpclient .methods .GetMethod ;
18
17
import org .json .JSONObject ;
19
18
20
19
25
24
public class GetMetadataRemoteOperation extends RemoteOperation <MetadataResponse > {
26
25
27
26
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 ;
30
27
private static final String METADATA_V1_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/meta-data/" ;
31
28
private static final String METADATA_V2_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/" ;
32
29
@@ -49,32 +46,29 @@ public GetMetadataRemoteOperation(long fileId) {
49
46
* @param client Client object
50
47
*/
51
48
@ 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 ;
54
51
RemoteOperationResult <MetadataResponse > result ;
55
52
56
53
try {
57
54
// 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 );
60
56
61
- int status = client .executeMethod (getMethod , SYNC_READ_TIMEOUT , SYNC_CONNECTION_TIMEOUT );
57
+ int status = client .execute (getMethod );
62
58
63
59
if (status == HttpStatus .SC_NOT_FOUND || status == HttpStatus .SC_INTERNAL_SERVER_ERROR ) {
64
60
// 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 );
67
62
68
- status = client .executeMethod (getMethod , SYNC_READ_TIMEOUT , SYNC_CONNECTION_TIMEOUT );
63
+ status = client .execute (getMethod );
69
64
}
70
65
71
66
if (status == HttpStatus .SC_OK ) {
72
67
String response = getMethod .getResponseBodyAsString ();
73
- Header signatureHeader = getMethod .getResponseHeader (HEADER_SIGNATURE );
68
+ String signature = getMethod .getResponseHeader (HEADER_SIGNATURE );
74
69
75
- String signature = "" ;
76
- if (signatureHeader != null ) {
77
- signature = signatureHeader .getValue ();
70
+ if (signature == null ) {
71
+ signature = "" ;
78
72
}
79
73
80
74
// Parse the response
@@ -90,7 +84,6 @@ protected RemoteOperationResult<MetadataResponse> run(OwnCloudClient client) {
90
84
result .setResultData (metadataResponse );
91
85
} else {
92
86
result = new RemoteOperationResult <>(false , getMethod );
93
- client .exhaustResponse (getMethod .getResponseBodyAsStream ());
94
87
}
95
88
} catch (Exception e ) {
96
89
result = new RemoteOperationResult <>(e );
0 commit comments