diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index 901261f9..6fe0dc9d 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -59,6 +59,7 @@ import java.util.Arrays; import okhttp3.OkHttpClient; import okhttp3.Protocol; +import okhttp3.Response; public class OwnCloudClient extends HttpClient { @@ -309,21 +310,21 @@ public class OwnCloudClient extends HttpClient { return status; } - public int executeHttpMethod (HttpBaseMethod method) throws Exception { + public Response executeHttpMethod (HttpBaseMethod method) throws Exception { boolean repeatWithFreshCredentials; int repeatCounter = 0; - int status; + Response response; do { - status = method.execute(); - repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter); + response = method.execute(); + repeatWithFreshCredentials = checkUnauthorizedAccess(response.code(), repeatCounter); if (repeatWithFreshCredentials) { repeatCounter++; } } while (repeatWithFreshCredentials); - return status; + return response; } private void checkFirstRedirection(HttpMethod method) { diff --git a/src/com/owncloud/android/lib/common/http/HttpBaseMethod.java b/src/com/owncloud/android/lib/common/http/HttpBaseMethod.java index 224e5eba..8a73c16b 100644 --- a/src/com/owncloud/android/lib/common/http/HttpBaseMethod.java +++ b/src/com/owncloud/android/lib/common/http/HttpBaseMethod.java @@ -4,15 +4,10 @@ import okhttp3.Request; import okhttp3.Response; public abstract class HttpBaseMethod { - public abstract int execute() throws Exception; + public abstract Response execute() throws Exception; protected Request mRequest; - protected Response mResponse; public Request getRequest() { return mRequest; } - - public Response getResponse() { - return mResponse; - } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/http/nonwebdav/GetMethod.java b/src/com/owncloud/android/lib/common/http/nonwebdav/GetMethod.java index 385582b6..6015e474 100644 --- a/src/com/owncloud/android/lib/common/http/nonwebdav/GetMethod.java +++ b/src/com/owncloud/android/lib/common/http/nonwebdav/GetMethod.java @@ -4,6 +4,7 @@ import java.io.IOException; import okhttp3.OkHttpClient; import okhttp3.Request; +import okhttp3.Response; public class GetMethod extends HttpMethod { @@ -12,13 +13,12 @@ public class GetMethod extends HttpMethod { } @Override - public int execute() throws IOException { + public Response execute() throws IOException { mRequest = mBaseRequest .newBuilder() .get() .build(); - mResponse = mOkHttpClient.newCall(mRequest).execute(); - return mResponse.code(); + return mOkHttpClient.newCall(mRequest).execute(); } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/http/webdav/PropfindMethod.java b/src/com/owncloud/android/lib/common/http/webdav/PropfindMethod.java index c90401a8..8fb66819 100644 --- a/src/com/owncloud/android/lib/common/http/webdav/PropfindMethod.java +++ b/src/com/owncloud/android/lib/common/http/webdav/PropfindMethod.java @@ -10,6 +10,7 @@ import at.bitfire.dav4android.exception.HttpException; import at.bitfire.dav4android.exception.UnauthorizedException; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; +import okhttp3.Response; public class PropfindMethod extends DavMethod { @@ -22,8 +23,7 @@ public class PropfindMethod extends DavMethod { }; @Override - public int execute() throws IOException, HttpException, DavException { - + public Response execute() throws IOException, HttpException, DavException { try { mDavResource.propfind(mDepth, PropertyUtils.INSTANCE.getAllPropSet()); mMembers = mDavResource.getMembers(); @@ -32,9 +32,7 @@ public class PropfindMethod extends DavMethod { } mRequest = mDavResource.getRequest(); - mResponse = mDavResource.getResponse(); - - return mResponse.code(); + return mDavResource.getResponse(); } public int getDepth() { diff --git a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java index 8c905305..7516febb 100644 --- a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java @@ -35,6 +35,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.HttpStatus; import okhttp3.HttpUrl; +import okhttp3.Response; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; @@ -86,7 +87,7 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { HttpUrl.parse(client.getNewWebDavUri() + WebdavUtils.encodePath(mPath)), 0); - int status = client.executeHttpMethod(propfindMethod); + Response response = client.executeHttpMethod(propfindMethod); // if (previousFollowRedirects) { // mRedirectionPath = client.followRedirection(propfind); @@ -101,21 +102,22 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { * 404 NOT FOUND: path doesn't exist, * 207 MULTI_STATUS: path exists. */ - boolean isSuccess = ((status == HttpStatus.SC_OK || status == HttpStatus.SC_MULTI_STATUS) && - !mSuccessIfAbsent) || - (status == HttpStatus.SC_MULTI_STATUS && !mSuccessIfAbsent) || - (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent); + boolean isSuccess = ((response.code() == HttpStatus.SC_OK + || response.code() == HttpStatus.SC_MULTI_STATUS) + && !mSuccessIfAbsent) + || (response.code() == HttpStatus.SC_MULTI_STATUS && !mSuccessIfAbsent) + || (response.code() == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent); result = isSuccess ? new RemoteOperationResult(OK) : new RemoteOperationResult( - false, propfindMethod.getRequest(), propfindMethod.getResponse() + false, propfindMethod.getRequest(), response ); Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + - "finished with HTTP status " + status + (!isSuccess?"(FAIL)":"")); + "finished with HTTP status " + response.code() + (!isSuccess?"(FAIL)":"")); } catch (Exception e) { result = new RemoteOperationResult(e); @@ -130,7 +132,6 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { return result; } - /** * Gets the sequence of redirections followed during the execution of the operation. * @@ -146,4 +147,4 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { public boolean wasRedirected() { return (mRedirectionPath != null && mRedirectionPath.getRedirectionsCount() > 0); } -} +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java index f906a346..25a8da92 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java @@ -34,6 +34,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.http.nonwebdav.GetMethod; import okhttp3.Request; +import okhttp3.Response; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; @@ -75,13 +76,12 @@ public class GetRemoteUserInfoOperation extends RemoteOperation { .build(); GetMethod getMethod = new GetMethod(client.getOkHttpClient(), request); - int status = client.executeHttpMethod(getMethod); - String response = getMethod.getResponse().body().string(); + Response response = client.executeHttpMethod(getMethod); - if (isSuccess(status)) { + if (isSuccess(response.code())) { Log_OC.d(TAG, "Successful response"); - JSONObject respJSON = new JSONObject(response); + JSONObject respJSON = new JSONObject(response.body().string()); JSONObject respOCS = respJSON.getJSONObject(NODE_OCS); JSONObject respData = respOCS.getJSONObject(NODE_DATA); @@ -97,12 +97,12 @@ public class GetRemoteUserInfoOperation extends RemoteOperation { result.setData(data); } else { - result = new RemoteOperationResult(false, getMethod.getRequest(), getMethod.getResponse()); + result = new RemoteOperationResult(false, getMethod.getRequest(), response); Log_OC.e(TAG, "Failed response while getting user information "); if (response != null) { - Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response); + Log_OC.e(TAG, "*** status code: " + response.code() + " ; response message: " + response); } else { - Log_OC.e(TAG, "*** status code: " + status); + Log_OC.e(TAG, "*** status code: " + response.code()); } } } catch (Exception e) {