mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +00:00 
			
		
		
		
	Retry uploads
This commit is contained in:
		
							parent
							
								
									c2bdea1c91
								
							
						
					
					
						commit
						d013d93ac9
					
				| @ -1 +1 @@ | ||||
| Subproject commit fab24c4727d4a201cbb0bb1e7f2f45bc5b5e0756 | ||||
| Subproject commit d519949bcc53896becb7ad92bc643938f189d04e | ||||
| @ -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); | ||||
|  | ||||
| @ -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(); | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user