mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +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; | 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 okhttp3.Credentials; | ||||||
| 
 | 
 | ||||||
| import static java.nio.charset.StandardCharsets.UTF_8; | import static java.nio.charset.StandardCharsets.UTF_8; | ||||||
| @ -52,7 +49,7 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials { | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public String getHeaderAuth() { |     public String getHeaderAuth() { | ||||||
|         return Credentials.basic(mUsername, mPassword, Util.UTF_8); |         return Credentials.basic(mUsername, mPassword, UTF_8); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | |||||||
| @ -4,6 +4,7 @@ import com.owncloud.android.lib.common.http.HttpClient | |||||||
| import okhttp3.Call | import okhttp3.Call | ||||||
| import okhttp3.Headers | import okhttp3.Headers | ||||||
| import okhttp3.HttpUrl | import okhttp3.HttpUrl | ||||||
|  | import okhttp3.HttpUrl.Companion.toHttpUrlOrNull | ||||||
| import okhttp3.OkHttpClient | import okhttp3.OkHttpClient | ||||||
| import okhttp3.Request | import okhttp3.Request | ||||||
| import okhttp3.RequestBody | import okhttp3.RequestBody | ||||||
| @ -15,7 +16,7 @@ import java.util.concurrent.TimeUnit | |||||||
| 
 | 
 | ||||||
| abstract class HttpBaseMethod constructor(url: URL) { | abstract class HttpBaseMethod constructor(url: URL) { | ||||||
|     var okHttpClient: OkHttpClient |     var okHttpClient: OkHttpClient | ||||||
|     var httpUrl: HttpUrl = HttpUrl.parse(url.toString()) ?: throw MalformedURLException() |     var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException() | ||||||
|     var request: Request |     var request: Request | ||||||
|     var requestBody: RequestBody? = null |     var requestBody: RequestBody? = null | ||||||
|     lateinit var response: Response |     lateinit var response: Response | ||||||
| @ -47,7 +48,7 @@ abstract class HttpBaseMethod constructor(url: URL) { | |||||||
| 
 | 
 | ||||||
|     // Headers |     // Headers | ||||||
|     val requestHeaders: Headers |     val requestHeaders: Headers | ||||||
|         get() = request.headers() |         get() = request.headers | ||||||
| 
 | 
 | ||||||
|     fun getRequestHeader(name: String): String? { |     fun getRequestHeader(name: String): String? { | ||||||
|         return request.header(name) |         return request.header(name) | ||||||
| @ -84,14 +85,14 @@ abstract class HttpBaseMethod constructor(url: URL) { | |||||||
|      *** Response *** |      *** Response *** | ||||||
|      ****************/ |      ****************/ | ||||||
|     val statusCode: Int |     val statusCode: Int | ||||||
|         get() = response.code() |         get() = response.code | ||||||
| 
 | 
 | ||||||
|     val statusMessage: String |     val statusMessage: String | ||||||
|         get() = response.message() |         get() = response.message | ||||||
| 
 | 
 | ||||||
|     // Headers |     // Headers | ||||||
|     open fun getResponseHeaders(): Headers? { |     open fun getResponseHeaders(): Headers? { | ||||||
|         return response.headers() |         return response.headers | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     open fun getResponseHeader(headerName: String): String? { |     open fun getResponseHeader(headerName: String): String? { | ||||||
| @ -100,14 +101,14 @@ abstract class HttpBaseMethod constructor(url: URL) { | |||||||
| 
 | 
 | ||||||
|     // Body |     // Body | ||||||
|     fun getResponseBodyAsString(): String? { |     fun getResponseBodyAsString(): String? { | ||||||
|         if (responseBodyString == null && response.body() != null) { |         if (responseBodyString == null && response.body != null) { | ||||||
|             responseBodyString = response.body()?.string() |             responseBodyString = response.body?.string() | ||||||
|         } |         } | ||||||
|         return responseBodyString |         return responseBodyString | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     open fun getResponseBodyAsStream(): InputStream? { |     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 |     open val isAborted: Boolean | ||||||
|         get() = call?.isCanceled ?: false |         get() = call?.isCanceled() ?: false | ||||||
| 
 | 
 | ||||||
|     ////////////////////////////// |     ////////////////////////////// | ||||||
|     //         For override |     //         For override | ||||||
|  | |||||||
| @ -23,15 +23,16 @@ | |||||||
|  */ |  */ | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
| 
 | 
 | ||||||
| import at.bitfire.dav4android.Constants.log | import at.bitfire.dav4jvm.Dav4jvm.log | ||||||
| import at.bitfire.dav4android.exception.HttpException | import at.bitfire.dav4jvm.exception.HttpException | ||||||
| import at.bitfire.dav4android.exception.RedirectException | import at.bitfire.dav4jvm.exception.RedirectException | ||||||
| import com.owncloud.android.lib.common.http.HttpConstants | import com.owncloud.android.lib.common.http.HttpConstants | ||||||
| import com.owncloud.android.lib.common.http.methods.HttpBaseMethod | import com.owncloud.android.lib.common.http.methods.HttpBaseMethod | ||||||
| import okhttp3.HttpUrl | import okhttp3.HttpUrl | ||||||
|  | import okhttp3.HttpUrl.Companion.toHttpUrlOrNull | ||||||
| import okhttp3.Protocol | import okhttp3.Protocol | ||||||
| import okhttp3.Response | import okhttp3.Response | ||||||
| import okhttp3.ResponseBody | import okhttp3.ResponseBody.Companion.toResponseBody | ||||||
| import java.net.MalformedURLException | import java.net.MalformedURLException | ||||||
| import java.net.URL | import java.net.URL | ||||||
| import java.util.concurrent.TimeUnit | import java.util.concurrent.TimeUnit | ||||||
| @ -45,7 +46,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) { | |||||||
|     protected var mDavResource: OCDavResource |     protected var mDavResource: OCDavResource | ||||||
| 
 | 
 | ||||||
|     init { |     init { | ||||||
|         val httpUrl = HttpUrl.parse(url.toString()) ?: throw MalformedURLException() |         val httpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException() | ||||||
|         mDavResource = OCDavResource( |         mDavResource = OCDavResource( | ||||||
|             okHttpClient, |             okHttpClient, | ||||||
|             httpUrl, |             httpUrl, | ||||||
| @ -76,11 +77,9 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) { | |||||||
|             } else { |             } else { | ||||||
|                 // The check below should be included in okhttp library, method ResponseBody.create( |                 // 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 |                 // 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) { |                 if (response.body?.contentType() != null) { | ||||||
|                     val responseBody = ResponseBody.create( |                     val responseBody = (httpException.responseBody ?: "" | ||||||
|                         response.body()?.contentType(), |                             ).toResponseBody(response.body?.contentType()) | ||||||
|                         httpException.responseBody?:"" |  | ||||||
|                     ) |  | ||||||
|                     response = response.newBuilder() |                     response = response.newBuilder() | ||||||
|                         .body(responseBody) |                         .body(responseBody) | ||||||
|                         .build() |                         .build() | ||||||
|  | |||||||
| @ -23,9 +23,9 @@ | |||||||
|  */ |  */ | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
| 
 | 
 | ||||||
| import at.bitfire.dav4android.Property | import at.bitfire.dav4jvm.Property | ||||||
| import at.bitfire.dav4android.PropertyUtils.getAllPropSet | import at.bitfire.dav4jvm.PropertyUtils.getAllPropSet | ||||||
| import at.bitfire.dav4android.PropertyUtils.getQuotaPropset | import at.bitfire.dav4jvm.PropertyUtils.getQuotaPropset | ||||||
| 
 | 
 | ||||||
| object DavUtils { | object DavUtils { | ||||||
|     @JvmStatic val allPropset: Array<Property.Name> |     @JvmStatic val allPropset: Array<Property.Name> | ||||||
|  | |||||||
| @ -1,17 +1,18 @@ | |||||||
| package com.owncloud.android.lib.common.http.methods.webdav | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
| 
 | 
 | ||||||
| import at.bitfire.dav4android.DavResource | import at.bitfire.dav4jvm.DavResource | ||||||
| import at.bitfire.dav4android.DavResponseCallback | import at.bitfire.dav4jvm.DavResponseCallback | ||||||
| import at.bitfire.dav4android.IF_MATCH_HEADER | import at.bitfire.dav4jvm.IF_MATCH_HEADER | ||||||
| import at.bitfire.dav4android.Property | import at.bitfire.dav4jvm.Property | ||||||
| import at.bitfire.dav4android.QuotedStringUtils | import at.bitfire.dav4jvm.QuotedStringUtils | ||||||
| import at.bitfire.dav4android.XmlUtils | import at.bitfire.dav4jvm.XmlUtils | ||||||
| import at.bitfire.dav4android.exception.DavException | import at.bitfire.dav4jvm.exception.DavException | ||||||
| import at.bitfire.dav4android.exception.HttpException | import at.bitfire.dav4jvm.exception.HttpException | ||||||
| import okhttp3.HttpUrl | import okhttp3.HttpUrl | ||||||
| import okhttp3.OkHttpClient | import okhttp3.OkHttpClient | ||||||
| import okhttp3.Request | import okhttp3.Request | ||||||
| import okhttp3.RequestBody | import okhttp3.RequestBody | ||||||
|  | import okhttp3.RequestBody.Companion.toRequestBody | ||||||
| import okhttp3.Response | import okhttp3.Response | ||||||
| import java.io.IOException | import java.io.IOException | ||||||
| import java.io.StringWriter | import java.io.StringWriter | ||||||
| @ -162,9 +163,9 @@ class OCDavResource( | |||||||
|         listOfHeaders: HashMap<String, String?>?, |         listOfHeaders: HashMap<String, String?>?, | ||||||
|         callback: (response: Response) -> Unit |         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() |         val requestBuilder = Request.Builder() | ||||||
|             .method("MKCOL", rqBody) |             .method("MKCOL", requestBody) | ||||||
|             .url(location) |             .url(location) | ||||||
|         listOfHeaders?.forEach { (name, value) -> |         listOfHeaders?.forEach { (name, value) -> | ||||||
|             value?.let { |             value?.let { | ||||||
| @ -264,7 +265,7 @@ class OCDavResource( | |||||||
|         }.use { response -> |         }.use { response -> | ||||||
|             callback(response) |             callback(response) | ||||||
|             checkStatus(response) |             checkStatus(response) | ||||||
|             if (response.code() == 207) |             if (response.code == 207) | ||||||
|             /* If an error occurs deleting a member resource (a resource other than |             /* If an error occurs deleting a member resource (a resource other than | ||||||
|                the resource identified in the Request-URI), then the response can be |                the resource identified in the Request-URI), then the response can be | ||||||
|                a 207 (Multi-Status). […] (RFC 4918 9.6.1. DELETE for Collections) */ |                a 207 (Multi-Status). […] (RFC 4918 9.6.1. DELETE for Collections) */ | ||||||
| @ -316,7 +317,7 @@ class OCDavResource( | |||||||
| 
 | 
 | ||||||
|         val requestBuilder = Request.Builder() |         val requestBuilder = Request.Builder() | ||||||
|             .url(location) |             .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") |             .header("Depth", if (depth >= 0) depth.toString() else "infinity") | ||||||
| 
 | 
 | ||||||
|         listOfHeaders?.forEach { (name, value) -> |         listOfHeaders?.forEach { (name, value) -> | ||||||
|  | |||||||
| @ -23,10 +23,10 @@ | |||||||
|  */ |  */ | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
| 
 | 
 | ||||||
| import at.bitfire.dav4android.Property | import at.bitfire.dav4jvm.Property | ||||||
| import at.bitfire.dav4android.Response | import at.bitfire.dav4jvm.Response | ||||||
| import at.bitfire.dav4android.Response.HrefRelation | import at.bitfire.dav4jvm.Response.HrefRelation | ||||||
| import at.bitfire.dav4android.exception.DavException | import at.bitfire.dav4jvm.exception.DavException | ||||||
| import java.io.IOException | import java.io.IOException | ||||||
| import java.net.URL | import java.net.URL | ||||||
| import java.util.ArrayList | import java.util.ArrayList | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ | |||||||
|  */ |  */ | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav | 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 com.owncloud.android.lib.common.http.HttpConstants | ||||||
| import java.io.IOException | import java.io.IOException | ||||||
| import java.net.URL | 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.OwnCloudClient; | ||||||
| import com.owncloud.android.lib.common.accounts.AccountUtils; | import com.owncloud.android.lib.common.accounts.AccountUtils; | ||||||
| import com.owncloud.android.lib.common.http.HttpConstants; | 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.network.WebdavUtils; | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperation; | import com.owncloud.android.lib.common.operations.RemoteOperation; | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | 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.accounts.AccountUtils; | ||||||
| import com.owncloud.android.lib.common.http.HttpConstants; | 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.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.network.WebdavUtils; | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperation; | import com.owncloud.android.lib.common.operations.RemoteOperation; | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||||
| @ -120,7 +122,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation<ArrayList<RemoteF | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private boolean isSuccess(int status) { |     private boolean isSuccess(int status) { | ||||||
|         return status == HttpConstants.HTTP_MULTI_STATUS || |         return status == HttpConstants.HTTP_MULTI_STATUS || status == HttpConstants.HTTP_OK; | ||||||
|                 status == HttpConstants.HTTP_OK; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user