mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Reformat some code thanks to code review
This commit is contained in:
parent
69497645ec
commit
f89cfd91a9
@ -101,12 +101,12 @@ public class OwnCloudClient extends HttpClient {
|
||||
|
||||
// Header to allow tracing requests in apache and ownCloud logs
|
||||
Timber.d("Executing in request with id %s", requestId);
|
||||
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID,requestId);
|
||||
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
|
||||
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
|
||||
method.setRequestHeader(HttpConstants.PARAM_SINGLE_COOKIE_HEADER, "true");
|
||||
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
|
||||
if(mCredentials.getHeaderAuth()!=null){
|
||||
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER,mCredentials.getHeaderAuth());
|
||||
if (mCredentials.getHeaderAuth() != null) {
|
||||
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
|
||||
}
|
||||
status = method.execute();
|
||||
|
||||
@ -133,12 +133,12 @@ public class OwnCloudClient extends HttpClient {
|
||||
|
||||
// Header to allow tracing requests in apache and ownCloud logs
|
||||
Timber.d("Executing in request with id %s", requestId);
|
||||
method.setRequestHeader(OC_X_REQUEST_ID,requestId);
|
||||
method.setRequestHeader(OC_X_REQUEST_ID, requestId);
|
||||
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
|
||||
method.setRequestHeader(HttpConstants.PARAM_SINGLE_COOKIE_HEADER, "true");
|
||||
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
|
||||
if(mCredentials.getHeaderAuth()!=null){
|
||||
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER,mCredentials.getHeaderAuth());
|
||||
if (mCredentials.getHeaderAuth() != null) {
|
||||
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
|
||||
}
|
||||
status = method.execute();
|
||||
|
||||
|
@ -19,8 +19,7 @@ abstract class HttpBaseMethod constructor(url: URL) {
|
||||
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
||||
var request: Request
|
||||
var requestBody: RequestBody? = null
|
||||
lateinit var response: Response
|
||||
private var responseBodyString: String? = null
|
||||
abstract var response: Response
|
||||
|
||||
var call: Call? = null
|
||||
|
||||
@ -100,12 +99,7 @@ abstract class HttpBaseMethod constructor(url: URL) {
|
||||
}
|
||||
|
||||
// Body
|
||||
fun getResponseBodyAsString(): String? {
|
||||
if (responseBodyString == null && response.body != null) {
|
||||
responseBodyString = response.body?.string()
|
||||
}
|
||||
return responseBodyString
|
||||
}
|
||||
fun getResponseBodyAsString(): String? = response.body?.string()
|
||||
|
||||
open fun getResponseBodyAsStream(): InputStream? {
|
||||
return response.body?.byteStream()
|
||||
|
@ -23,18 +23,21 @@
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.nonwebdav
|
||||
|
||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
|
||||
import okhttp3.Response
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* Wrapper to perform OkHttp calls
|
||||
*
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
abstract class HttpMethod(url: URL) : HttpBaseMethod(url) {
|
||||
@Throws(IOException::class)
|
||||
abstract class HttpMethod(
|
||||
url: URL
|
||||
) : HttpBaseMethod(url) {
|
||||
|
||||
override lateinit var response: Response
|
||||
|
||||
public override fun onExecute(): Int {
|
||||
call = okHttpClient.newCall(request)
|
||||
call?.let { response = it.execute() }
|
||||
|
@ -32,7 +32,10 @@ import java.net.URL
|
||||
*
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class PutMethod(url: URL, private val putRequestBody: RequestBody) : HttpMethod(url) {
|
||||
class PutMethod(
|
||||
url: URL,
|
||||
private val putRequestBody: RequestBody
|
||||
) : HttpMethod(url) {
|
||||
@Throws(IOException::class)
|
||||
override fun onExecute(): Int {
|
||||
requestBody = putRequestBody
|
||||
|
@ -39,7 +39,7 @@ class CopyMethod(
|
||||
) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.copy(
|
||||
davResource.copy(
|
||||
destinationUrl,
|
||||
forceOverride,
|
||||
super.getRequestHeadersAsHashMap()
|
||||
|
@ -44,11 +44,13 @@ import java.util.concurrent.TimeUnit
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
protected var mDavResource: DavOCResource
|
||||
protected var davResource: DavOCResource
|
||||
|
||||
override lateinit var response: Response
|
||||
|
||||
init {
|
||||
val httpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
|
||||
mDavResource = DavOCResource(
|
||||
davResource = DavOCResource(
|
||||
okHttpClient,
|
||||
httpUrl,
|
||||
log
|
||||
@ -56,7 +58,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
}
|
||||
|
||||
override fun abort() {
|
||||
mDavResource.cancelCall()
|
||||
davResource.cancelCall()
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
@ -79,8 +81,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
// The check below should be included in okhttp library, method ResponseBody.create(
|
||||
// TODO check most recent versions of okhttp to see if this is already fixed and try to update if so
|
||||
if (response.body?.contentType() != null) {
|
||||
val responseBody = (httpException.responseBody ?: ""
|
||||
).toResponseBody(response.body?.contentType())
|
||||
val responseBody = (httpException.responseBody ?: "").toResponseBody(response.body?.contentType())
|
||||
response = response.newBuilder()
|
||||
.body(responseBody)
|
||||
.build()
|
||||
@ -96,7 +97,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
// Connection parameters
|
||||
override fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
|
||||
super.setReadTimeout(readTimeout, timeUnit)
|
||||
mDavResource = DavOCResource(
|
||||
davResource = DavOCResource(
|
||||
okHttpClient,
|
||||
httpUrl,
|
||||
log
|
||||
@ -108,7 +109,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
timeUnit: TimeUnit
|
||||
) {
|
||||
super.setConnectionTimeout(connectionTimeout, timeUnit)
|
||||
mDavResource = DavOCResource(
|
||||
davResource = DavOCResource(
|
||||
okHttpClient,
|
||||
httpUrl,
|
||||
log
|
||||
@ -117,7 +118,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
|
||||
override fun setFollowRedirects(followRedirects: Boolean) {
|
||||
super.setFollowRedirects(followRedirects)
|
||||
mDavResource = DavOCResource(
|
||||
davResource = DavOCResource(
|
||||
okHttpClient,
|
||||
httpUrl,
|
||||
log
|
||||
@ -126,7 +127,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
|
||||
override fun setUrl(url: HttpUrl) {
|
||||
super.setUrl(url)
|
||||
mDavResource = DavOCResource(
|
||||
davResource = DavOCResource(
|
||||
okHttpClient,
|
||||
httpUrl,
|
||||
log
|
||||
@ -135,23 +136,19 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
|
||||
override fun setRequestHeader(name: String, value: String) {
|
||||
super.setRequestHeader(name, value)
|
||||
mDavResource = DavOCResource(
|
||||
davResource = DavOCResource(
|
||||
okHttpClient,
|
||||
httpUrl,
|
||||
log
|
||||
)
|
||||
}
|
||||
|
||||
fun getRetryOnConnectionFailure(): Boolean {
|
||||
return false //TODO: implement me
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Getter
|
||||
//////////////////////////////
|
||||
override fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
|
||||
super.setRetryOnConnectionFailure(retryOnConnectionFailure)
|
||||
mDavResource = DavOCResource(
|
||||
davResource = DavOCResource(
|
||||
okHttpClient,
|
||||
httpUrl,
|
||||
log
|
||||
@ -159,6 +156,6 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
|
||||
}
|
||||
|
||||
override val isAborted: Boolean
|
||||
get() = mDavResource.isCallAborted()
|
||||
get() = davResource.isCallAborted()
|
||||
|
||||
}
|
@ -35,7 +35,7 @@ import java.net.URL
|
||||
class MkColMethod(url: URL) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.mkCol(
|
||||
davResource.mkCol(
|
||||
xmlBody = null,
|
||||
listOfHeaders = super.getRequestHeadersAsHashMap()
|
||||
) { callBackResponse: Response ->
|
||||
|
@ -23,7 +23,6 @@
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.webdav
|
||||
|
||||
import com.owncloud.android.lib.common.http.HttpConstants
|
||||
import okhttp3.Response
|
||||
import java.net.URL
|
||||
|
||||
@ -40,7 +39,7 @@ class MoveMethod(
|
||||
) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.move(
|
||||
davResource.move(
|
||||
destinationUrl,
|
||||
forceOverride,
|
||||
super.getRequestHeadersAsHashMap()
|
||||
|
@ -29,7 +29,6 @@ import at.bitfire.dav4jvm.Response.HrefRelation
|
||||
import at.bitfire.dav4jvm.exception.DavException
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
* Propfind calls wrapper
|
||||
@ -38,30 +37,27 @@ import java.util.ArrayList
|
||||
*/
|
||||
class PropfindMethod(
|
||||
url: URL,
|
||||
// request
|
||||
val depth: Int,
|
||||
private val mPropertiesToRequest: Array<Property.Name>
|
||||
private val depth: Int,
|
||||
private val propertiesToRequest: Array<Property.Name>
|
||||
) : DavMethod(url) {
|
||||
|
||||
// response
|
||||
private val mMembers: MutableList<Response>
|
||||
val members: MutableList<Response>
|
||||
var root: Response?
|
||||
private set
|
||||
|
||||
@Throws(IOException::class, DavException::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.propfind(
|
||||
davResource.propfind(
|
||||
depth = depth,
|
||||
reqProp = *mPropertiesToRequest,
|
||||
reqProp = *propertiesToRequest,
|
||||
listOfHeaders = super.getRequestHeadersAsHashMap(),
|
||||
callback = { response: Response, hrefRelation: HrefRelation? ->
|
||||
when (hrefRelation) {
|
||||
HrefRelation.MEMBER -> mMembers.add(response)
|
||||
HrefRelation.MEMBER -> members.add(response)
|
||||
HrefRelation.SELF -> this.root = response
|
||||
HrefRelation.OTHER -> {
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
}, rawCallback = { callBackResponse: okhttp3.Response ->
|
||||
response = callBackResponse
|
||||
@ -69,11 +65,8 @@ class PropfindMethod(
|
||||
return statusCode
|
||||
}
|
||||
|
||||
val members: List<Response>
|
||||
get() = mMembers
|
||||
|
||||
init {
|
||||
mMembers = ArrayList()
|
||||
members = arrayListOf()
|
||||
this.root = null
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class PutMethod(
|
||||
) : DavMethod(url) {
|
||||
@Throws(IOException::class, HttpException::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.put(
|
||||
davResource.put(
|
||||
requestBody!!,
|
||||
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
|
||||
getRequestHeadersAsHashMap()
|
||||
|
@ -45,6 +45,7 @@ public class AdvancedX509TrustManager implements X509TrustManager {
|
||||
|
||||
private X509TrustManager mStandardTrustManager;
|
||||
private KeyStore mKnownServersKeyStore;
|
||||
|
||||
/**
|
||||
* Constructor for AdvancedX509TrustManager
|
||||
*
|
||||
@ -66,7 +67,7 @@ public class AdvancedX509TrustManager implements X509TrustManager {
|
||||
* @return The first X509TrustManager found in factory.
|
||||
*/
|
||||
private X509TrustManager findX509TrustManager(TrustManagerFactory factory) {
|
||||
TrustManager tms[] = factory.getTrustManagers();
|
||||
TrustManager[] tms = factory.getTrustManagers();
|
||||
for (TrustManager tm : tms) {
|
||||
if (tm instanceof X509TrustManager) {
|
||||
return (X509TrustManager) tm;
|
||||
|
@ -44,9 +44,9 @@ import java.util.Set;
|
||||
*/
|
||||
public class FileRequestBody extends RequestBody implements ProgressiveDataTransferer {
|
||||
|
||||
final Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<>();
|
||||
protected File mFile;
|
||||
private MediaType mContentType;
|
||||
final Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<>();
|
||||
|
||||
public FileRequestBody(File file, MediaType contentType) {
|
||||
mFile = file;
|
||||
|
@ -29,7 +29,6 @@ import com.owncloud.android.lib.common.http.methods.webdav.PutMethod;
|
||||
import com.owncloud.android.lib.common.network.ChunkFromFileRequestBody;
|
||||
import com.owncloud.android.lib.common.operations.OperationCancelledException;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
|
||||
import okhttp3.MediaType;
|
||||
import timber.log.Timber;
|
||||
|
Loading…
x
Reference in New Issue
Block a user