1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-15 18:32:57 +00:00

Refactor httm methods to return response instead of response code

This commit is contained in:
davigonz
2018-06-06 13:53:14 +02:00
parent 25bba85ee1
commit 01d4592de0
6 changed files with 30 additions and 35 deletions
@@ -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) {
@@ -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;
}
}
@@ -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();
}
}
@@ -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() {