diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java deleted file mode 100644 index b8148c53..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -/* 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.content.Context; -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, - ConnectionValidator connectionValidator, - boolean followRedirects, - SingleSessionManager singleSessionManager, - Context context) { - OwnCloudClient client = new OwnCloudClient(uri, connectionValidator, true, singleSessionManager, context); - - client.setFollowRedirects(followRedirects); - retrieveCookiesFromMiddleware(client); - return client; - } - - private static void retrieveCookiesFromMiddleware(OwnCloudClient client) { - final GetRemoteStatusOperation statusOperation = new GetRemoteStatusOperation(); - statusOperation.run(client); - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java index afe4735a..241a50fa 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java @@ -61,15 +61,14 @@ public class HttpClient { private OkHttpClient mOkHttpClient = null; protected HttpClient(Context context) { + if(context == null) { + Timber.e("Context may not be NULL!"); + throw new NullPointerException("Context may not be NULL!"); + } mContext = context; } public OkHttpClient getOkHttpClient() { - if (mContext == 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( diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt index bf58b0fd..88a44142 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt @@ -60,8 +60,8 @@ abstract class HttpBaseMethod constructor(url: URL) { @Throws(Exception::class) open fun execute(httpClient: HttpClient): Int { val okHttpClient = httpClient.okHttpClient.newBuilder().apply { - retryOnConnectionFailure?.let { retryOnConnectionFailure(it) } - followRedirects?.let { followRedirects(it) } + retryOnConnectionFailure.let { retryOnConnectionFailure(it) } + followRedirects.let { followRedirects(it) } readTimeoutUnit?.let { unit -> readTimeoutVal?.let { readTimeout(it, unit) } } @@ -152,12 +152,7 @@ abstract class HttpBaseMethod constructor(url: URL) { // Setter ////////////////////////////// // Connection parameters - /* - open fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) { - retryOnConnectionFailureVal = true - } - */ open fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) { readTimeoutVal = readTimeout diff --git a/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java b/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java index 10128afa..b595b8e7 100644 --- a/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java +++ b/sample_client/src/main/java/com/owncloud/android/lib/sampleclient/MainActivity.java @@ -74,7 +74,6 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, super.onCreate(savedInstanceState); setContentView(R.layout.main); - Timber.plant(new DebugTree()); mHandler = new Handler(); final Uri serverUri = Uri.parse(getString(R.string.server_base_url)); @@ -86,8 +85,6 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, true, SingleSessionManager.getDefaultSingleton()); - mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true); - mClient.setCredentials( OwnCloudCredentialsFactory.newBasicCredentials( getString(R.string.username),