mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
remove redundant intercept of httpclient with httpmethod
This commit is contained in:
parent
344c1e1136
commit
fc4ae27bbe
@ -135,10 +135,10 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
|
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
|
||||||
}
|
}
|
||||||
|
|
||||||
status = method.execute();
|
status = method.execute(this);
|
||||||
|
|
||||||
if (shouldConnectionValidatorBeCalled(method, status)) {
|
if (shouldConnectionValidatorBeCalled(method, status)) {
|
||||||
retry = mConnectionValidator.validate(this, mSingleSessionManager); // retry on success fail on no success
|
retry = mConnectionValidator.validate(this, mSingleSessionManager, getContext()); // retry on success fail on no success
|
||||||
} else if(method.getFollowPermanentRedirects() && status == HTTP_MOVED_PERMANENTLY) {
|
} else if(method.getFollowPermanentRedirects() && status == HTTP_MOVED_PERMANENTLY) {
|
||||||
retry = true;
|
retry = true;
|
||||||
method.setFollowRedirects(true);
|
method.setFollowRedirects(true);
|
||||||
|
@ -37,25 +37,40 @@ import java.net.MalformedURLException
|
|||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
abstract class HttpBaseMethod constructor(clientWrapper: HttpClient, url: URL) {
|
abstract class HttpBaseMethod constructor(url: URL) {
|
||||||
var okHttpClient: OkHttpClient
|
|
||||||
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
||||||
var request: Request
|
var request: Request
|
||||||
private var _followPermanentRedirects = false
|
private var _followPermanentRedirects = false
|
||||||
abstract var response: Response
|
abstract var response: Response
|
||||||
|
|
||||||
var call: Call? = null
|
var call: Call? = null
|
||||||
|
|
||||||
|
var followRedirects: Boolean? = true
|
||||||
|
var retryOnConnectionFailure: Boolean? = false
|
||||||
|
var connectionTimeoutVal: Long? = null
|
||||||
|
var connectionTimeoutUnit: TimeUnit? = null
|
||||||
|
var readTimeoutVal: Long? = null
|
||||||
|
var readTimeoutUnit: TimeUnit? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
okHttpClient = clientWrapper.okHttpClient
|
|
||||||
request = Request.Builder()
|
request = Request.Builder()
|
||||||
.url(httpUrl)
|
.url(httpUrl)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
open fun execute(): Int {
|
open fun execute(httpClient: HttpClient): Int {
|
||||||
return onExecute()
|
val okHttpClient = httpClient.okHttpClient.newBuilder().apply {
|
||||||
|
retryOnConnectionFailure?.let { retryOnConnectionFailure(it) }
|
||||||
|
followRedirects?.let { followRedirects(it) }
|
||||||
|
readTimeoutUnit?.let { unit ->
|
||||||
|
readTimeoutVal?.let { readTimeout(it, unit) }
|
||||||
|
}
|
||||||
|
connectionTimeoutUnit?.let { unit ->
|
||||||
|
connectionTimeoutVal?.let { connectTimeout(it, unit) }
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
|
||||||
|
return onExecute(okHttpClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun setUrl(url: HttpUrl) {
|
open fun setUrl(url: HttpUrl) {
|
||||||
@ -137,42 +152,26 @@ abstract class HttpBaseMethod constructor(clientWrapper: HttpClient, url: URL) {
|
|||||||
// Setter
|
// Setter
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
// Connection parameters
|
// Connection parameters
|
||||||
|
/*
|
||||||
open fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
|
open fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
|
||||||
okHttpClient = okHttpClient.newBuilder()
|
retryOnConnectionFailureVal = true
|
||||||
.retryOnConnectionFailure(retryOnConnectionFailure)
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
open fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
|
open fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
|
||||||
okHttpClient = okHttpClient.newBuilder()
|
readTimeoutVal = readTimeout
|
||||||
.readTimeout(readTimeout, timeUnit)
|
readTimeoutUnit = timeUnit
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun setConnectionTimeout(
|
open fun setConnectionTimeout(
|
||||||
connectionTimeout: Long,
|
connectionTimeout: Long,
|
||||||
timeUnit: TimeUnit
|
timeUnit: TimeUnit
|
||||||
) {
|
) {
|
||||||
okHttpClient = okHttpClient.newBuilder()
|
connectionTimeoutVal = connectionTimeout
|
||||||
.readTimeout(connectionTimeout, timeUnit)
|
connectionTimeoutUnit = timeUnit
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun setFollowRedirects(followRedirects: Boolean) {
|
|
||||||
okHttpClient = okHttpClient.newBuilder()
|
|
||||||
.followRedirects(followRedirects)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun getFollowRedirects() = okHttpClient.followRedirects
|
|
||||||
|
|
||||||
open fun setFollowPermanentRedirects(followRedirects: Boolean) {
|
|
||||||
_followPermanentRedirects = followRedirects
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun getFollowPermanentRedirects() = _followPermanentRedirects
|
|
||||||
|
|
||||||
|
|
||||||
/************
|
/************
|
||||||
*** Call ***
|
*** Call ***
|
||||||
************/
|
************/
|
||||||
@ -187,5 +186,5 @@ abstract class HttpBaseMethod constructor(clientWrapper: HttpClient, url: URL) {
|
|||||||
// For override
|
// For override
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
protected abstract fun onExecute(): Int
|
protected abstract fun onExecute(okHttpClient: OkHttpClient): Int
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
import okhttp3.OkHttpClient
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -32,12 +32,12 @@ import java.net.URL
|
|||||||
*
|
*
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class DeleteMethod(httpClient: HttpClient, url: URL) : HttpMethod(httpClient, url) {
|
class DeleteMethod(url: URL) : HttpMethod(url) {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun onExecute(): Int {
|
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||||
request = request.newBuilder()
|
request = request.newBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.build()
|
.build()
|
||||||
return super.onExecute()
|
return super.onExecute(okHttpClient)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
import okhttp3.OkHttpClient
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -32,12 +32,12 @@ import java.net.URL
|
|||||||
*
|
*
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class GetMethod(httpClient: HttpClient, url: URL) : HttpMethod(httpClient, url) {
|
class GetMethod(url: URL) : HttpMethod(url) {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun onExecute(): Int {
|
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||||
request = request.newBuilder()
|
request = request.newBuilder()
|
||||||
.get()
|
.get()
|
||||||
.build()
|
.build()
|
||||||
return super.onExecute()
|
return super.onExecute(okHttpClient)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
|
||||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
|
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -34,13 +34,12 @@ import java.net.URL
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
abstract class HttpMethod(
|
abstract class HttpMethod(
|
||||||
httpClient: HttpClient,
|
|
||||||
url: URL
|
url: URL
|
||||||
) : HttpBaseMethod(httpClient, url) {
|
) : HttpBaseMethod(url) {
|
||||||
|
|
||||||
override lateinit var response: Response
|
override lateinit var response: Response
|
||||||
|
|
||||||
public override fun onExecute(): Int {
|
public override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||||
call = okHttpClient.newCall(request)
|
call = okHttpClient.newCall(request)
|
||||||
call?.let { response = it.execute() }
|
call?.let { response = it.execute() }
|
||||||
return super.statusCode
|
return super.statusCode
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
@ -34,15 +34,14 @@ import java.net.URL
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class PostMethod(
|
class PostMethod(
|
||||||
httpClient: HttpClient,
|
|
||||||
url: URL,
|
url: URL,
|
||||||
private val postRequestBody: RequestBody
|
private val postRequestBody: RequestBody
|
||||||
) : HttpMethod(httpClient, url) {
|
) : HttpMethod(url) {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun onExecute(): Int {
|
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||||
request = request.newBuilder()
|
request = request.newBuilder()
|
||||||
.post(postRequestBody)
|
.post(postRequestBody)
|
||||||
.build()
|
.build()
|
||||||
return super.onExecute()
|
return super.onExecute(okHttpClient)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
@ -34,15 +34,14 @@ import java.net.URL
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class PutMethod(
|
class PutMethod(
|
||||||
httpClient: HttpClient,
|
|
||||||
url: URL,
|
url: URL,
|
||||||
private val putRequestBody: RequestBody
|
private val putRequestBody: RequestBody
|
||||||
) : HttpMethod(httpClient, url) {
|
) : HttpMethod(url) {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun onExecute(): Int {
|
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||||
request = request.newBuilder()
|
request = request.newBuilder()
|
||||||
.put(putRequestBody)
|
.put(putRequestBody)
|
||||||
.build()
|
.build()
|
||||||
return super.onExecute()
|
return super.onExecute(okHttpClient)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
import at.bitfire.dav4jvm.DavOCResource
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -34,13 +34,12 @@ import java.net.URL
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class CopyMethod(
|
class CopyMethod(
|
||||||
httpClient: HttpClient,
|
|
||||||
val url: URL,
|
val url: URL,
|
||||||
private val destinationUrl: String,
|
private val destinationUrl: String,
|
||||||
private val forceOverride: Boolean
|
private val forceOverride: Boolean
|
||||||
) : DavMethod(httpClient, url) {
|
) : DavMethod(url) {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
public override fun onExecute(): Int {
|
public override fun onDavExecute(davResource: DavOCResource): Int {
|
||||||
davResource.copy(
|
davResource.copy(
|
||||||
destinationUrl,
|
destinationUrl,
|
||||||
forceOverride,
|
forceOverride,
|
||||||
|
@ -27,45 +27,39 @@ import at.bitfire.dav4jvm.Dav4jvm.log
|
|||||||
import at.bitfire.dav4jvm.DavOCResource
|
import at.bitfire.dav4jvm.DavOCResource
|
||||||
import at.bitfire.dav4jvm.exception.HttpException
|
import at.bitfire.dav4jvm.exception.HttpException
|
||||||
import at.bitfire.dav4jvm.exception.RedirectException
|
import at.bitfire.dav4jvm.exception.RedirectException
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
|
||||||
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.OkHttpClient
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
|
||||||
import okhttp3.Protocol
|
import okhttp3.Protocol
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||||
import java.net.MalformedURLException
|
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper to perform WebDAV (dav4android) calls
|
* Wrapper to perform WebDAV (dav4android) calls
|
||||||
*
|
*
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
abstract class DavMethod protected constructor(httpClient: HttpClient, url: URL) : HttpBaseMethod(httpClient, url) {
|
abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||||
protected var davResource: DavOCResource
|
|
||||||
|
|
||||||
override lateinit var response: Response
|
override lateinit var response: Response
|
||||||
|
private var davResource: DavOCResource? = null
|
||||||
init {
|
|
||||||
val httpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
|
||||||
davResource = DavOCResource(
|
|
||||||
okHttpClient,
|
|
||||||
httpUrl,
|
|
||||||
log
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun abort() {
|
override fun abort() {
|
||||||
davResource.cancelCall()
|
davResource?.cancelCall()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract fun onDavExecute(davResource: DavOCResource): Int
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun execute(): Int {
|
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||||
return try {
|
return try {
|
||||||
onExecute()
|
davResource = DavOCResource(
|
||||||
|
okHttpClient.newBuilder().followRedirects(false).build(),
|
||||||
|
httpUrl,
|
||||||
|
log
|
||||||
|
)
|
||||||
|
|
||||||
|
onDavExecute(davResource!!)
|
||||||
} catch (httpException: HttpException) {
|
} catch (httpException: HttpException) {
|
||||||
// Modify responses with information gathered from exceptions
|
// Modify responses with information gathered from exceptions
|
||||||
if (httpException is RedirectException) {
|
if (httpException is RedirectException) {
|
||||||
@ -92,71 +86,12 @@ abstract class DavMethod protected constructor(httpClient: HttpClient, url: URL)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
|
||||||
// Setter
|
|
||||||
//////////////////////////////
|
|
||||||
// Connection parameters
|
|
||||||
override fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
|
|
||||||
super.setReadTimeout(readTimeout, timeUnit)
|
|
||||||
davResource = DavOCResource(
|
|
||||||
okHttpClient,
|
|
||||||
request.url,
|
|
||||||
log
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setConnectionTimeout(
|
|
||||||
connectionTimeout: Long,
|
|
||||||
timeUnit: TimeUnit
|
|
||||||
) {
|
|
||||||
super.setConnectionTimeout(connectionTimeout, timeUnit)
|
|
||||||
davResource = DavOCResource(
|
|
||||||
okHttpClient,
|
|
||||||
request.url,
|
|
||||||
log
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setFollowRedirects(followRedirects: Boolean) {
|
|
||||||
super.setFollowRedirects(followRedirects)
|
|
||||||
davResource = DavOCResource(
|
|
||||||
okHttpClient,
|
|
||||||
request.url,
|
|
||||||
log
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setUrl(url: HttpUrl) {
|
|
||||||
super.setUrl(url)
|
|
||||||
davResource = DavOCResource(
|
|
||||||
okHttpClient,
|
|
||||||
request.url,
|
|
||||||
log
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setRequestHeader(name: String, value: String) {
|
|
||||||
super.setRequestHeader(name, value)
|
|
||||||
davResource = DavOCResource(
|
|
||||||
okHttpClient,
|
|
||||||
request.url,
|
|
||||||
log
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
// Getter
|
// Getter
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
override fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
|
|
||||||
super.setRetryOnConnectionFailure(retryOnConnectionFailure)
|
|
||||||
davResource = DavOCResource(
|
|
||||||
okHttpClient,
|
|
||||||
request.url,
|
|
||||||
log
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override val isAborted: Boolean
|
override val isAborted: Boolean
|
||||||
get() = davResource.isCallAborted()
|
get() = davResource?.isCallAborted() ?: false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
import at.bitfire.dav4jvm.DavOCResource
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -33,9 +33,9 @@ import java.net.URL
|
|||||||
* @author Christian Schabesberger
|
* @author Christian Schabesberger
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class MkColMethod(httpClient: HttpClient, url: URL) : DavMethod(httpClient, url) {
|
class MkColMethod(url: URL) : DavMethod(url) {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
public override fun onExecute(): Int {
|
public override fun onDavExecute(davResource: DavOCResource): Int {
|
||||||
davResource.mkCol(
|
davResource.mkCol(
|
||||||
xmlBody = null,
|
xmlBody = null,
|
||||||
listOfHeaders = super.getRequestHeadersAsHashMap()
|
listOfHeaders = super.getRequestHeadersAsHashMap()
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
import at.bitfire.dav4jvm.DavOCResource
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -34,13 +34,12 @@ import java.net.URL
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class MoveMethod(
|
class MoveMethod(
|
||||||
httpClient: HttpClient,
|
|
||||||
url: URL,
|
url: URL,
|
||||||
private val destinationUrl: String,
|
private val destinationUrl: String,
|
||||||
private val forceOverride: Boolean
|
private val forceOverride: Boolean
|
||||||
) : DavMethod(httpClient, url) {
|
) : DavMethod(url) {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
public override fun onExecute(): Int {
|
override fun onDavExecute(davResource: DavOCResource): Int {
|
||||||
davResource.move(
|
davResource.move(
|
||||||
destinationUrl,
|
destinationUrl,
|
||||||
forceOverride,
|
forceOverride,
|
||||||
|
@ -23,11 +23,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
|
import at.bitfire.dav4jvm.DavOCResource
|
||||||
import at.bitfire.dav4jvm.Property
|
import at.bitfire.dav4jvm.Property
|
||||||
import at.bitfire.dav4jvm.Response
|
import at.bitfire.dav4jvm.Response
|
||||||
import at.bitfire.dav4jvm.Response.HrefRelation
|
import at.bitfire.dav4jvm.Response.HrefRelation
|
||||||
import at.bitfire.dav4jvm.exception.DavException
|
import at.bitfire.dav4jvm.exception.DavException
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
@ -37,11 +37,10 @@ import java.net.URL
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class PropfindMethod(
|
class PropfindMethod(
|
||||||
httpClient: HttpClient,
|
|
||||||
url: URL,
|
url: URL,
|
||||||
private val depth: Int,
|
private val depth: Int,
|
||||||
private val propertiesToRequest: Array<Property.Name>
|
private val propertiesToRequest: Array<Property.Name>
|
||||||
) : DavMethod(httpClient, url) {
|
) : DavMethod(url) {
|
||||||
|
|
||||||
// response
|
// response
|
||||||
val members: MutableList<Response>
|
val members: MutableList<Response>
|
||||||
@ -49,7 +48,7 @@ class PropfindMethod(
|
|||||||
private set
|
private set
|
||||||
|
|
||||||
@Throws(IOException::class, DavException::class)
|
@Throws(IOException::class, DavException::class)
|
||||||
public override fun onExecute(): Int {
|
public override fun onDavExecute(davResource: DavOCResource): Int {
|
||||||
davResource.propfind(
|
davResource.propfind(
|
||||||
depth = depth,
|
depth = depth,
|
||||||
reqProp = propertiesToRequest,
|
reqProp = propertiesToRequest,
|
||||||
|
@ -23,8 +23,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.common.http.methods.webdav
|
package com.owncloud.android.lib.common.http.methods.webdav
|
||||||
|
|
||||||
|
import at.bitfire.dav4jvm.DavOCResource
|
||||||
import at.bitfire.dav4jvm.exception.HttpException
|
import at.bitfire.dav4jvm.exception.HttpException
|
||||||
import com.owncloud.android.lib.common.http.HttpClient
|
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants
|
import com.owncloud.android.lib.common.http.HttpConstants
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -36,12 +36,11 @@ import java.net.URL
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class PutMethod(
|
class PutMethod(
|
||||||
httpClient: HttpClient,
|
|
||||||
url: URL,
|
url: URL,
|
||||||
private val putRequestBody: RequestBody
|
private val putRequestBody: RequestBody
|
||||||
) : DavMethod(httpClient, url) {
|
) : DavMethod(url) {
|
||||||
@Throws(IOException::class, HttpException::class)
|
@Throws(IOException::class, HttpException::class)
|
||||||
public override fun onExecute(): Int {
|
public override fun onDavExecute(davResource: DavOCResource): Int {
|
||||||
davResource.put(
|
davResource.put(
|
||||||
putRequestBody,
|
putRequestBody,
|
||||||
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
|
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
|
||||||
|
@ -57,11 +57,15 @@ class CheckPathExistenceRemoteOperation(
|
|||||||
if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
|
if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
|
||||||
else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)
|
else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)
|
||||||
|
|
||||||
val propFindMethod = PropfindMethod(client, URL(stringUrl), 0, allPropset).apply {
|
val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropset).apply {
|
||||||
setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
||||||
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
propFindMethod.followRedirects = false
|
||||||
|
>>>>>>> 27ecf79c (remove redundant intercept of httpclient with httpmethod)
|
||||||
var status = client.executeHttpMethod(propFindMethod)
|
var status = client.executeHttpMethod(propFindMethod)
|
||||||
/* PROPFIND method
|
/* PROPFIND method
|
||||||
* 404 NOT FOUND: path doesn't exist,
|
* 404 NOT FOUND: path doesn't exist,
|
||||||
|
@ -92,7 +92,7 @@ public class CopyRemoteFileOperation extends RemoteOperation<String> {
|
|||||||
RemoteOperationResult result;
|
RemoteOperationResult result;
|
||||||
try {
|
try {
|
||||||
CopyMethod copyMethod =
|
CopyMethod copyMethod =
|
||||||
new CopyMethod(client,
|
new CopyMethod(
|
||||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||||
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||||
mOverwrite);
|
mOverwrite);
|
||||||
|
@ -87,7 +87,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|||||||
RemoteOperationResult result;
|
RemoteOperationResult result;
|
||||||
try {
|
try {
|
||||||
Uri webDavUri = createChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
Uri webDavUri = createChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
||||||
final MkColMethod mkcol = new MkColMethod(client,
|
final MkColMethod mkcol = new MkColMethod(
|
||||||
new URL(webDavUri + WebdavUtils.encodePath(mRemotePath)));
|
new URL(webDavUri + WebdavUtils.encodePath(mRemotePath)));
|
||||||
mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
|
mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
|
||||||
mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
||||||
|
@ -96,7 +96,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
|
|||||||
RemoteOperationResult result;
|
RemoteOperationResult result;
|
||||||
int status;
|
int status;
|
||||||
boolean savedFile = false;
|
boolean savedFile = false;
|
||||||
mGet = new GetMethod(client, new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)));
|
mGet = new GetMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)));
|
||||||
Iterator<OnDatatransferProgressListener> it;
|
Iterator<OnDatatransferProgressListener> it;
|
||||||
|
|
||||||
FileOutputStream fos = null;
|
FileOutputStream fos = null;
|
||||||
|
@ -100,7 +100,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
// so this uri has to be customizable
|
// so this uri has to be customizable
|
||||||
Uri srcWebDavUri = moveChunkedFile ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
Uri srcWebDavUri = moveChunkedFile ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
||||||
|
|
||||||
final MoveMethod move = new MoveMethod(client,
|
final MoveMethod move = new MoveMethod(
|
||||||
new URL(srcWebDavUri + WebdavUtils.encodePath(mSrcRemotePath)),
|
new URL(srcWebDavUri + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||||
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||||
mOverwrite);
|
mOverwrite);
|
||||||
|
@ -76,7 +76,7 @@ public class ReadRemoteFileOperation extends RemoteOperation<RemoteFile> {
|
|||||||
/// take the duty of check the server for the current state of the file there
|
/// take the duty of check the server for the current state of the file there
|
||||||
try {
|
try {
|
||||||
// remote request
|
// remote request
|
||||||
propfind = new PropfindMethod(client,
|
propfind = new PropfindMethod(
|
||||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||||
DEPTH_0,
|
DEPTH_0,
|
||||||
DavUtils.getAllPropset());
|
DavUtils.getAllPropset());
|
||||||
|
@ -73,7 +73,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation<ArrayList<RemoteF
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
PropfindMethod propfindMethod = new PropfindMethod(
|
PropfindMethod propfindMethod = new PropfindMethod(
|
||||||
client,
|
|
||||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||||
DavConstants.DEPTH_1,
|
DavConstants.DEPTH_1,
|
||||||
DavUtils.getAllPropset());
|
DavUtils.getAllPropset());
|
||||||
|
@ -72,7 +72,6 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
|
|||||||
Uri srcWebDavUri = removeChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
Uri srcWebDavUri = removeChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
||||||
|
|
||||||
DeleteMethod deleteMethod = new DeleteMethod(
|
DeleteMethod deleteMethod = new DeleteMethod(
|
||||||
client,
|
|
||||||
new URL(srcWebDavUri + WebdavUtils.encodePath(mRemotePath)));
|
new URL(srcWebDavUri + WebdavUtils.encodePath(mRemotePath)));
|
||||||
|
|
||||||
int status = client.executeHttpMethod(deleteMethod);
|
int status = client.executeHttpMethod(deleteMethod);
|
||||||
|
@ -91,7 +91,7 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
return new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
return new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
final MoveMethod move = new MoveMethod(client,
|
final MoveMethod move = new MoveMethod(
|
||||||
new URL(client.getUserFilesWebDavUri() +
|
new URL(client.getUserFilesWebDavUri() +
|
||||||
WebdavUtils.encodePath(mOldRemotePath)),
|
WebdavUtils.encodePath(mOldRemotePath)),
|
||||||
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mNewRemotePath), false);
|
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mNewRemotePath), false);
|
||||||
|
@ -49,8 +49,8 @@ class UploadFileFromContentUriOperation(
|
|||||||
) : RemoteOperation<Unit>() {
|
) : RemoteOperation<Unit>() {
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
||||||
val putMethod = PutMethod(client, URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(uploadPath)), requestBody).apply {
|
val putMethod = PutMethod(URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(uploadPath)), requestBody).apply {
|
||||||
setRetryOnConnectionFailure(false)
|
retryOnConnectionFailure = false
|
||||||
addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, requestBody.contentLength().toString())
|
addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, requestBody.contentLength().toString())
|
||||||
addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, lastModified)
|
addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, lastModified)
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
|||||||
mFileRequestBody.addDatatransferProgressListeners(mDataTransferListeners);
|
mFileRequestBody.addDatatransferProgressListeners(mDataTransferListeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
mPutMethod = new PutMethod(client,
|
mPutMethod = new PutMethod(
|
||||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), mFileRequestBody);
|
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), mFileRequestBody);
|
||||||
|
|
||||||
mPutMethod.setRetryOnConnectionFailure(false);
|
mPutMethod.setRetryOnConnectionFailure(false);
|
||||||
|
@ -92,7 +92,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
|||||||
result = new RemoteOperationResult<>(new OperationCancelledException());
|
result = new RemoteOperationResult<>(new OperationCancelledException());
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
mPutMethod = new PutMethod(client,
|
mPutMethod = new PutMethod(
|
||||||
new URL(uriPrefix + File.separator + chunkIndex), mFileRequestBody);
|
new URL(uriPrefix + File.separator + chunkIndex), mFileRequestBody);
|
||||||
|
|
||||||
if (chunkIndex == chunkCount - 1) {
|
if (chunkIndex == chunkCount - 1) {
|
||||||
|
@ -51,7 +51,7 @@ class GetOIDCDiscoveryRemoteOperation : RemoteOperation<OIDCDiscoveryResponse>()
|
|||||||
appendPath(OPENID_CONFIGURATION_RESOURCE)
|
appendPath(OPENID_CONFIGURATION_RESOURCE)
|
||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
val getMethod = GetMethod(client, URL(uriBuilder.toString())).apply {
|
val getMethod = GetMethod(URL(uriBuilder.toString())).apply {
|
||||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@ class RegisterClientRemoteOperation(
|
|||||||
val requestBody = clientRegistrationParams.toRequestBody()
|
val requestBody = clientRegistrationParams.toRequestBody()
|
||||||
|
|
||||||
val postMethod = PostMethod(
|
val postMethod = PostMethod(
|
||||||
httpClient = client,
|
|
||||||
url = URL(clientRegistrationParams.registrationEndpoint),
|
url = URL(clientRegistrationParams.registrationEndpoint),
|
||||||
postRequestBody = requestBody
|
postRequestBody = requestBody
|
||||||
)
|
)
|
||||||
|
@ -52,7 +52,7 @@ class TokenRequestRemoteOperation(
|
|||||||
try {
|
try {
|
||||||
val requestBody = tokenRequestParams.toRequestBody()
|
val requestBody = tokenRequestParams.toRequestBody()
|
||||||
|
|
||||||
val postMethod = PostMethod(client, URL(tokenRequestParams.tokenEndpoint), requestBody)
|
val postMethod = PostMethod(URL(tokenRequestParams.tokenEndpoint), requestBody)
|
||||||
|
|
||||||
postMethod.addRequestHeader(AUTHORIZATION_HEADER, tokenRequestParams.clientAuth)
|
postMethod.addRequestHeader(AUTHORIZATION_HEADER, tokenRequestParams.clientAuth)
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ class CreateRemoteShareOperation(
|
|||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
||||||
val requestUri = buildRequestUri(client.baseUri)
|
val requestUri = buildRequestUri(client.baseUri)
|
||||||
|
|
||||||
val postMethod = PostMethod(client, URL(requestUri.toString()), createFormBody()).apply {
|
val postMethod = PostMethod(URL(requestUri.toString()), createFormBody()).apply {
|
||||||
setRequestHeader(HttpConstants.CONTENT_TYPE_HEADER, HttpConstants.CONTENT_TYPE_URLENCODED_UTF8)
|
setRequestHeader(HttpConstants.CONTENT_TYPE_HEADER, HttpConstants.CONTENT_TYPE_URLENCODED_UTF8)
|
||||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||||
}
|
}
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
|
||||||
* @author David A. Velasco
|
|
||||||
* @author David González Verdugo
|
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.shares;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
|
||||||
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod;
|
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the data about a Share resource, known its remote ID.
|
|
||||||
*
|
|
||||||
* @author David A. Velasco
|
|
||||||
* @author David González Verdugo
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class GetRemoteShareOperation extends RemoteOperation<ShareParserResult> {
|
|
||||||
|
|
||||||
private String mRemoteId;
|
|
||||||
|
|
||||||
public GetRemoteShareOperation(String remoteId) {
|
|
||||||
mRemoteId = remoteId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
|
||||||
RemoteOperationResult<ShareParserResult> result;
|
|
||||||
|
|
||||||
try {
|
|
||||||
Uri requestUri = client.getBaseUri();
|
|
||||||
Uri.Builder uriBuilder = requestUri.buildUpon();
|
|
||||||
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
|
|
||||||
uriBuilder.appendEncodedPath(mRemoteId);
|
|
||||||
|
|
||||||
GetMethod getMethod = new GetMethod(client, new URL(uriBuilder.build().toString()));
|
|
||||||
getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
|
||||||
|
|
||||||
int status = client.executeHttpMethod(getMethod);
|
|
||||||
|
|
||||||
if (isSuccess(status)) {
|
|
||||||
// Parse xml response and obtain the list of shares
|
|
||||||
ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser(
|
|
||||||
new ShareXMLParser()
|
|
||||||
);
|
|
||||||
parser.setOneOrMoreSharesRequired(true);
|
|
||||||
parser.setOwnCloudVersion(client.getOwnCloudVersion());
|
|
||||||
parser.setServerBaseUri(client.getBaseUri());
|
|
||||||
result = parser.parse(getMethod.getResponseBodyAsString());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
result = new RemoteOperationResult<>(getMethod);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
result = new RemoteOperationResult<>(e);
|
|
||||||
Timber.e(e, "Exception while getting remote shares");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSuccess(int status) {
|
|
||||||
return (status == HttpConstants.HTTP_OK);
|
|
||||||
}
|
|
||||||
}
|
|
@ -131,7 +131,7 @@ class GetRemoteShareesOperation
|
|||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareeOcsResponse> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareeOcsResponse> {
|
||||||
val requestUri = buildRequestUri(client.baseUri)
|
val requestUri = buildRequestUri(client.baseUri)
|
||||||
|
|
||||||
val getMethod = GetMethod(client, URL(requestUri.toString()))
|
val getMethod = GetMethod(URL(requestUri.toString()))
|
||||||
getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
|
@ -119,7 +119,7 @@ class GetRemoteSharesForFileOperation(
|
|||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
||||||
val requestUri = buildRequestUri(client.baseUri)
|
val requestUri = buildRequestUri(client.baseUri)
|
||||||
|
|
||||||
val getMethod = GetMethod(client, URL(requestUri.toString())).apply {
|
val getMethod = GetMethod(URL(requestUri.toString())).apply {
|
||||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOper
|
|||||||
|
|
||||||
val requestUri = buildRequestUri(client.baseUri)
|
val requestUri = buildRequestUri(client.baseUri)
|
||||||
|
|
||||||
val deleteMethod = DeleteMethod(client, URL(requestUri.toString())).apply {
|
val deleteMethod = DeleteMethod(URL(requestUri.toString())).apply {
|
||||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,17 +195,17 @@ class UpdateRemoteShareOperation
|
|||||||
return formBodyBuilder
|
return formBodyBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
||||||
val requestUri = buildRequestUri(client.baseUri)
|
val requestUri = buildRequestUri(client.baseUri)
|
||||||
|
|
||||||
val formBodyBuilder = createFormBodyBuilder()
|
val formBodyBuilder = createFormBodyBuilder()
|
||||||
|
|
||||||
val putMethod = PutMethod(client, URL(requestUri.toString()), formBodyBuilder.build()).apply {
|
val putMethod = PutMethod(URL(requestUri.toString()), formBodyBuilder.build()).apply {
|
||||||
setRequestHeader(HttpConstants.CONTENT_TYPE_HEADER, HttpConstants.CONTENT_TYPE_URLENCODED_UTF8)
|
setRequestHeader(HttpConstants.CONTENT_TYPE_HEADER, HttpConstants.CONTENT_TYPE_URLENCODED_UTF8)
|
||||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val status = client.executeHttpMethod(putMethod)
|
val status = client.executeHttpMethod(putMethod)
|
||||||
val response = putMethod.getResponseBodyAsString()
|
val response = putMethod.getResponseBodyAsString()
|
||||||
|
@ -60,7 +60,7 @@ class GetRemoteCapabilitiesOperation : RemoteOperation<RemoteCapability>() {
|
|||||||
appendEncodedPath(OCS_ROUTE) // avoid starting "/" in this method
|
appendEncodedPath(OCS_ROUTE) // avoid starting "/" in this method
|
||||||
appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT)
|
appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT)
|
||||||
}
|
}
|
||||||
val getMethod = GetMethod(client, URL(uriBuilder.build().toString())).apply {
|
val getMethod = GetMethod(URL(uriBuilder.build().toString())).apply {
|
||||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||||
}
|
}
|
||||||
val status = client.executeHttpMethod(getMethod)
|
val status = client.executeHttpMethod(getMethod)
|
||||||
|
@ -65,7 +65,7 @@ internal class StatusRequester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getGetMethod(client: HttpClient, url: String): GetMethod {
|
private fun getGetMethod(client: HttpClient, url: String): GetMethod {
|
||||||
return GetMethod(client, URL(url)).apply {
|
return GetMethod(URL(url)).apply {
|
||||||
setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||||
setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class GetRemoteUserAvatarOperation(private val avatarDimension: Int) : RemoteOpe
|
|||||||
client.baseUri.toString() + NON_OFFICIAL_AVATAR_PATH + client.credentials.username + File.separator + avatarDimension
|
client.baseUri.toString() + NON_OFFICIAL_AVATAR_PATH + client.credentials.username + File.separator + avatarDimension
|
||||||
Timber.d("avatar URI: %s", endPoint)
|
Timber.d("avatar URI: %s", endPoint)
|
||||||
|
|
||||||
val getMethod = GetMethod(client, URL(endPoint))
|
val getMethod = GetMethod(URL(endPoint))
|
||||||
|
|
||||||
val status = client.executeHttpMethod(getMethod)
|
val status = client.executeHttpMethod(getMethod)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class GetRemoteUserInfoOperation : RemoteOperation<RemoteUserInfo>() {
|
|||||||
var result: RemoteOperationResult<RemoteUserInfo>
|
var result: RemoteOperationResult<RemoteUserInfo>
|
||||||
//Get the user
|
//Get the user
|
||||||
try {
|
try {
|
||||||
val getMethod = GetMethod(client, URL(client.baseUri.toString() + OCS_ROUTE))
|
val getMethod = GetMethod(URL(client.baseUri.toString() + OCS_ROUTE))
|
||||||
val status = client.executeHttpMethod(getMethod)
|
val status = client.executeHttpMethod(getMethod)
|
||||||
val response = getMethod.getResponseBodyAsString() ?: ""
|
val response = getMethod.getResponseBodyAsString() ?: ""
|
||||||
if (status == HttpConstants.HTTP_OK) {
|
if (status == HttpConstants.HTTP_OK) {
|
||||||
|
@ -50,7 +50,6 @@ class GetRemoteUserQuotaOperation : RemoteOperation<RemoteQuota>() {
|
|||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteQuota> =
|
override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteQuota> =
|
||||||
try {
|
try {
|
||||||
val propfindMethod = PropfindMethod(
|
val propfindMethod = PropfindMethod(
|
||||||
client,
|
|
||||||
URL(client.userFilesWebDavUri.toString()),
|
URL(client.userFilesWebDavUri.toString()),
|
||||||
DavConstants.DEPTH_0,
|
DavConstants.DEPTH_0,
|
||||||
DavUtils.quotaPropSet
|
DavUtils.quotaPropSet
|
||||||
|
Loading…
x
Reference in New Issue
Block a user