From b287cb91486092f95c483328235039a7ce013470 Mon Sep 17 00:00:00 2001 From: agarcia Date: Wed, 1 Jul 2020 17:16:10 +0200 Subject: [PATCH] Compile project with latest changes from OkHttp and dav4jvm --- .../OwnCloudBasicCredentials.java | 5 +--- .../lib/common/http/methods/HttpBaseMethod.kt | 19 +++++++------- .../common/http/methods/webdav/DavMethod.kt | 19 +++++++------- .../common/http/methods/webdav/DavUtils.kt | 6 ++--- .../http/methods/webdav/OCDavResource.kt | 25 ++++++++++--------- .../http/methods/webdav/PropfindMethod.kt | 8 +++--- .../common/http/methods/webdav/PutMethod.kt | 2 +- .../files/ReadRemoteFileOperation.java | 2 ++ .../files/ReadRemoteFolderOperation.java | 7 +++--- 9 files changed, 47 insertions(+), 46 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java index 96e8a233..3f1eeb4c 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java @@ -23,9 +23,6 @@ */ package com.owncloud.android.lib.common.authentication; -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.http.HttpClient; -import com.owncloud.android.lib.common.http.HttpConstants; import okhttp3.Credentials; import static java.nio.charset.StandardCharsets.UTF_8; @@ -52,7 +49,7 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials { @Override public String getHeaderAuth() { - return Credentials.basic(mUsername, mPassword, Util.UTF_8); + return Credentials.basic(mUsername, mPassword, UTF_8); } @Override diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt index c71d065d..f29420d8 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt @@ -4,6 +4,7 @@ import com.owncloud.android.lib.common.http.HttpClient import okhttp3.Call import okhttp3.Headers import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody @@ -15,7 +16,7 @@ import java.util.concurrent.TimeUnit abstract class HttpBaseMethod constructor(url: URL) { var okHttpClient: OkHttpClient - var httpUrl: HttpUrl = HttpUrl.parse(url.toString()) ?: throw MalformedURLException() + var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException() var request: Request var requestBody: RequestBody? = null lateinit var response: Response @@ -47,7 +48,7 @@ abstract class HttpBaseMethod constructor(url: URL) { // Headers val requestHeaders: Headers - get() = request.headers() + get() = request.headers fun getRequestHeader(name: String): String? { return request.header(name) @@ -84,14 +85,14 @@ abstract class HttpBaseMethod constructor(url: URL) { *** Response *** ****************/ val statusCode: Int - get() = response.code() + get() = response.code val statusMessage: String - get() = response.message() + get() = response.message // Headers open fun getResponseHeaders(): Headers? { - return response.headers() + return response.headers } open fun getResponseHeader(headerName: String): String? { @@ -100,14 +101,14 @@ abstract class HttpBaseMethod constructor(url: URL) { // Body fun getResponseBodyAsString(): String? { - if (responseBodyString == null && response.body() != null) { - responseBodyString = response.body()?.string() + if (responseBodyString == null && response.body != null) { + responseBodyString = response.body?.string() } return responseBodyString } open fun getResponseBodyAsStream(): InputStream? { - return response.body()?.byteStream() + return response.body?.byteStream() } /************************* @@ -153,7 +154,7 @@ abstract class HttpBaseMethod constructor(url: URL) { } open val isAborted: Boolean - get() = call?.isCanceled ?: false + get() = call?.isCanceled() ?: false ////////////////////////////// // For override diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.kt index ce98bb4f..aa160966 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.kt @@ -23,15 +23,16 @@ */ package com.owncloud.android.lib.common.http.methods.webdav -import at.bitfire.dav4android.Constants.log -import at.bitfire.dav4android.exception.HttpException -import at.bitfire.dav4android.exception.RedirectException +import at.bitfire.dav4jvm.Dav4jvm.log +import at.bitfire.dav4jvm.exception.HttpException +import at.bitfire.dav4jvm.exception.RedirectException import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.HttpBaseMethod import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Protocol import okhttp3.Response -import okhttp3.ResponseBody +import okhttp3.ResponseBody.Companion.toResponseBody import java.net.MalformedURLException import java.net.URL import java.util.concurrent.TimeUnit @@ -45,7 +46,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) { protected var mDavResource: OCDavResource init { - val httpUrl = HttpUrl.parse(url.toString()) ?: throw MalformedURLException() + val httpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException() mDavResource = OCDavResource( okHttpClient, httpUrl, @@ -76,11 +77,9 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) { } else { // The check below should be included in okhttp library, method ResponseBody.create( // TODO check most recent versions of okhttp to see if this is already fixed and try to update if so - if (response.body()?.contentType() != null) { - val responseBody = ResponseBody.create( - response.body()?.contentType(), - httpException.responseBody?:"" - ) + if (response.body?.contentType() != null) { + val responseBody = (httpException.responseBody ?: "" + ).toResponseBody(response.body?.contentType()) response = response.newBuilder() .body(responseBody) .build() diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavUtils.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavUtils.kt index 6da28798..22e1981f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavUtils.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavUtils.kt @@ -23,9 +23,9 @@ */ package com.owncloud.android.lib.common.http.methods.webdav -import at.bitfire.dav4android.Property -import at.bitfire.dav4android.PropertyUtils.getAllPropSet -import at.bitfire.dav4android.PropertyUtils.getQuotaPropset +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyUtils.getAllPropSet +import at.bitfire.dav4jvm.PropertyUtils.getQuotaPropset object DavUtils { @JvmStatic val allPropset: Array diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/OCDavResource.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/OCDavResource.kt index 037f65ed..d8a53583 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/OCDavResource.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/OCDavResource.kt @@ -1,17 +1,18 @@ package com.owncloud.android.lib.common.http.methods.webdav -import at.bitfire.dav4android.DavResource -import at.bitfire.dav4android.DavResponseCallback -import at.bitfire.dav4android.IF_MATCH_HEADER -import at.bitfire.dav4android.Property -import at.bitfire.dav4android.QuotedStringUtils -import at.bitfire.dav4android.XmlUtils -import at.bitfire.dav4android.exception.DavException -import at.bitfire.dav4android.exception.HttpException +import at.bitfire.dav4jvm.DavResource +import at.bitfire.dav4jvm.DavResponseCallback +import at.bitfire.dav4jvm.IF_MATCH_HEADER +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.QuotedStringUtils +import at.bitfire.dav4jvm.XmlUtils +import at.bitfire.dav4jvm.exception.DavException +import at.bitfire.dav4jvm.exception.HttpException import okhttp3.HttpUrl import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response import java.io.IOException import java.io.StringWriter @@ -162,9 +163,9 @@ class OCDavResource( listOfHeaders: HashMap?, callback: (response: Response) -> Unit ) { - val rqBody = if (xmlBody != null) RequestBody.create(MIME_XML, xmlBody) else null + val requestBody = xmlBody?.toRequestBody(MIME_XML) val requestBuilder = Request.Builder() - .method("MKCOL", rqBody) + .method("MKCOL", requestBody) .url(location) listOfHeaders?.forEach { (name, value) -> value?.let { @@ -264,7 +265,7 @@ class OCDavResource( }.use { response -> callback(response) checkStatus(response) - if (response.code() == 207) + if (response.code == 207) /* If an error occurs deleting a member resource (a resource other than the resource identified in the Request-URI), then the response can be a 207 (Multi-Status). […] (RFC 4918 9.6.1. DELETE for Collections) */ @@ -316,7 +317,7 @@ class OCDavResource( val requestBuilder = Request.Builder() .url(location) - .method("PROPFIND", RequestBody.create(MIME_XML, writer.toString())) + .method("PROPFIND", writer.toString().toRequestBody(MIME_XML)) .header("Depth", if (depth >= 0) depth.toString() else "infinity") listOfHeaders?.forEach { (name, value) -> diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt index f99fd394..7fb0b05b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt @@ -23,10 +23,10 @@ */ package com.owncloud.android.lib.common.http.methods.webdav -import at.bitfire.dav4android.Property -import at.bitfire.dav4android.Response -import at.bitfire.dav4android.Response.HrefRelation -import at.bitfire.dav4android.exception.DavException +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.Response +import at.bitfire.dav4jvm.Response.HrefRelation +import at.bitfire.dav4jvm.exception.DavException import java.io.IOException import java.net.URL import java.util.ArrayList diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.kt index c63b7327..d19e7118 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.kt @@ -23,7 +23,7 @@ */ package com.owncloud.android.lib.common.http.methods.webdav -import at.bitfire.dav4android.exception.HttpException +import at.bitfire.dav4jvm.exception.HttpException import com.owncloud.android.lib.common.http.HttpConstants import java.io.IOException import java.net.URL diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java index 55facfe4..9149e6d3 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java @@ -26,6 +26,8 @@ package com.owncloud.android.lib.resources.files; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.http.HttpConstants; +import com.owncloud.android.lib.common.http.methods.webdav.DavUtils; +import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java index 8a11bc9c..03cb3aa7 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java @@ -29,6 +29,8 @@ import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.http.HttpConstants; import com.owncloud.android.lib.common.http.methods.webdav.DavConstants; +import com.owncloud.android.lib.common.http.methods.webdav.DavUtils; +import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -120,7 +122,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation