From 83f24f0e23b68ef23b6d12ec54aaba051df63d72 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 21 Apr 2022 12:04:33 +0200 Subject: [PATCH 1/2] Update UploadFileRemoteOperation.java to get access to etag from response header - Add a private static final value which is the response header's name for etag. - update 'RemoteOperationResult uploadFile(OwnCloudClient client)' to check for this header, and set value as RemoteOperationResult's data. Signed-off-by: vincent Bourgmayer --- .../lib/resources/files/UploadFileRemoteOperation.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java index 7cce0de9f..9084b2d84 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java @@ -35,6 +35,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; +import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.RequestEntity; @@ -56,6 +57,7 @@ public class UploadFileRemoteOperation extends RemoteOperation { private static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; private static final String IF_MATCH_HEADER = "If-Match"; + protected static final String RESULT_ETAG_HEADER = "etag"; protected static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; protected static final String OC_X_OC_CTIME_HEADER = "X-OC-Ctime"; @@ -232,6 +234,11 @@ protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOExcep result = new RemoteOperationResult(isSuccess(status), putMethod); + final Header resultEtagHeader = putMethod.getResponseHeader(RESULT_ETAG_HEADER); + if (resultEtagHeader != null) { + result.setResultData(resultEtagHeader.getValue()); + } + client.exhaustResponse(putMethod.getResponseBodyAsStream()); } finally { From 01f0cb28158241fdf532097d3c518cf2f236ea2e Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 22 Apr 2022 13:49:21 +0200 Subject: [PATCH 2/2] UploadFileRemoteOperation extends RemoteOperation instead of raw type Signed-off-by: vincent Bourgmayer --- .../files/UploadFileRemoteOperation.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java index 9084b2d84..da1bc0b7c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java @@ -54,7 +54,7 @@ * @author masensio */ -public class UploadFileRemoteOperation extends RemoteOperation { +public class UploadFileRemoteOperation extends RemoteOperation { private static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; private static final String IF_MATCH_HEADER = "If-Match"; protected static final String RESULT_ETAG_HEADER = "etag"; @@ -157,8 +157,8 @@ public UploadFileRemoteOperation(String localPath, } @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result; DefaultHttpMethodRetryHandler oldRetryHandler = (DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER); @@ -177,7 +177,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { if (cancellationRequested.get()) { // the operation was cancelled before getting it's turn to be executed in the queue of uploads - result = new RemoteOperationResult(new OperationCancelledException()); + result = new RemoteOperationResult<>(new OperationCancelledException()); } else { // perform the upload @@ -187,12 +187,12 @@ protected RemoteOperationResult run(OwnCloudClient client) { } catch (Exception e) { if (putMethod != null && putMethod.isAborted()) { if (cancellationRequested.get() && cancellationReason != null) { - result = new RemoteOperationResult(cancellationReason); + result = new RemoteOperationResult<>(cancellationReason); } else { - result = new RemoteOperationResult(new OperationCancelledException()); + result = new RemoteOperationResult<>(new OperationCancelledException()); } } else { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); } } finally { if (disableRetries) { @@ -208,9 +208,9 @@ public boolean isSuccess(int status) { status == HttpStatus.SC_NO_CONTENT)); } - protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { + protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { int status; - RemoteOperationResult result; + RemoteOperationResult result; try { File f = new File(localPath); @@ -232,7 +232,7 @@ protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOExcep putMethod.setRequestEntity(entity); status = client.executeMethod(putMethod); - result = new RemoteOperationResult(isSuccess(status), putMethod); + result = new RemoteOperationResult<>(isSuccess(status), putMethod); final Header resultEtagHeader = putMethod.getResponseHeader(RESULT_ETAG_HEADER); if (resultEtagHeader != null) {