Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit b287cb9

Browse files
committed
Compile project with latest changes from OkHttp and dav4jvm
1 parent 93026e8 commit b287cb9

File tree

9 files changed

+47
-46
lines changed

9 files changed

+47
-46
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudBasicCredentials.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
*/
2424
package com.owncloud.android.lib.common.authentication;
2525

26-
import com.owncloud.android.lib.common.OwnCloudClient;
27-
import com.owncloud.android.lib.common.http.HttpClient;
28-
import com.owncloud.android.lib.common.http.HttpConstants;
2926
import okhttp3.Credentials;
3027

3128
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -52,7 +49,7 @@ public String getAuthToken() {
5249

5350
@Override
5451
public String getHeaderAuth() {
55-
return Credentials.basic(mUsername, mPassword, Util.UTF_8);
52+
return Credentials.basic(mUsername, mPassword, UTF_8);
5653
}
5754

5855
@Override

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.owncloud.android.lib.common.http.HttpClient
44
import okhttp3.Call
55
import okhttp3.Headers
66
import okhttp3.HttpUrl
7+
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
78
import okhttp3.OkHttpClient
89
import okhttp3.Request
910
import okhttp3.RequestBody
@@ -15,7 +16,7 @@ import java.util.concurrent.TimeUnit
1516

1617
abstract class HttpBaseMethod constructor(url: URL) {
1718
var okHttpClient: OkHttpClient
18-
var httpUrl: HttpUrl = HttpUrl.parse(url.toString()) ?: throw MalformedURLException()
19+
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
1920
var request: Request
2021
var requestBody: RequestBody? = null
2122
lateinit var response: Response
@@ -47,7 +48,7 @@ abstract class HttpBaseMethod constructor(url: URL) {
4748

4849
// Headers
4950
val requestHeaders: Headers
50-
get() = request.headers()
51+
get() = request.headers
5152

5253
fun getRequestHeader(name: String): String? {
5354
return request.header(name)
@@ -84,14 +85,14 @@ abstract class HttpBaseMethod constructor(url: URL) {
8485
*** Response ***
8586
****************/
8687
val statusCode: Int
87-
get() = response.code()
88+
get() = response.code
8889

8990
val statusMessage: String
90-
get() = response.message()
91+
get() = response.message
9192

9293
// Headers
9394
open fun getResponseHeaders(): Headers? {
94-
return response.headers()
95+
return response.headers
9596
}
9697

9798
open fun getResponseHeader(headerName: String): String? {
@@ -100,14 +101,14 @@ abstract class HttpBaseMethod constructor(url: URL) {
100101

101102
// Body
102103
fun getResponseBodyAsString(): String? {
103-
if (responseBodyString == null && response.body() != null) {
104-
responseBodyString = response.body()?.string()
104+
if (responseBodyString == null && response.body != null) {
105+
responseBodyString = response.body?.string()
105106
}
106107
return responseBodyString
107108
}
108109

109110
open fun getResponseBodyAsStream(): InputStream? {
110-
return response.body()?.byteStream()
111+
return response.body?.byteStream()
111112
}
112113

113114
/*************************
@@ -153,7 +154,7 @@ abstract class HttpBaseMethod constructor(url: URL) {
153154
}
154155

155156
open val isAborted: Boolean
156-
get() = call?.isCanceled ?: false
157+
get() = call?.isCanceled() ?: false
157158

158159
//////////////////////////////
159160
// For override

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
*/
2424
package com.owncloud.android.lib.common.http.methods.webdav
2525

26-
import at.bitfire.dav4android.Constants.log
27-
import at.bitfire.dav4android.exception.HttpException
28-
import at.bitfire.dav4android.exception.RedirectException
26+
import at.bitfire.dav4jvm.Dav4jvm.log
27+
import at.bitfire.dav4jvm.exception.HttpException
28+
import at.bitfire.dav4jvm.exception.RedirectException
2929
import com.owncloud.android.lib.common.http.HttpConstants
3030
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
3131
import okhttp3.HttpUrl
32+
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
3233
import okhttp3.Protocol
3334
import okhttp3.Response
34-
import okhttp3.ResponseBody
35+
import okhttp3.ResponseBody.Companion.toResponseBody
3536
import java.net.MalformedURLException
3637
import java.net.URL
3738
import java.util.concurrent.TimeUnit
@@ -45,7 +46,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
4546
protected var mDavResource: OCDavResource
4647

4748
init {
48-
val httpUrl = HttpUrl.parse(url.toString()) ?: throw MalformedURLException()
49+
val httpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
4950
mDavResource = OCDavResource(
5051
okHttpClient,
5152
httpUrl,
@@ -76,11 +77,9 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
7677
} else {
7778
// The check below should be included in okhttp library, method ResponseBody.create(
7879
// TODO check most recent versions of okhttp to see if this is already fixed and try to update if so
79-
if (response.body()?.contentType() != null) {
80-
val responseBody = ResponseBody.create(
81-
response.body()?.contentType(),
82-
httpException.responseBody?:""
83-
)
80+
if (response.body?.contentType() != null) {
81+
val responseBody = (httpException.responseBody ?: ""
82+
).toResponseBody(response.body?.contentType())
8483
response = response.newBuilder()
8584
.body(responseBody)
8685
.build()

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
package com.owncloud.android.lib.common.http.methods.webdav
2525

26-
import at.bitfire.dav4android.Property
27-
import at.bitfire.dav4android.PropertyUtils.getAllPropSet
28-
import at.bitfire.dav4android.PropertyUtils.getQuotaPropset
26+
import at.bitfire.dav4jvm.Property
27+
import at.bitfire.dav4jvm.PropertyUtils.getAllPropSet
28+
import at.bitfire.dav4jvm.PropertyUtils.getQuotaPropset
2929

3030
object DavUtils {
3131
@JvmStatic val allPropset: Array<Property.Name>

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/OCDavResource.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package com.owncloud.android.lib.common.http.methods.webdav
22

3-
import at.bitfire.dav4android.DavResource
4-
import at.bitfire.dav4android.DavResponseCallback
5-
import at.bitfire.dav4android.IF_MATCH_HEADER
6-
import at.bitfire.dav4android.Property
7-
import at.bitfire.dav4android.QuotedStringUtils
8-
import at.bitfire.dav4android.XmlUtils
9-
import at.bitfire.dav4android.exception.DavException
10-
import at.bitfire.dav4android.exception.HttpException
3+
import at.bitfire.dav4jvm.DavResource
4+
import at.bitfire.dav4jvm.DavResponseCallback
5+
import at.bitfire.dav4jvm.IF_MATCH_HEADER
6+
import at.bitfire.dav4jvm.Property
7+
import at.bitfire.dav4jvm.QuotedStringUtils
8+
import at.bitfire.dav4jvm.XmlUtils
9+
import at.bitfire.dav4jvm.exception.DavException
10+
import at.bitfire.dav4jvm.exception.HttpException
1111
import okhttp3.HttpUrl
1212
import okhttp3.OkHttpClient
1313
import okhttp3.Request
1414
import okhttp3.RequestBody
15+
import okhttp3.RequestBody.Companion.toRequestBody
1516
import okhttp3.Response
1617
import java.io.IOException
1718
import java.io.StringWriter
@@ -162,9 +163,9 @@ class OCDavResource(
162163
listOfHeaders: HashMap<String, String?>?,
163164
callback: (response: Response) -> Unit
164165
) {
165-
val rqBody = if (xmlBody != null) RequestBody.create(MIME_XML, xmlBody) else null
166+
val requestBody = xmlBody?.toRequestBody(MIME_XML)
166167
val requestBuilder = Request.Builder()
167-
.method("MKCOL", rqBody)
168+
.method("MKCOL", requestBody)
168169
.url(location)
169170
listOfHeaders?.forEach { (name, value) ->
170171
value?.let {
@@ -264,7 +265,7 @@ class OCDavResource(
264265
}.use { response ->
265266
callback(response)
266267
checkStatus(response)
267-
if (response.code() == 207)
268+
if (response.code == 207)
268269
/* If an error occurs deleting a member resource (a resource other than
269270
the resource identified in the Request-URI), then the response can be
270271
a 207 (Multi-Status). […] (RFC 4918 9.6.1. DELETE for Collections) */
@@ -316,7 +317,7 @@ class OCDavResource(
316317

317318
val requestBuilder = Request.Builder()
318319
.url(location)
319-
.method("PROPFIND", RequestBody.create(MIME_XML, writer.toString()))
320+
.method("PROPFIND", writer.toString().toRequestBody(MIME_XML))
320321
.header("Depth", if (depth >= 0) depth.toString() else "infinity")
321322

322323
listOfHeaders?.forEach { (name, value) ->

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
*/
2424
package com.owncloud.android.lib.common.http.methods.webdav
2525

26-
import at.bitfire.dav4android.Property
27-
import at.bitfire.dav4android.Response
28-
import at.bitfire.dav4android.Response.HrefRelation
29-
import at.bitfire.dav4android.exception.DavException
26+
import at.bitfire.dav4jvm.Property
27+
import at.bitfire.dav4jvm.Response
28+
import at.bitfire.dav4jvm.Response.HrefRelation
29+
import at.bitfire.dav4jvm.exception.DavException
3030
import java.io.IOException
3131
import java.net.URL
3232
import java.util.ArrayList

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
package com.owncloud.android.lib.common.http.methods.webdav
2525

26-
import at.bitfire.dav4android.exception.HttpException
26+
import at.bitfire.dav4jvm.exception.HttpException
2727
import com.owncloud.android.lib.common.http.HttpConstants
2828
import java.io.IOException
2929
import java.net.URL

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.owncloud.android.lib.common.OwnCloudClient;
2727
import com.owncloud.android.lib.common.accounts.AccountUtils;
2828
import com.owncloud.android.lib.common.http.HttpConstants;
29+
import com.owncloud.android.lib.common.http.methods.webdav.DavUtils;
30+
import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod;
2931
import com.owncloud.android.lib.common.network.WebdavUtils;
3032
import com.owncloud.android.lib.common.operations.RemoteOperation;
3133
import com.owncloud.android.lib.common.operations.RemoteOperationResult;

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.owncloud.android.lib.common.accounts.AccountUtils;
3030
import com.owncloud.android.lib.common.http.HttpConstants;
3131
import com.owncloud.android.lib.common.http.methods.webdav.DavConstants;
32+
import com.owncloud.android.lib.common.http.methods.webdav.DavUtils;
33+
import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod;
3234
import com.owncloud.android.lib.common.network.WebdavUtils;
3335
import com.owncloud.android.lib.common.operations.RemoteOperation;
3436
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -120,7 +122,6 @@ protected RemoteOperationResult<ArrayList<RemoteFile>> run(OwnCloudClient client
120122
}
121123

122124
private boolean isSuccess(int status) {
123-
return status == HttpConstants.HTTP_MULTI_STATUS ||
124-
status == HttpConstants.HTTP_OK;
125+
return status == HttpConstants.HTTP_MULTI_STATUS || status == HttpConstants.HTTP_OK;
125126
}
126-
}
127+
}

0 commit comments

Comments
 (0)