diff --git a/dav4android b/dav4android index fab24c47..d519949b 160000 --- a/dav4android +++ b/dav4android @@ -1 +1 @@ -Subproject commit fab24c4727d4a201cbb0bb1e7f2f45bc5b5e0756 +Subproject commit d519949bcc53896becb7ad92bc643938f189d04e diff --git a/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java b/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java index 1d6cdff6..811194bf 100644 --- a/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java @@ -60,6 +60,7 @@ public abstract class HttpBaseMethod { .build(); } + // Connection parameters public void setReadTimeout(long readTimeout, TimeUnit timeUnit) { mOkHttpClient = mOkHttpClient.newBuilder() .readTimeout(readTimeout, timeUnit) @@ -78,6 +79,16 @@ public abstract class HttpBaseMethod { .build(); } + public void setRetryOnConnectionFailure(boolean retryOnConnectionFailure) { + mOkHttpClient = mOkHttpClient.newBuilder() + .retryOnConnectionFailure(retryOnConnectionFailure) + .build(); + } + + public boolean getRetryOnConnectionFailure() { + return mOkHttpClient.retryOnConnectionFailure(); + } + // Request public String getRequestHeader(String name) { return mRequest.header(name); diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java index c9c8c00a..7d7d9e6d 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java @@ -26,6 +26,8 @@ package com.owncloud.android.lib.common.http.methods.webdav; import com.owncloud.android.lib.common.http.methods.HttpBaseMethod; +import java.util.concurrent.TimeUnit; + import at.bitfire.dav4android.DavOCResource; import at.bitfire.dav4android.DavResource; import okhttp3.HttpUrl; @@ -59,4 +61,14 @@ public abstract class DavMethod extends HttpBaseMethod { public boolean isAborted() { return mDavResource.isCallAborted(); } + + @Override + public void setRetryOnConnectionFailure(boolean retryOnConnectionFailure) { + mDavResource.setRetryOnConnectionFailure(retryOnConnectionFailure); + } + + @Override + public boolean getRetryOnConnectionFailure() { + return mDavResource.isRetryOnConnectionFailure(); + } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 6683af46..3fbd1119 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -34,6 +34,7 @@ import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.OperationCancelledException; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.utils.Log_OC; import java.io.File; import java.util.HashSet; @@ -86,20 +87,12 @@ public class UploadRemoteFileOperation extends RemoteOperation { protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; -// DefaultHttpMethodRetryHandler oldRetryHandler = -// (DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER); - try { - // TODO - // prevent that uploads are retried automatically by network library -// client.getParams().setParameter( -// HttpMethodParams.RETRY_HANDLER, -// new DefaultHttpMethodRetryHandler(0, false) -// ); - mPutMethod = new PutMethod( HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath))); + mPutMethod.setRetryOnConnectionFailure(false); + if (mCancellationRequested.get()) { // the operation was cancelled before getting it's turn to be executed in the queue of uploads result = new RemoteOperationResult(new OperationCancelledException()); @@ -107,22 +100,23 @@ public class UploadRemoteFileOperation extends RemoteOperation { } else { // perform the upload result = uploadFile(client); + Log_OC.i(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " + + result.getLogMessage()); } } catch (Exception e) { + if (mPutMethod != null && mPutMethod.isAborted()) { result = new RemoteOperationResult(new OperationCancelledException()); + Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " + + result.getLogMessage(), new OperationCancelledException()); } else { result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " + + result.getLogMessage(), e); } - } finally { - // TODO - // reset previous retry handler -// client.getParams().setParameter( -// HttpMethodParams.RETRY_HANDLER, -// oldRetryHandler -// ); } + return result; }