mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
make redirection actually work ... finaly
This commit is contained in:
parent
bd5dc20842
commit
c33c7c551d
@ -1 +1 @@
|
||||
Subproject commit 1108048f1a2ff12103cdf6a95307a314d621c088
|
||||
Subproject commit c6c06a144a1eaf3a75035dfe8700c42b86b0d223
|
@ -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")
|
||||
|
@ -132,23 +132,14 @@ public class OwnCloudClient extends HttpClient {
|
||||
|
||||
boolean repeatWithFreshCredentials;
|
||||
int repeatCounter = 0;
|
||||
int status = -1;
|
||||
int status;
|
||||
|
||||
do {
|
||||
try {
|
||||
status = method.execute();
|
||||
checkFirstRedirection(method);
|
||||
if(mFollowRedirects) {
|
||||
if(mFollowRedirects && !isIdPRedirection()) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter);
|
||||
if (repeatWithFreshCredentials) {
|
||||
@ -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;
|
||||
|
@ -45,6 +45,7 @@ public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {
|
||||
HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER);
|
||||
|
||||
HttpClient.addHeaderForAllRequests(HttpConstants.COOKIE_HEADER, mSessionCookie);
|
||||
client.setFollowRedirects(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
//////////////////////////////
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -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,9 +58,18 @@ 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
|
||||
@ -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);
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ public class MkColMethod extends DavMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int execute() throws Exception {
|
||||
public int onExecute() throws Exception {
|
||||
try {
|
||||
mDavResource.mkCol(null);
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class MoveMethod extends DavMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int execute() throws Exception {
|
||||
public int onExecute() throws Exception {
|
||||
try {
|
||||
mDavResource.move(
|
||||
destinationUrl,
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)) {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user