mirror of
https://github.com/owncloud/android-library.git
synced 2026-08-18 20:03:00 +00:00
Refactored handle of ownCloud URIs inside OwnCloudClient; rest of library adapted
This commit is contained in:
@@ -43,6 +43,7 @@ import org.apache.commons.httpclient.params.HttpMethodParams;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
|
||||
|
||||
@@ -66,15 +67,20 @@ public class OwnCloudClient extends HttpClient {
|
||||
//private String mSsoSessionCookie = null;
|
||||
private int mInstanceNumber = 0;
|
||||
|
||||
private Uri mUri;
|
||||
private Uri mWebdavUri;
|
||||
private Uri mBaseUri;
|
||||
//private Uri mWebdavUri;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public OwnCloudClient(HttpConnectionManager connectionMgr) {
|
||||
public OwnCloudClient(Uri baseUri, HttpConnectionManager connectionMgr) {
|
||||
super(connectionMgr);
|
||||
|
||||
if (baseUri == null) {
|
||||
throw new IllegalArgumentException("Parameter 'baseUri' cannot be NULL");
|
||||
}
|
||||
mBaseUri = baseUri;
|
||||
|
||||
mInstanceNumber = sIntanceCounter++;
|
||||
Log.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
|
||||
|
||||
@@ -131,7 +137,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
/*
|
||||
public void setSsoSessionCookie(String accessToken) {
|
||||
Log.d(TAG + " #" + mInstanceNumber, "Setting session cookie: " + accessToken);
|
||||
Log.e(TAG + " #" + mInstanceNumber, "BASE URL: " + mUri);
|
||||
Log.e(TAG + " #" + mInstanceNumber, "BASE URL: " + mBaseUri);
|
||||
Log.e(TAG + " #" + mInstanceNumber, "WebDAV URL: " + mWebdavUri);
|
||||
|
||||
if (accessToken != null && accessToken.length() > 0) {
|
||||
@@ -141,7 +147,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
mSsoSessionCookie = accessToken;
|
||||
mCredentials = null;
|
||||
|
||||
Uri serverUri = (mUri != null)? mUri : mWebdavUri;
|
||||
Uri serverUri = (mBaseUri != null)? mBaseUri : mWebdavUri;
|
||||
// TODO refactoring the mess of URIs
|
||||
|
||||
String[] cookies = mSsoSessionCookie.split(";");
|
||||
@@ -183,7 +189,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
* @throws Exception When the existence could not be determined
|
||||
*/
|
||||
public boolean existsFile(String path) throws IOException, HttpException {
|
||||
HeadMethod head = new HeadMethod(mWebdavUri.toString() + WebdavUtils.encodePath(path));
|
||||
HeadMethod head = new HeadMethod(getWebdavUri() + WebdavUtils.encodePath(path));
|
||||
try {
|
||||
int status = executeMethod(head);
|
||||
Log.d(TAG, "HEAD to " + path + " finished with HTTP status " + status +
|
||||
@@ -323,31 +329,27 @@ public class OwnCloudClient extends HttpClient {
|
||||
getHttpConnectionManager().getParams().setConnectionTimeout(defaultConnectionTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Webdav URI for the helper methods that receive paths as parameters,
|
||||
* instead of full URLs
|
||||
* @param uri
|
||||
*/
|
||||
public void setWebdavUri(Uri uri) {
|
||||
mWebdavUri = uri;
|
||||
}
|
||||
|
||||
public Uri getWebdavUri() {
|
||||
return mWebdavUri;
|
||||
if (mCredentials instanceof OwnCloudBearerCredentials) {
|
||||
return Uri.parse(mBaseUri + AccountUtils.ODAV_PATH);
|
||||
} else {
|
||||
return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_4_0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base URI for the helper methods that receive paths as parameters,
|
||||
* instead of full URLs
|
||||
* Sets the root URI to the ownCloud server.
|
||||
*
|
||||
* Use with care.
|
||||
*
|
||||
* @param uri
|
||||
*/
|
||||
public void setBaseUri(Uri uri) {
|
||||
mUri = uri;
|
||||
mBaseUri = uri;
|
||||
}
|
||||
|
||||
public Uri getBaseUri() {
|
||||
return mUri;
|
||||
return mBaseUri;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -72,14 +72,11 @@ public class OwnCloudClientFactory {
|
||||
*/
|
||||
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {
|
||||
//Log_OC.d(TAG, "Creating OwnCloudClient associated to " + account.name);
|
||||
|
||||
Uri webdavUri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account));
|
||||
Uri uri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account));
|
||||
Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account));
|
||||
AccountManager am = AccountManager.get(appContext);
|
||||
boolean isOauth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here
|
||||
boolean isSamlSso = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||
OwnCloudClient client = createOwnCloudClient(webdavUri, appContext, !isSamlSso);
|
||||
client.setBaseUri(uri);
|
||||
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
||||
|
||||
if (isOauth2) {
|
||||
String accessToken = am.blockingGetAuthToken(
|
||||
@@ -123,13 +120,11 @@ public class OwnCloudClientFactory {
|
||||
|
||||
|
||||
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext, Activity currentActivity) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {
|
||||
Uri webdavUri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account));
|
||||
Uri uri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account));
|
||||
Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account));
|
||||
AccountManager am = AccountManager.get(appContext);
|
||||
boolean isOauth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here
|
||||
boolean isSamlSso = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||
OwnCloudClient client = createOwnCloudClient(webdavUri, appContext, !isSamlSso);
|
||||
client.setBaseUri(uri);
|
||||
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
||||
|
||||
if (isOauth2) { // TODO avoid a call to getUserData here
|
||||
AccountManagerFuture<Bundle> future = am.getAuthToken(
|
||||
@@ -192,7 +187,7 @@ 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
|
||||
* @param uri URL to the ownCloud server; BASE ENTRY POINT, not WebDavPATH
|
||||
* @param context Android context where the OwnCloudClient is being created.
|
||||
* @return A OwnCloudClient object ready to be used
|
||||
*/
|
||||
@@ -206,10 +201,8 @@ public class OwnCloudClientFactory {
|
||||
Log.e(TAG, "The local server truststore could not be read. Default SSL management in the system will be used for HTTPS connections", e);
|
||||
}
|
||||
|
||||
OwnCloudClient client = new OwnCloudClient(NetworkUtils.getMultiThreadedConnManager());
|
||||
|
||||
OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager());
|
||||
client.setDefaultTimeouts(DEFAULT_DATA_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
|
||||
client.setWebdavUri(uri);
|
||||
client.setFollowRedirects(followRedirects);
|
||||
|
||||
return client;
|
||||
|
||||
@@ -45,7 +45,7 @@ public class AccountUtils {
|
||||
public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php";
|
||||
public static final String WEBDAV_PATH_2_0 = "/files/webdav.php";
|
||||
public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";
|
||||
private static final String ODAV_PATH = "/remote.php/odav";
|
||||
public static final String ODAV_PATH = "/remote.php/odav";
|
||||
private static final String SAML_SSO_PATH = "/remote.php/webdav";
|
||||
public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php";
|
||||
public static final String CARDDAV_PATH_4_0 = "/remote/carddav.php";
|
||||
@@ -81,11 +81,15 @@ public class AccountUtils {
|
||||
|
||||
/**
|
||||
* Constructs full url to host and webdav resource basing on host version
|
||||
*
|
||||
* @deprecated To be removed in release 1.0.
|
||||
*
|
||||
* @param context
|
||||
* @param account
|
||||
* @return url or null on failure
|
||||
* @throws AccountNotFoundException When 'account' is unknown for the AccountManager
|
||||
*/
|
||||
@Deprecated
|
||||
public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException {
|
||||
AccountManager ama = AccountManager.get(context);
|
||||
String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL);
|
||||
|
||||
Reference in New Issue
Block a user