mirror of
https://github.com/owncloud/android-library.git
synced 2025-07-23 18:06:17 +00:00
Compile project with latest changes from OkHttp and dav4jvm
This commit is contained in:
parent
93026e8180
commit
b287cb9148
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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<Property.Name>
|
||||
|
@ -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<String, String?>?,
|
||||
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) ->
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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<ArrayList<RemoteF
|
||||
}
|
||||
|
||||
private boolean isSuccess(int status) {
|
||||
return status == HttpConstants.HTTP_MULTI_STATUS ||
|
||||
status == HttpConstants.HTTP_OK;
|
||||
return status == HttpConstants.HTTP_MULTI_STATUS || status == HttpConstants.HTTP_OK;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user