diff --git a/dav4android b/dav4android index 1108048f..c6c06a14 160000 --- a/dav4android +++ b/dav4android @@ -1 +1 @@ -Subproject commit 1108048f1a2ff12103cdf6a95307a314d621c088 +Subproject commit c6c06a144a1eaf3a75035dfe8700c42b86b0d223 diff --git a/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java b/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java index c8f1dfa9..72e61460 100644 --- a/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java +++ b/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java @@ -174,7 +174,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, }); }).start(); // ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR); -// refreshOperation.execute(mClient, this, mHandler); +// refreshOperation.onExecute(mClient, this, mHandler); } private void startUpload() { @@ -210,7 +210,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, // UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType, timeStamp); // uploadOperation.addDatatransferProgressListener(this); -// uploadOperation.execute(mClient, this, mHandler); +// uploadOperation.onExecute(mClient, this, mHandler); } private void startRemoteDeletion() { @@ -237,7 +237,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, // RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); -// removeOperation.execute(mClient, this, mHandler); +// removeOperation.onExecute(mClient, this, mHandler); } private void startDownload() { @@ -268,7 +268,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, // DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath()); // downloadOperation.addDatatransferProgressListener(this); -// downloadOperation.execute(mClient, this, mHandler); +// downloadOperation.onExecute(mClient, this, mHandler); } @SuppressWarnings("deprecation") diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index 28a90c68..79d45023 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -132,22 +132,13 @@ public class OwnCloudClient extends HttpClient { boolean repeatWithFreshCredentials; int repeatCounter = 0; - int status = -1; + int status; do { - try { - status = method.execute(); - checkFirstRedirection(method); - if(mFollowRedirects) { - status = followRedirection(method).getLastStatus(); - } - } catch (RedirectException e) { - // redirect must be handled twice. Once for dav4droid and once okhttp redirect errors - status = e.getStatus(); - mRedirectedLocation = e.getRedirectLocation(); - if(mFollowRedirects) { - status = followRedirection(method).getLastStatus(); - } + status = method.execute(); + checkFirstRedirection(method); + if(mFollowRedirects && !isIdPRedirection()) { + status = followRedirection(method).getLastStatus(); } repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter); @@ -160,7 +151,6 @@ public class OwnCloudClient extends HttpClient { } private void checkFirstRedirection(HttpBaseMethod method) { - final String location = method.getResponseHeader("location"); if(location != null && !location.isEmpty()) { mRedirectedLocation = location; @@ -414,7 +404,7 @@ public class OwnCloudClient extends HttpClient { mOwnCloudClientManager.removeClientFor(mAccount); } } - // else: execute will finish with status 401 + // else: onExecute will finish with status 401 } return credentialsWereRefreshed; diff --git a/src/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java b/src/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java index 30d5d504..3cba25d7 100644 --- a/src/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java +++ b/src/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java @@ -45,6 +45,7 @@ public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials { HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER); HttpClient.addHeaderForAllRequests(HttpConstants.COOKIE_HEADER, mSessionCookie); + client.setFollowRedirects(false); } @Override diff --git a/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java b/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java index d84d9f44..6d06cdc2 100644 --- a/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java +++ b/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java @@ -107,7 +107,7 @@ public class OAuth2GetAccessTokenOperation extends RemoteOperation { postMethod.setRequestBody(requestBody); - // Do the B***S*** Switch and execute + // Do the B***S*** Switch and onExecute OwnCloudCredentials oauthCredentials = new OwnCloudBasicCredentials(mClientId, mClientSecret); OwnCloudCredentials oldCredentials = switchClientCredentials(oauthCredentials); 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 f03ae1c1..c1ffd5c2 100644 --- a/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java @@ -46,7 +46,6 @@ import okhttp3.Response; * @author David González Verdugo */ public abstract class HttpBaseMethod { - public abstract int execute() throws Exception; protected OkHttpClient mOkHttpClient; protected Request mRequest; protected RequestBody mRequestBody; @@ -60,6 +59,10 @@ public abstract class HttpBaseMethod { .build(); } + public int execute() throws Exception { + return onExecute(); + } + public void abort() { mCall.cancel(); } @@ -68,6 +71,13 @@ public abstract class HttpBaseMethod { return mCall.isCanceled(); } + + ////////////////////////////// + // For override + ////////////////////////////// + + protected abstract int onExecute() throws Exception; + ////////////////////////////// // Getter ////////////////////////////// diff --git a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/DeleteMethod.java b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/DeleteMethod.java index 9ed7307a..249dc520 100644 --- a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/DeleteMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/DeleteMethod.java @@ -39,11 +39,11 @@ public class DeleteMethod extends HttpMethod{ } @Override - public int execute() throws IOException { + public int onExecute() throws IOException { mRequest = mRequest.newBuilder() .delete() .build(); - return super.execute(); + return super.onExecute(); } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/GetMethod.java b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/GetMethod.java index b24b9bce..9e33df29 100644 --- a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/GetMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/GetMethod.java @@ -39,11 +39,11 @@ public class GetMethod extends HttpMethod { } @Override - public int execute() throws IOException { + public int onExecute() throws IOException { mRequest = mRequest.newBuilder() .get() .build(); - return super.execute(); + return super.onExecute(); } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/HttpMethod.java b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/HttpMethod.java index a439b03b..0321bf15 100644 --- a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/HttpMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/HttpMethod.java @@ -43,7 +43,7 @@ public abstract class HttpMethod extends HttpBaseMethod { } @Override - public int execute() throws IOException { + public int onExecute() throws IOException { mCall = mOkHttpClient.newCall(mRequest); mResponse = mCall.execute(); return super.getStatusCode(); diff --git a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/PostMethod.java b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/PostMethod.java index 680400b6..5d0a3c7f 100644 --- a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/PostMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/PostMethod.java @@ -27,7 +27,6 @@ package com.owncloud.android.lib.common.http.methods.nonwebdav; import java.io.IOException; import okhttp3.HttpUrl; -import okhttp3.RequestBody; /** * OkHttp post calls wrapper @@ -40,11 +39,11 @@ public class PostMethod extends HttpMethod { } @Override - public int execute() throws IOException { + public int onExecute() throws IOException { mRequest = mRequest.newBuilder() .post(mRequestBody) .build(); - return super.execute(); + return super.onExecute(); } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/PutMethod.java b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/PutMethod.java index 64bf0f25..ede0db28 100644 --- a/src/com/owncloud/android/lib/common/http/methods/nonwebdav/PutMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/nonwebdav/PutMethod.java @@ -27,7 +27,6 @@ package com.owncloud.android.lib.common.http.methods.nonwebdav; import java.io.IOException; import okhttp3.HttpUrl; -import okhttp3.RequestBody; public class PutMethod extends HttpMethod{ @@ -36,11 +35,11 @@ public class PutMethod extends HttpMethod{ } @Override - public int execute() throws IOException { + public int onExecute() throws IOException { mRequest = mRequest.newBuilder() .put(mRequestBody) .build(); - return super.execute(); + return super.onExecute(); } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java index 9bcb9ce0..e133c536 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java @@ -15,7 +15,7 @@ public class CopyMethod extends DavMethod { } @Override - public int execute() throws Exception { + public int onExecute() throws Exception { try { mDavResource.copy(destinationUrl, forceOverride); 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 59802714..caed4780 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 @@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit; import at.bitfire.dav4android.DavOCResource; import at.bitfire.dav4android.DavResource; +import at.bitfire.dav4android.exception.RedirectException; import okhttp3.HttpUrl; /** @@ -50,9 +51,6 @@ public abstract class DavMethod extends HttpBaseMethod { mDavResource.setFollowRedirects(false); } - public DavResource getDavResource() { - return mDavResource; - } @Override public void abort() { @@ -60,10 +58,19 @@ public abstract class DavMethod extends HttpBaseMethod { } @Override - public boolean isAborted() { - return mDavResource.isCallAborted(); + public int execute() throws Exception { + try { + return onExecute(); + } catch(RedirectException e) { + mResponse = getDavResource().getResponse(); + return getStatusCode(); + } } + ////////////////////////////// + // setter + ////////////////////////////// + // Connection parameters @Override public void setReadTimeout(long readTimeout, TimeUnit timeUnit) { @@ -85,8 +92,26 @@ public abstract class DavMethod extends HttpBaseMethod { mDavResource.setRetryOnConnectionFailure(retryOnConnectionFailure); } + ////////////////////////////// + // getter + ////////////////////////////// + @Override public boolean getRetryOnConnectionFailure() { return mDavResource.isRetryOnConnectionFailure(); } + + @Override + public boolean isAborted() { + return mDavResource.isCallAborted(); + } + + + public DavResource getDavResource() { + return mDavResource; + } + + public void setUrl(HttpUrl url) { + mDavResource = new DavOCResource(mOkHttpClient, url); + } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java index ac8ebd06..91a13d5b 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java @@ -9,7 +9,7 @@ public class MkColMethod extends DavMethod { } @Override - public int execute() throws Exception { + public int onExecute() throws Exception { try { mDavResource.mkCol(null); diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java index 48861c6b..b5f1e65a 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java @@ -16,7 +16,7 @@ public class MoveMethod extends DavMethod { } @Override - public int execute() throws Exception { + public int onExecute() throws Exception { try { mDavResource.move( destinationUrl, diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java index 0f4f5ad4..f509c002 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java @@ -51,7 +51,7 @@ public class PropfindMethod extends DavMethod { }; @Override - public int execute() throws IOException, HttpException, DavException { + public int onExecute() throws IOException, HttpException, DavException { try { mDavResource.propfind(mDepth, mProperties); mMembers = mDavResource.getMembers(); diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java index 020bdcad..24e4c660 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java @@ -45,7 +45,7 @@ public class PutMethod extends DavMethod { }; @Override - public int execute() throws IOException, HttpException { + public int onExecute() throws IOException, HttpException { try { mDavResource.put( mRequestBody, diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java index 32be1215..365fcdcf 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java @@ -45,7 +45,7 @@ import okhttp3.OkHttpClient; /** * Operation which execution involves one or several interactions with an ownCloud server. * - * Provides methods to execute the operation both synchronously or asynchronously. + * Provides methods to onExecute the operation both synchronously or asynchronously. * * @author David A. Velasco * @author David González Verdugo @@ -115,10 +115,10 @@ public abstract class RemoteOperation implements Runnable { */ public RemoteOperationResult execute(Account account, Context context) { if (account == null) - throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + + throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " + "Account"); if (context == null) - throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + + throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " + "Context"); mAccount = account; mContext = context.getApplicationContext(); @@ -138,7 +138,7 @@ public abstract class RemoteOperation implements Runnable { */ public RemoteOperationResult execute(OwnCloudClient client) { if (client == null) - throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + + throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " + "OwnCloudClient"); mClient = client; if (client.getAccount() != null) { @@ -160,7 +160,7 @@ public abstract class RemoteOperation implements Runnable { */ public RemoteOperationResult execute(OkHttpClient client, Context context) { if (client == null) - throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + + throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " + "OwnCloudClient"); mHttpClient = client; mContext = context; @@ -188,10 +188,10 @@ public abstract class RemoteOperation implements Runnable { if (account == null) throw new IllegalArgumentException - ("Trying to execute a remote operation with a NULL Account"); + ("Trying to onExecute a remote operation with a NULL Account"); if (context == null) throw new IllegalArgumentException - ("Trying to execute a remote operation with a NULL Context"); + ("Trying to onExecute a remote operation with a NULL Context"); // mAccount and mContext in the runnerThread to create below mAccount = account; mContext = context.getApplicationContext(); @@ -221,7 +221,7 @@ public abstract class RemoteOperation implements Runnable { OnRemoteOperationListener listener, Handler listenerHandler) { if (client == null) { throw new IllegalArgumentException - ("Trying to execute a remote operation with a NULL OwnCloudClient"); + ("Trying to onExecute a remote operation with a NULL OwnCloudClient"); } mClient = client; if (client.getAccount() != null) { @@ -231,7 +231,7 @@ public abstract class RemoteOperation implements Runnable { if (listener == null) { throw new IllegalArgumentException - ("Trying to execute a remote operation asynchronously " + + ("Trying to onExecute a remote operation asynchronously " + "without a listener to notiy the result"); } mListener = listener; @@ -275,7 +275,7 @@ public abstract class RemoteOperation implements Runnable { } /** - * Run operation for asynchronous or synchronous 'execute' method. + * Run operation for asynchronous or synchronous 'onExecute' method. * * Considers and performs silent refresh of account credentials if possible, and if * {@link RemoteOperation#setSilentRefreshOfAccountCredentials(boolean)} was called with diff --git a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java index 456a7425..bf9090cd 100644 --- a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java @@ -86,7 +86,7 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { try { -// client.setFollowRedirects(false); + client.setFollowRedirects(true); PropfindMethod propfindMethod = new PropfindMethod( HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mPath)), 0, @@ -97,14 +97,6 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { int status = client.executeHttpMethod(propfindMethod); -// if (previousFollowRedirects) { -// mRedirectionPath = client.followRedirection(propfind); -// status = mRedirectionPath.getLastStatus(); -// } -// if (status != FORBIDDEN_ERROR && status != SERVICE_UNAVAILABLE_ERROR) { -// client.exhaustResponse(propfind.getResponseBodyAsStream()); -// } - /** * PROPFIND method * 404 NOT FOUND: path doesn't exist, @@ -127,9 +119,8 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException()); - } finally { -// client.setFollowRedirects(previousFollowRedirects); } + return result; } diff --git a/src/com/owncloud/android/lib/resources/files/RemoteFile.java b/src/com/owncloud/android/lib/resources/files/RemoteFile.java index c675f803..14ed0e2d 100644 --- a/src/com/owncloud/android/lib/resources/files/RemoteFile.java +++ b/src/com/owncloud/android/lib/resources/files/RemoteFile.java @@ -210,7 +210,9 @@ public class RemoteFile implements Parcelable, Serializable { ? BigDecimal.valueOf( properties.get(QuotaAvailableBytes.class).getQuotaAvailableBytes()) : BigDecimal.ZERO); - this.setPrivateLink(properties.get(OCPrivatelink.class).getLink()); + this.setPrivateLink(properties.get(OCPrivatelink.class) != null + ? properties.get(OCPrivatelink.class).getLink() + : null); } diff --git a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java index 719a25d1..55e2c55a 100644 --- a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java +++ b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java @@ -47,6 +47,8 @@ import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLPeerUnverifiedException; +import okhttp3.HttpUrl; + import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED; @@ -100,28 +102,25 @@ public class GetRemoteStatusOperation extends RemoteOperation { return false; } - + client.setFollowRedirects(false); boolean isRedirectToNonSecureConnection = false; + String redirectedLocation = mLatestResult.getRedirectedLocation(); + while (redirectedLocation != null && redirectedLocation.length() > 0 + && !mLatestResult.isSuccess()) { - // TODO Check this, although OkHttp should take care of the redirections -// boolean isRedirectToNonSecureConnection = false; -// String redirectedLocation = mLatestResult.getRedirectedLocation(); -// while (redirectedLocation != null && redirectedLocation.length() > 0 -// && !mLatestResult.isSuccess()) { -// -// isRedirectToNonSecureConnection |= ( -// baseUrlSt.startsWith(HTTPS_PREFIX) && -// redirectedLocation.startsWith(HTTP_PREFIX) -// ); -// get.releaseConnection(); -// get = new GetMethod(redirectedLocation); -// status = client.executeRequest(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); -// mLatestResult = new RemoteOperationResult( -// (status == HttpConstants.HTTP_OK), -// get -// ); -// redirectedLocation = mLatestResult.getRedirectedLocation(); -// } + isRedirectToNonSecureConnection |= ( + baseUrlSt.startsWith(HTTPS_PREFIX) && + redirectedLocation.startsWith(HTTP_PREFIX) + ); + + getMethod = new GetMethod(HttpUrl.parse(redirectedLocation)); + getMethod.setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS); + getMethod.setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS); + + status = client.executeHttpMethod(getMethod); + mLatestResult = new RemoteOperationResult(getMethod); + redirectedLocation = mLatestResult.getRedirectedLocation(); + } if (isSuccess(status)) {