mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 07:56:19 +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());
|
||||
}
|
||||
|
||||
status = method.execute();
|
||||
status = method.execute(this);
|
||||
|
||||
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) {
|
||||
retry = true;
|
||||
method.setFollowRedirects(true);
|
||||
|
@ -37,25 +37,40 @@ import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
abstract class HttpBaseMethod constructor(clientWrapper: HttpClient, url: URL) {
|
||||
var okHttpClient: OkHttpClient
|
||||
abstract class HttpBaseMethod constructor(url: URL) {
|
||||
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
||||
var request: Request
|
||||
private var _followPermanentRedirects = false
|
||||
abstract var response: Response
|
||||
|
||||
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 {
|
||||
okHttpClient = clientWrapper.okHttpClient
|
||||
request = Request.Builder()
|
||||
.url(httpUrl)
|
||||
.build()
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
open fun execute(): Int {
|
||||
return onExecute()
|
||||
open fun execute(httpClient: HttpClient): Int {
|
||||
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) {
|
||||
@ -137,42 +152,26 @@ abstract class HttpBaseMethod constructor(clientWrapper: HttpClient, url: URL) {
|
||||
// Setter
|
||||
//////////////////////////////
|
||||
// Connection parameters
|
||||
/*
|
||||
open fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
|
||||
okHttpClient = okHttpClient.newBuilder()
|
||||
.retryOnConnectionFailure(retryOnConnectionFailure)
|
||||
.build()
|
||||
retryOnConnectionFailureVal = true
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
open fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
|
||||
okHttpClient = okHttpClient.newBuilder()
|
||||
.readTimeout(readTimeout, timeUnit)
|
||||
.build()
|
||||
readTimeoutVal = readTimeout
|
||||
readTimeoutUnit = timeUnit
|
||||
}
|
||||
|
||||
open fun setConnectionTimeout(
|
||||
connectionTimeout: Long,
|
||||
timeUnit: TimeUnit
|
||||
) {
|
||||
okHttpClient = okHttpClient.newBuilder()
|
||||
.readTimeout(connectionTimeout, timeUnit)
|
||||
.build()
|
||||
connectionTimeoutVal = connectionTimeout
|
||||
connectionTimeoutUnit = timeUnit
|
||||
}
|
||||
|
||||
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 ***
|
||||
************/
|
||||
@ -187,5 +186,5 @@ abstract class HttpBaseMethod constructor(clientWrapper: HttpClient, url: URL) {
|
||||
// For override
|
||||
//////////////////////////////
|
||||
@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
|
||||
|
||||
import com.owncloud.android.lib.common.http.HttpClient
|
||||
import okhttp3.OkHttpClient
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
|
||||
@ -32,12 +32,12 @@ import java.net.URL
|
||||
*
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class DeleteMethod(httpClient: HttpClient, url: URL) : HttpMethod(httpClient, url) {
|
||||
class DeleteMethod(url: URL) : HttpMethod(url) {
|
||||
@Throws(IOException::class)
|
||||
override fun onExecute(): Int {
|
||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||
request = request.newBuilder()
|
||||
.delete()
|
||||
.build()
|
||||
return super.onExecute()
|
||||
return super.onExecute(okHttpClient)
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
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.net.URL
|
||||
|
||||
@ -32,12 +32,12 @@ import java.net.URL
|
||||
*
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class GetMethod(httpClient: HttpClient, url: URL) : HttpMethod(httpClient, url) {
|
||||
class GetMethod(url: URL) : HttpMethod(url) {
|
||||
@Throws(IOException::class)
|
||||
override fun onExecute(): Int {
|
||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||
request = request.newBuilder()
|
||||
.get()
|
||||
.build()
|
||||
return super.onExecute()
|
||||
return super.onExecute(okHttpClient)
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,8 @@
|
||||
*/
|
||||
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 okhttp3.OkHttpClient
|
||||
import okhttp3.Response
|
||||
import java.net.URL
|
||||
|
||||
@ -34,13 +34,12 @@ import java.net.URL
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
abstract class HttpMethod(
|
||||
httpClient: HttpClient,
|
||||
url: URL
|
||||
) : HttpBaseMethod(httpClient, url) {
|
||||
) : HttpBaseMethod(url) {
|
||||
|
||||
override lateinit var response: Response
|
||||
|
||||
public override fun onExecute(): Int {
|
||||
public override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||
call = okHttpClient.newCall(request)
|
||||
call?.let { response = it.execute() }
|
||||
return super.statusCode
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||
|
||||
import com.owncloud.android.lib.common.http.HttpClient
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
@ -34,15 +34,14 @@ import java.net.URL
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class PostMethod(
|
||||
httpClient: HttpClient,
|
||||
url: URL,
|
||||
private val postRequestBody: RequestBody
|
||||
) : HttpMethod(httpClient, url) {
|
||||
) : HttpMethod(url) {
|
||||
@Throws(IOException::class)
|
||||
override fun onExecute(): Int {
|
||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||
request = request.newBuilder()
|
||||
.post(postRequestBody)
|
||||
.build()
|
||||
return super.onExecute()
|
||||
return super.onExecute(okHttpClient)
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||
|
||||
import com.owncloud.android.lib.common.http.HttpClient
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
@ -34,15 +34,14 @@ import java.net.URL
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class PutMethod(
|
||||
httpClient: HttpClient,
|
||||
url: URL,
|
||||
private val putRequestBody: RequestBody
|
||||
) : HttpMethod(httpClient, url) {
|
||||
) : HttpMethod(url) {
|
||||
@Throws(IOException::class)
|
||||
override fun onExecute(): Int {
|
||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||
request = request.newBuilder()
|
||||
.put(putRequestBody)
|
||||
.build()
|
||||
return super.onExecute()
|
||||
return super.onExecute(okHttpClient)
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
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 java.net.URL
|
||||
|
||||
@ -34,13 +34,12 @@ import java.net.URL
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class CopyMethod(
|
||||
httpClient: HttpClient,
|
||||
val url: URL,
|
||||
private val destinationUrl: String,
|
||||
private val forceOverride: Boolean
|
||||
) : DavMethod(httpClient, url) {
|
||||
) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onExecute(): Int {
|
||||
public override fun onDavExecute(davResource: DavOCResource): Int {
|
||||
davResource.copy(
|
||||
destinationUrl,
|
||||
forceOverride,
|
||||
|
@ -27,45 +27,39 @@ import at.bitfire.dav4jvm.Dav4jvm.log
|
||||
import at.bitfire.dav4jvm.DavOCResource
|
||||
import at.bitfire.dav4jvm.exception.HttpException
|
||||
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.methods.HttpBaseMethod
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Protocol
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Wrapper to perform WebDAV (dav4android) calls
|
||||
*
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
abstract class DavMethod protected constructor(httpClient: HttpClient, url: URL) : HttpBaseMethod(httpClient, url) {
|
||||
protected var davResource: DavOCResource
|
||||
|
||||
abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
override lateinit var response: Response
|
||||
|
||||
init {
|
||||
val httpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
||||
davResource = DavOCResource(
|
||||
okHttpClient,
|
||||
httpUrl,
|
||||
log
|
||||
)
|
||||
}
|
||||
private var davResource: DavOCResource? = null
|
||||
|
||||
override fun abort() {
|
||||
davResource.cancelCall()
|
||||
davResource?.cancelCall()
|
||||
}
|
||||
|
||||
protected abstract fun onDavExecute(davResource: DavOCResource): Int
|
||||
|
||||
@Throws(Exception::class)
|
||||
override fun execute(): Int {
|
||||
override fun onExecute(okHttpClient: OkHttpClient): Int {
|
||||
return try {
|
||||
onExecute()
|
||||
davResource = DavOCResource(
|
||||
okHttpClient.newBuilder().followRedirects(false).build(),
|
||||
httpUrl,
|
||||
log
|
||||
)
|
||||
|
||||
onDavExecute(davResource!!)
|
||||
} catch (httpException: HttpException) {
|
||||
// Modify responses with information gathered from exceptions
|
||||
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
|
||||
//////////////////////////////
|
||||
override fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
|
||||
super.setRetryOnConnectionFailure(retryOnConnectionFailure)
|
||||
davResource = DavOCResource(
|
||||
okHttpClient,
|
||||
request.url,
|
||||
log
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
override val isAborted: Boolean
|
||||
get() = davResource.isCallAborted()
|
||||
get() = davResource?.isCallAborted() ?: false
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
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 java.net.URL
|
||||
|
||||
@ -33,9 +33,9 @@ import java.net.URL
|
||||
* @author Christian Schabesberger
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class MkColMethod(httpClient: HttpClient, url: URL) : DavMethod(httpClient, url) {
|
||||
class MkColMethod(url: URL) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onExecute(): Int {
|
||||
public override fun onDavExecute(davResource: DavOCResource): Int {
|
||||
davResource.mkCol(
|
||||
xmlBody = null,
|
||||
listOfHeaders = super.getRequestHeadersAsHashMap()
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
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 java.net.URL
|
||||
|
||||
@ -34,13 +34,12 @@ import java.net.URL
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class MoveMethod(
|
||||
httpClient: HttpClient,
|
||||
url: URL,
|
||||
private val destinationUrl: String,
|
||||
private val forceOverride: Boolean
|
||||
) : DavMethod(httpClient, url) {
|
||||
) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onExecute(): Int {
|
||||
override fun onDavExecute(davResource: DavOCResource): Int {
|
||||
davResource.move(
|
||||
destinationUrl,
|
||||
forceOverride,
|
||||
|
@ -23,11 +23,11 @@
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.webdav
|
||||
|
||||
import at.bitfire.dav4jvm.DavOCResource
|
||||
import at.bitfire.dav4jvm.Property
|
||||
import at.bitfire.dav4jvm.Response
|
||||
import at.bitfire.dav4jvm.Response.HrefRelation
|
||||
import at.bitfire.dav4jvm.exception.DavException
|
||||
import com.owncloud.android.lib.common.http.HttpClient
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
|
||||
@ -37,11 +37,10 @@ import java.net.URL
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class PropfindMethod(
|
||||
httpClient: HttpClient,
|
||||
url: URL,
|
||||
private val depth: Int,
|
||||
private val propertiesToRequest: Array<Property.Name>
|
||||
) : DavMethod(httpClient, url) {
|
||||
) : DavMethod(url) {
|
||||
|
||||
// response
|
||||
val members: MutableList<Response>
|
||||
@ -49,7 +48,7 @@ class PropfindMethod(
|
||||
private set
|
||||
|
||||
@Throws(IOException::class, DavException::class)
|
||||
public override fun onExecute(): Int {
|
||||
public override fun onDavExecute(davResource: DavOCResource): Int {
|
||||
davResource.propfind(
|
||||
depth = depth,
|
||||
reqProp = propertiesToRequest,
|
||||
|
@ -23,8 +23,8 @@
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.webdav
|
||||
|
||||
import at.bitfire.dav4jvm.DavOCResource
|
||||
import at.bitfire.dav4jvm.exception.HttpException
|
||||
import com.owncloud.android.lib.common.http.HttpClient
|
||||
import com.owncloud.android.lib.common.http.HttpConstants
|
||||
import okhttp3.RequestBody
|
||||
import java.io.IOException
|
||||
@ -36,12 +36,11 @@ import java.net.URL
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class PutMethod(
|
||||
httpClient: HttpClient,
|
||||
url: URL,
|
||||
private val putRequestBody: RequestBody
|
||||
) : DavMethod(httpClient, url) {
|
||||
) : DavMethod(url) {
|
||||
@Throws(IOException::class, HttpException::class)
|
||||
public override fun onExecute(): Int {
|
||||
public override fun onDavExecute(davResource: DavOCResource): Int {
|
||||
davResource.put(
|
||||
putRequestBody,
|
||||
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
|
||||
|
@ -57,11 +57,15 @@ class CheckPathExistenceRemoteOperation(
|
||||
if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
|
||||
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)
|
||||
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
propFindMethod.followRedirects = false
|
||||
>>>>>>> 27ecf79c (remove redundant intercept of httpclient with httpmethod)
|
||||
var status = client.executeHttpMethod(propFindMethod)
|
||||
/* PROPFIND method
|
||||
* 404 NOT FOUND: path doesn't exist,
|
||||
|
@ -92,7 +92,7 @@ public class CopyRemoteFileOperation extends RemoteOperation<String> {
|
||||
RemoteOperationResult result;
|
||||
try {
|
||||
CopyMethod copyMethod =
|
||||
new CopyMethod(client,
|
||||
new CopyMethod(
|
||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
mOverwrite);
|
||||
|
@ -87,7 +87,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
||||
RemoteOperationResult result;
|
||||
try {
|
||||
Uri webDavUri = createChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
||||
final MkColMethod mkcol = new MkColMethod(client,
|
||||
final MkColMethod mkcol = new MkColMethod(
|
||||
new URL(webDavUri + WebdavUtils.encodePath(mRemotePath)));
|
||||
mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
||||
|
@ -96,7 +96,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
|
||||
RemoteOperationResult result;
|
||||
int status;
|
||||
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;
|
||||
|
||||
FileOutputStream fos = null;
|
||||
|
@ -100,7 +100,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
||||
// so this uri has to be customizable
|
||||
Uri srcWebDavUri = moveChunkedFile ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
||||
|
||||
final MoveMethod move = new MoveMethod(client,
|
||||
final MoveMethod move = new MoveMethod(
|
||||
new URL(srcWebDavUri + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
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
|
||||
try {
|
||||
// remote request
|
||||
propfind = new PropfindMethod(client,
|
||||
propfind = new PropfindMethod(
|
||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||
DEPTH_0,
|
||||
DavUtils.getAllPropset());
|
||||
|
@ -73,7 +73,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation<ArrayList<RemoteF
|
||||
|
||||
try {
|
||||
PropfindMethod propfindMethod = new PropfindMethod(
|
||||
client,
|
||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||
DavConstants.DEPTH_1,
|
||||
DavUtils.getAllPropset());
|
||||
|
@ -72,7 +72,6 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
|
||||
Uri srcWebDavUri = removeChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
||||
|
||||
DeleteMethod deleteMethod = new DeleteMethod(
|
||||
client,
|
||||
new URL(srcWebDavUri + WebdavUtils.encodePath(mRemotePath)));
|
||||
|
||||
int status = client.executeHttpMethod(deleteMethod);
|
||||
|
@ -91,7 +91,7 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
||||
return new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
||||
}
|
||||
|
||||
final MoveMethod move = new MoveMethod(client,
|
||||
final MoveMethod move = new MoveMethod(
|
||||
new URL(client.getUserFilesWebDavUri() +
|
||||
WebdavUtils.encodePath(mOldRemotePath)),
|
||||
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mNewRemotePath), false);
|
||||
|
@ -49,8 +49,8 @@ class UploadFileFromContentUriOperation(
|
||||
) : RemoteOperation<Unit>() {
|
||||
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
||||
val putMethod = PutMethod(client, URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(uploadPath)), requestBody).apply {
|
||||
setRetryOnConnectionFailure(false)
|
||||
val putMethod = PutMethod(URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(uploadPath)), requestBody).apply {
|
||||
retryOnConnectionFailure = false
|
||||
addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, requestBody.contentLength().toString())
|
||||
addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, lastModified)
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
||||
mFileRequestBody.addDatatransferProgressListeners(mDataTransferListeners);
|
||||
}
|
||||
|
||||
mPutMethod = new PutMethod(client,
|
||||
mPutMethod = new PutMethod(
|
||||
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), mFileRequestBody);
|
||||
|
||||
mPutMethod.setRetryOnConnectionFailure(false);
|
||||
|
@ -92,7 +92,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
||||
result = new RemoteOperationResult<>(new OperationCancelledException());
|
||||
break;
|
||||
} else {
|
||||
mPutMethod = new PutMethod(client,
|
||||
mPutMethod = new PutMethod(
|
||||
new URL(uriPrefix + File.separator + chunkIndex), mFileRequestBody);
|
||||
|
||||
if (chunkIndex == chunkCount - 1) {
|
||||
|
@ -51,7 +51,7 @@ class GetOIDCDiscoveryRemoteOperation : RemoteOperation<OIDCDiscoveryResponse>()
|
||||
appendPath(OPENID_CONFIGURATION_RESOURCE)
|
||||
}.build()
|
||||
|
||||
val getMethod = GetMethod(client, URL(uriBuilder.toString())).apply {
|
||||
val getMethod = GetMethod(URL(uriBuilder.toString())).apply {
|
||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,6 @@ class RegisterClientRemoteOperation(
|
||||
val requestBody = clientRegistrationParams.toRequestBody()
|
||||
|
||||
val postMethod = PostMethod(
|
||||
httpClient = client,
|
||||
url = URL(clientRegistrationParams.registrationEndpoint),
|
||||
postRequestBody = requestBody
|
||||
)
|
||||
|
@ -52,7 +52,7 @@ class TokenRequestRemoteOperation(
|
||||
try {
|
||||
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)
|
||||
|
||||
|
@ -171,7 +171,7 @@ class CreateRemoteShareOperation(
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
||||
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)
|
||||
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> {
|
||||
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)
|
||||
|
||||
return try {
|
||||
|
@ -119,7 +119,7 @@ class GetRemoteSharesForFileOperation(
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOper
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -195,17 +195,17 @@ class UpdateRemoteShareOperation
|
||||
return formBodyBuilder
|
||||
}
|
||||
|
||||
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
|
||||
val requestUri = buildRequestUri(client.baseUri)
|
||||
|
||||
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)
|
||||
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||
}
|
||||
|
||||
|
||||
return try {
|
||||
val status = client.executeHttpMethod(putMethod)
|
||||
val response = putMethod.getResponseBodyAsString()
|
||||
|
@ -60,7 +60,7 @@ class GetRemoteCapabilitiesOperation : RemoteOperation<RemoteCapability>() {
|
||||
appendEncodedPath(OCS_ROUTE) // avoid starting "/" in this method
|
||||
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)
|
||||
}
|
||||
val status = client.executeHttpMethod(getMethod)
|
||||
|
@ -65,7 +65,7 @@ internal class StatusRequester {
|
||||
}
|
||||
|
||||
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)
|
||||
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
|
||||
Timber.d("avatar URI: %s", endPoint)
|
||||
|
||||
val getMethod = GetMethod(client, URL(endPoint))
|
||||
val getMethod = GetMethod(URL(endPoint))
|
||||
|
||||
val status = client.executeHttpMethod(getMethod)
|
||||
|
||||
|
@ -51,7 +51,7 @@ class GetRemoteUserInfoOperation : RemoteOperation<RemoteUserInfo>() {
|
||||
var result: RemoteOperationResult<RemoteUserInfo>
|
||||
//Get the user
|
||||
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 response = getMethod.getResponseBodyAsString() ?: ""
|
||||
if (status == HttpConstants.HTTP_OK) {
|
||||
|
@ -50,7 +50,6 @@ class GetRemoteUserQuotaOperation : RemoteOperation<RemoteQuota>() {
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteQuota> =
|
||||
try {
|
||||
val propfindMethod = PropfindMethod(
|
||||
client,
|
||||
URL(client.userFilesWebDavUri.toString()),
|
||||
DavConstants.DEPTH_0,
|
||||
DavUtils.quotaPropSet
|
||||
|
Loading…
x
Reference in New Issue
Block a user