1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 07:56:19 +00:00

get okhttp singleton removal changes to compile

This commit is contained in:
Christian Schabesberger 2021-01-04 15:08:10 +01:00 committed by Abel García de Prada
parent 06e361afaa
commit 0313c1e103
40 changed files with 256 additions and 50 deletions

View File

@ -0,0 +1,54 @@
/* ownCloud Android Library is available under MIT license
* 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.common;
import android.net.Uri;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation;
public class OwnCloudClientFactory {
/**
* Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud
* client connections.
*
* @param uri URL to the ownCloud server; BASE ENTRY POINT, not WebDavPATH
* @return A OwnCloudClient object ready to be used
*/
public static OwnCloudClient createOwnCloudClient(Uri uri, boolean followRedirects) {
OwnCloudClient client = new OwnCloudClient(uri);
client.setFollowRedirects(followRedirects);
HttpClient.setContext(context);
retrieveCookiesFromMiddleware(client);
return client;
}
private static void retrieveCookiesFromMiddleware(OwnCloudClient client) {
final GetRemoteStatusOperation statusOperation = new GetRemoteStatusOperation();
statusOperation.run(client);
}
}

View File

@ -140,7 +140,6 @@ public class SingleSessionManager {
client.clearCredentials();
client.setAccount(account);
HttpClient.setContext(context);
account.loadCredentials(context);
client.setCredentials(account.getCredentials());

View File

@ -55,30 +55,38 @@ import java.util.concurrent.TimeUnit;
*/
public class HttpClient {
private static OkHttpClient sOkHttpClient;
private static Context sContext;
private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>();
private static LogInterceptor sLogInterceptor;
private static Interceptor sDebugInterceptor;
private HashMap<String, List<Cookie>> mCookieStore = new HashMap<>();
private LogInterceptor mLogInterceptor;
public static OkHttpClient getOkHttpClient() {
if (sOkHttpClient == null) {
private OkHttpClient mOkHttpClient = null;
protected HttpClient() {
mLogInterceptor = new LogInterceptor();
}
public OkHttpClient getOkHttpClient() {
if(sContext == null) {
Timber.e("Context not initialized call HttpClient.setContext(applicationContext) in the MainApp.onCrate()");
throw new RuntimeException("Context not initialized call HttpClient.setContext(applicationContext) in the MainApp.onCrate()");
}
if(mOkHttpClient == null) {
try {
final X509TrustManager trustManager = new AdvancedX509TrustManager(
NetworkUtils.getKnownServersStore(sContext));
final SSLSocketFactory sslSocketFactory = getNewSslSocketFactory(trustManager);
// Automatic cookie handling, NOT PERSISTENT
final CookieJar cookieJar = new CookieJarImpl(sCookieStore);
final CookieJar cookieJar = new CookieJarImpl(mCookieStore);
// TODO: Not verifying the hostname against certificate. ask owncloud security human if this is ok.
//.hostnameVerifier(new BrowserCompatHostnameVerifier());
sOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager, cookieJar);
mOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager, cookieJar);
} catch (Exception e) {
Timber.e(e, "Could not setup SSL system.");
}
}
return sOkHttpClient;
return mOkHttpClient;
}
private static SSLContext getSslContext() throws NoSuchAlgorithmException {
@ -109,7 +117,7 @@ public class HttpClient {
return sslContext.getSocketFactory();
}
private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager,
private OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager,
CookieJar cookieJar) {
return new OkHttpClient.Builder()
.addNetworkInterceptor(getLogInterceptor())
@ -125,22 +133,23 @@ public class HttpClient {
.build();
}
public static LogInterceptor getLogInterceptor() {
if (sLogInterceptor == null) {
sLogInterceptor = new LogInterceptor();
}
return sLogInterceptor;
}
public Context getContext() {
return sContext;
}
public LogInterceptor getLogInterceptor() {
return mLogInterceptor;
}
public List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) {
return mCookieStore.get(httpUrl.host());
}
public static void setContext(Context context) {
sContext = context;
}
public void clearCookies() {
sCookieStore.clear();
mCookieStore.clear();
}
}

View File

@ -37,7 +37,7 @@ import java.net.MalformedURLException
import java.net.URL
import java.util.concurrent.TimeUnit
abstract class HttpBaseMethod constructor(url: URL) {
abstract class HttpBaseMethod constructor(clientWrapper: HttpClient, url: URL) {
var okHttpClient: OkHttpClient
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
var request: Request
@ -47,7 +47,7 @@ abstract class HttpBaseMethod constructor(url: URL) {
var call: Call? = null
init {
okHttpClient = HttpClient.getOkHttpClient()
okHttpClient = clientWrapper.okHttpClient
request = Request.Builder()
.url(httpUrl)
.build()

View File

@ -23,6 +23,7 @@
*/
package com.owncloud.android.lib.common.http.methods.nonwebdav
import com.owncloud.android.lib.common.http.HttpClient
import java.io.IOException
import java.net.URL
@ -31,7 +32,7 @@ import java.net.URL
*
* @author David González Verdugo
*/
class DeleteMethod(url: URL) : HttpMethod(url) {
class DeleteMethod(httpClient: HttpClient, url: URL) : HttpMethod(httpClient, url) {
@Throws(IOException::class)
override fun onExecute(): Int {
request = request.newBuilder()

View File

@ -23,6 +23,7 @@
*/
package com.owncloud.android.lib.common.http.methods.nonwebdav
import com.owncloud.android.lib.common.http.HttpClient
import java.io.IOException
import java.net.URL
@ -31,7 +32,7 @@ import java.net.URL
*
* @author David González Verdugo
*/
class GetMethod(url: URL) : HttpMethod(url) {
class GetMethod(httpClient: HttpClient, url: URL) : HttpMethod(httpClient, url) {
@Throws(IOException::class)
override fun onExecute(): Int {
request = request.newBuilder()

View File

@ -23,7 +23,9 @@
*/
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
@ -33,8 +35,9 @@ import java.net.URL
* @author David González Verdugo
*/
abstract class HttpMethod(
httpClient: HttpClient,
url: URL
) : HttpBaseMethod(url) {
) : HttpBaseMethod(httpClient, url) {
override lateinit var response: Response

View File

@ -23,6 +23,8 @@
*/
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
@ -33,9 +35,10 @@ import java.net.URL
* @author David González Verdugo
*/
class PostMethod(
httpClient: HttpClient,
url: URL,
private val postRequestBody: RequestBody
) : HttpMethod(url) {
) : HttpMethod(httpClient, url) {
@Throws(IOException::class)
override fun onExecute(): Int {
request = request.newBuilder()

View File

@ -23,6 +23,8 @@
*/
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
@ -33,9 +35,10 @@ import java.net.URL
* @author David González Verdugo
*/
class PutMethod(
httpClient: HttpClient,
url: URL,
private val putRequestBody: RequestBody
) : HttpMethod(url) {
) : HttpMethod(httpClient, url) {
@Throws(IOException::class)
override fun onExecute(): Int {
request = request.newBuilder()

View File

@ -23,6 +23,7 @@
*/
package com.owncloud.android.lib.common.http.methods.webdav
import com.owncloud.android.lib.common.http.HttpClient
import okhttp3.Response
import java.net.URL
@ -33,10 +34,11 @@ 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(url) {
) : DavMethod(httpClient, url) {
@Throws(Exception::class)
public override fun onExecute(): Int {
davResource.copy(

View File

@ -27,6 +27,7 @@ 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
@ -43,7 +44,7 @@ import java.util.concurrent.TimeUnit
*
* @author David González Verdugo
*/
abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
abstract class DavMethod protected constructor(httpClient: HttpClient,url: URL) : HttpBaseMethod(httpClient, url) {
protected var davResource: DavOCResource
override lateinit var response: Response

View File

@ -23,6 +23,7 @@
*/
package com.owncloud.android.lib.common.http.methods.webdav
import com.owncloud.android.lib.common.http.HttpClient
import okhttp3.Response
import java.net.URL
@ -32,7 +33,7 @@ import java.net.URL
* @author Christian Schabesberger
* @author David González Verdugo
*/
class MkColMethod(url: URL) : DavMethod(url) {
class MkColMethod(httpClient: HttpClient, url: URL) : DavMethod(httpClient, url) {
@Throws(Exception::class)
public override fun onExecute(): Int {
davResource.mkCol(

View File

@ -23,6 +23,7 @@
*/
package com.owncloud.android.lib.common.http.methods.webdav
import com.owncloud.android.lib.common.http.HttpClient
import okhttp3.Response
import java.net.URL
@ -33,10 +34,11 @@ import java.net.URL
* @author David González Verdugo
*/
class MoveMethod(
httpClient: HttpClient,
url: URL,
private val destinationUrl: String,
private val forceOverride: Boolean
) : DavMethod(url) {
) : DavMethod(httpClient, url) {
@Throws(Exception::class)
public override fun onExecute(): Int {
davResource.move(

View File

@ -27,6 +27,7 @@ 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
@ -36,10 +37,11 @@ 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(url) {
) : DavMethod(httpClient, url) {
// response
val members: MutableList<Response>

View File

@ -24,6 +24,7 @@
package com.owncloud.android.lib.common.http.methods.webdav
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
@ -35,9 +36,10 @@ import java.net.URL
* @author David González Verdugo
*/
class PutMethod(
httpClient: HttpClient,
url: URL,
private val putRequestBody: RequestBody
) : DavMethod(url) {
) : DavMethod(httpClient, url) {
@Throws(IOException::class, HttpException::class)
public override fun onExecute(): Int {
davResource.put(

View File

@ -57,7 +57,7 @@ class CheckPathExistenceRemoteOperation(
if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)
val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropset).apply {
val propFindMethod = PropfindMethod(client, URL(stringUrl), 0, allPropset).apply {
setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
}

View File

@ -92,7 +92,8 @@ public class CopyRemoteFileOperation extends RemoteOperation<String> {
RemoteOperationResult result;
try {
CopyMethod copyMethod =
new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
new CopyMethod(client,
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
mOverwrite);

View File

@ -87,7 +87,8 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
RemoteOperationResult result;
try {
Uri webDavUri = createChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
final MkColMethod mkcol = new MkColMethod(new URL(webDavUri + WebdavUtils.encodePath(mRemotePath)));
final MkColMethod mkcol = new MkColMethod(client,
new URL(webDavUri + WebdavUtils.encodePath(mRemotePath)));
mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
final int status = client.executeHttpMethod(mkcol);

View File

@ -96,7 +96,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
RemoteOperationResult result;
int status;
boolean savedFile = false;
mGet = new GetMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)));
mGet = new GetMethod(client, new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)));
Iterator<OnDatatransferProgressListener> it;
FileOutputStream fos = null;

View File

@ -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(
final MoveMethod move = new MoveMethod(client,
new URL(srcWebDavUri + WebdavUtils.encodePath(mSrcRemotePath)),
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
mOverwrite);

View File

@ -76,7 +76,8 @@ 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(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
propfind = new PropfindMethod(client,
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
DEPTH_0,
DavUtils.getAllPropset());

View File

@ -73,6 +73,7 @@ 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());

View File

@ -72,6 +72,7 @@ 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);

View File

@ -91,7 +91,8 @@ public class RenameRemoteFileOperation extends RemoteOperation {
return new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
}
final MoveMethod move = new MoveMethod(new URL(client.getUserFilesWebDavUri() +
final MoveMethod move = new MoveMethod(client,
new URL(client.getUserFilesWebDavUri() +
WebdavUtils.encodePath(mOldRemotePath)),
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mNewRemotePath), false);

View File

@ -121,7 +121,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
mFileRequestBody.addDatatransferProgressListeners(mDataTransferListeners);
}
mPutMethod = new PutMethod(
mPutMethod = new PutMethod(client,
new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), mFileRequestBody);
mPutMethod.setRetryOnConnectionFailure(false);

View File

@ -92,7 +92,8 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
result = new RemoteOperationResult<>(new OperationCancelledException());
break;
} else {
mPutMethod = new PutMethod(new URL(uriPrefix + File.separator + chunkIndex), mFileRequestBody);
mPutMethod = new PutMethod(client,
new URL(uriPrefix + File.separator + chunkIndex), mFileRequestBody);
if (chunkIndex == chunkCount - 1) {
// Added a high timeout to the last chunk due to when the last chunk

View File

@ -138,7 +138,6 @@ class CreateRemoteShareOperation(
}
private fun createFormBody(): FormBody {
val formBodyBuilder = FormBody.Builder()
.add(PARAM_PATH, remoteFilePath)
.add(PARAM_SHARE_TYPE, shareType.value.toString())
@ -172,7 +171,7 @@ class CreateRemoteShareOperation(
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
val requestUri = buildRequestUri(client.baseUri)
val postMethod = PostMethod(URL(requestUri.toString()), createFormBody()).apply {
val postMethod = PostMethod(client, URL(requestUri.toString()), createFormBody()).apply {
setRequestHeader(HttpConstants.CONTENT_TYPE_HEADER, HttpConstants.CONTENT_TYPE_URLENCODED_UTF8)
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
}

View File

@ -0,0 +1,94 @@
/* 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);
}
}

View File

@ -131,7 +131,7 @@ class GetRemoteShareesOperation
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareeOcsResponse> {
val requestUri = buildRequestUri(client.baseUri)
val getMethod = GetMethod(URL(requestUri.toString()))
val getMethod = GetMethod(client, URL(requestUri.toString()))
getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
return try {

View File

@ -119,7 +119,7 @@ class GetRemoteSharesForFileOperation(
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
val requestUri = buildRequestUri(client.baseUri)
val getMethod = GetMethod(URL(requestUri.toString())).apply {
val getMethod = GetMethod(client, URL(requestUri.toString())).apply {
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
}

View File

@ -104,9 +104,10 @@ class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOper
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
val requestUri = buildRequestUri(client.baseUri)
val deleteMethod = DeleteMethod(URL(requestUri.toString())).apply {
val deleteMethod = DeleteMethod(client, URL(requestUri.toString())).apply {
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
}

View File

@ -200,7 +200,7 @@ class UpdateRemoteShareOperation
val formBodyBuilder = createFormBodyBuilder()
val putMethod = PutMethod(URL(requestUri.toString()), formBodyBuilder.build()).apply {
val putMethod = PutMethod(client, URL(requestUri.toString()), formBodyBuilder.build()).apply {
setRequestHeader(HttpConstants.CONTENT_TYPE_HEADER, HttpConstants.CONTENT_TYPE_URLENCODED_UTF8)
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
}

View File

@ -60,7 +60,7 @@ class GetRemoteCapabilitiesOperation : RemoteOperation<RemoteCapability>() {
appendEncodedPath(OCS_ROUTE) // avoid starting "/" in this method
appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT)
}
val getMethod = GetMethod(URL(uriBuilder.build().toString())).apply {
val getMethod = GetMethod(client, URL(uriBuilder.build().toString())).apply {
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
}
val status = client.executeHttpMethod(getMethod)

View File

@ -53,6 +53,7 @@ class GetRemoteStatusOperation : RemoteOperation<RemoteServerInfo>() {
client.baseUri = Uri.parse(newBaseUrl)
}
private fun tryToConnect(client: OwnCloudClient): RemoteOperationResult<RemoteServerInfo> {
val baseUrl = client.baseUri.toString()
return try {

View File

@ -23,6 +23,7 @@
*/
package com.owncloud.android.lib.resources.status.services
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.status.RemoteServerInfo

View File

@ -26,6 +26,7 @@
package com.owncloud.android.lib.resources.status.services.implementation
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation

View File

@ -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(URL(endPoint))
val getMethod = GetMethod(client, URL(endPoint))
val status = client.executeHttpMethod(getMethod)

View File

@ -51,7 +51,7 @@ class GetRemoteUserInfoOperation : RemoteOperation<RemoteUserInfo>() {
var result: RemoteOperationResult<RemoteUserInfo>
//Get the user
try {
val getMethod = GetMethod(URL(client.baseUri.toString() + OCS_ROUTE))
val getMethod = GetMethod(client, URL(client.baseUri.toString() + OCS_ROUTE))
val status = client.executeHttpMethod(getMethod)
val response = getMethod.getResponseBodyAsString() ?: ""
if (status == HttpConstants.HTTP_OK) {

View File

@ -50,6 +50,7 @@ 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

View File

@ -38,8 +38,13 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
<<<<<<< HEAD
import com.owncloud.android.lib.common.ConnectionValidator;
import com.owncloud.android.lib.common.OwnCloudClient;
=======
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
import com.owncloud.android.lib.common.SingleSessionManager;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
@ -51,6 +56,10 @@ import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
<<<<<<< HEAD
=======
import info.hannes.timber.DebugTree;
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
import timber.log.Timber;
import java.io.File;
@ -75,17 +84,26 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
<<<<<<< HEAD
Timber.plant();
=======
Timber.plant(new DebugTree());
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
mHandler = new Handler();
final Uri serverUri = Uri.parse(getString(R.string.server_base_url));
SingleSessionManager.setUserAgent(getUserAgent());
<<<<<<< HEAD
SingleSessionManager.setConnectionValidator(new ConnectionValidator(this, false));
mClient = new OwnCloudClient(serverUri,
SingleSessionManager.getConnectionValidator(),
true,
SingleSessionManager.getDefaultSingleton());
=======
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, true);
>>>>>>> 5e555278 (get okhttp singleton removal changes to compile)
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
getString(R.string.username),