1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-08 00:16:09 +00:00

Refactor parameter user_agent out of RemoteOperation and children

This commit is contained in:
masensio 2015-03-24 14:31:40 +01:00
parent 94ac3a93d3
commit 9990eeb7ff
29 changed files with 96 additions and 166 deletions

View File

@ -79,8 +79,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
mHandler = new Handler(); mHandler = new Handler();
Uri serverUri = Uri.parse(getString(R.string.server_base_url)); Uri serverUri = Uri.parse(getString(R.string.server_base_url));
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true, mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
getString(R.string.user_agent));
mClient.setCredentials( mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials( OwnCloudCredentialsFactory.newBasicCredentials(
getString(R.string.username), getString(R.string.username),
@ -150,7 +149,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private void startRefresh() { private void startRefresh() {
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR); ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
refreshOperation.execute(mClient, getString(R.string.user_agent), this, mHandler); refreshOperation.execute(mClient, this, mHandler);
} }
private void startUpload() { private void startUpload() {
@ -160,7 +159,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
String mimeType = getString(R.string.sample_file_mimetype); String mimeType = getString(R.string.sample_file_mimetype);
UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType); UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType);
uploadOperation.addDatatransferProgressListener(this); uploadOperation.addDatatransferProgressListener(this);
uploadOperation.execute(mClient, getString(R.string.user_agent), this, mHandler); uploadOperation.execute(mClient, this, mHandler);
} }
private void startRemoteDeletion() { private void startRemoteDeletion() {
@ -168,7 +167,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
File fileToUpload = upFolder.listFiles()[0]; File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
removeOperation.execute(mClient, getString(R.string.user_agent), this, mHandler); removeOperation.execute(mClient, this, mHandler);
} }
private void startDownload() { private void startDownload() {
@ -179,7 +178,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath()); DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath());
downloadOperation.addDatatransferProgressListener(this); downloadOperation.addDatatransferProgressListener(this);
downloadOperation.execute(mClient, getString(R.string.user_agent), this, mHandler); downloadOperation.execute(mClient, this, mHandler);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View File

@ -67,12 +67,11 @@ public class OwnCloudClient extends HttpClient {
private int mInstanceNumber = 0; private int mInstanceNumber = 0;
private Uri mBaseUri; private Uri mBaseUri;
private String mUserAgent;
/** /**
* Constructor * Constructor
*/ */
public OwnCloudClient(Uri baseUri, HttpConnectionManager connectionMgr, String userAgent) { public OwnCloudClient(Uri baseUri, HttpConnectionManager connectionMgr) {
super(connectionMgr); super(connectionMgr);
if (baseUri == null) { if (baseUri == null) {
@ -83,8 +82,8 @@ public class OwnCloudClient extends HttpClient {
mInstanceNumber = sIntanceCounter++; mInstanceNumber = sIntanceCounter++;
Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient"); Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
mUserAgent = userAgent; String userAgent = OwnCloudClientManagerFactory.getUserAgent();
getParams().setParameter(HttpMethodParams.USER_AGENT, mUserAgent); getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
getParams().setParameter( getParams().setParameter(
CoreProtocolPNames.PROTOCOL_VERSION, CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_1); HttpVersion.HTTP_1_1);
@ -212,7 +211,8 @@ public class OwnCloudClient extends HttpClient {
// Update User Agent // Update User Agent
HttpParams params = method.getParams(); HttpParams params = method.getParams();
params.setParameter(HttpMethodParams.USER_AGENT, mUserAgent); String userAgent = OwnCloudClientManagerFactory.getUserAgent();
params.setParameter(HttpMethodParams.USER_AGENT, userAgent);
Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " + Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
method.getName() + " " + method.getPath()); method.getName() + " " + method.getPath());

View File

@ -61,7 +61,6 @@ public class OwnCloudClientFactory {
* *
* @param account The ownCloud account * @param account The ownCloud account
* @param appContext Android application context * @param appContext Android application context
* @param userAgent OwnCloud userAgent string
* @return A OwnCloudClient object ready to be used * @return A OwnCloudClient object ready to be used
* @throws AuthenticatorException If the authenticator failed to get the authorization * @throws AuthenticatorException If the authenticator failed to get the authorization
* token for the account. * token for the account.
@ -71,8 +70,7 @@ public class OwnCloudClientFactory {
* authorization token for the account. * authorization token for the account.
* @throws AccountNotFoundException If 'account' is unknown for the AccountManager * @throws AccountNotFoundException If 'account' is unknown for the AccountManager
*/ */
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext, public static OwnCloudClient createOwnCloudClient (Account account, Context appContext)
String userAgent)
throws OperationCanceledException, AuthenticatorException, IOException, throws OperationCanceledException, AuthenticatorException, IOException,
AccountNotFoundException { AccountNotFoundException {
//Log_OC.d(TAG, "Creating OwnCloudClient associated to " + account.name); //Log_OC.d(TAG, "Creating OwnCloudClient associated to " + account.name);
@ -83,7 +81,7 @@ public class OwnCloudClientFactory {
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null;
boolean isSamlSso = boolean isSamlSso =
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso, userAgent); OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
if (isOauth2) { if (isOauth2) {
String accessToken = am.blockingGetAuthToken( String accessToken = am.blockingGetAuthToken(
@ -127,7 +125,7 @@ public class OwnCloudClientFactory {
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext, public static OwnCloudClient createOwnCloudClient (Account account, Context appContext,
Activity currentActivity, String userAgent) Activity currentActivity)
throws OperationCanceledException, AuthenticatorException, IOException, throws OperationCanceledException, AuthenticatorException, IOException,
AccountNotFoundException { AccountNotFoundException {
Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account)); Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account));
@ -137,7 +135,7 @@ public class OwnCloudClientFactory {
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null;
boolean isSamlSso = boolean isSamlSso =
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso, userAgent); OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
if (isOauth2) { // TODO avoid a call to getUserData here if (isOauth2) { // TODO avoid a call to getUserData here
AccountManagerFuture<Bundle> future = am.getAuthToken( AccountManagerFuture<Bundle> future = am.getAuthToken(
@ -204,11 +202,10 @@ public class OwnCloudClientFactory {
* *
* @param uri URL to the ownCloud server; BASE ENTRY POINT, not WebDavPATH * @param uri URL to the ownCloud server; BASE ENTRY POINT, not WebDavPATH
* @param context Android context where the OwnCloudClient is being created. * @param context Android context where the OwnCloudClient is being created.
* @param userAgent OwnCloud userAgent string
* @return A OwnCloudClient object ready to be used * @return A OwnCloudClient object ready to be used
*/ */
public static OwnCloudClient createOwnCloudClient(Uri uri, Context context, public static OwnCloudClient createOwnCloudClient(Uri uri, Context context,
boolean followRedirects, String userAgent) { boolean followRedirects) {
try { try {
NetworkUtils.registerAdvancedSslContext(true, context); NetworkUtils.registerAdvancedSslContext(true, context);
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
@ -220,8 +217,7 @@ public class OwnCloudClientFactory {
" in the system will be used for HTTPS connections", e); " in the system will be used for HTTPS connections", e);
} }
OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager(), OwnCloudClient client = new OwnCloudClient(uri, NetworkUtils.getMultiThreadedConnManager());
userAgent);
client.setDefaultTimeouts(DEFAULT_DATA_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT); client.setDefaultTimeouts(DEFAULT_DATA_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
client.setFollowRedirects(followRedirects); client.setFollowRedirects(followRedirects);

View File

@ -42,7 +42,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce
public interface OwnCloudClientManager { public interface OwnCloudClientManager {
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context, String userAgent) public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException, throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
IOException; IOException;

View File

@ -34,6 +34,8 @@ public class OwnCloudClientManagerFactory {
private static OwnCloudClientManager sDefaultSingleton; private static OwnCloudClientManager sDefaultSingleton;
private static String sUserAgent;
public static OwnCloudClientManager newDefaultOwnCloudClientManager() { public static OwnCloudClientManager newDefaultOwnCloudClientManager() {
return newOwnCloudClientManager(sDefaultPolicy); return newOwnCloudClientManager(sDefaultPolicy);
} }
@ -72,6 +74,14 @@ public class OwnCloudClientManagerFactory {
sDefaultPolicy = policy; sDefaultPolicy = policy;
} }
public static void setUserAgent(String userAgent){
sUserAgent = userAgent;
}
public static String getUserAgent() {
return sUserAgent;
}
private static boolean defaultSingletonMustBeUpdated(Policy policy) { private static boolean defaultSingletonMustBeUpdated(Policy policy) {
if (sDefaultSingleton == null) { if (sDefaultSingleton == null) {
return false; return false;

View File

@ -40,7 +40,7 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
private static final String TAG = SimpleFactoryManager.class.getSimpleName(); private static final String TAG = SimpleFactoryManager.class.getSimpleName();
@Override @Override
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context, String userAgent) public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException, throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
IOException { IOException {
@ -49,8 +49,7 @@ public class SimpleFactoryManager implements OwnCloudClientManager {
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient( OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(
account.getBaseUri(), account.getBaseUri(),
context.getApplicationContext(), context.getApplicationContext(),
true, true);
userAgent);
Log_OC.v(TAG, " new client {" + Log_OC.v(TAG, " new client {" +
(account.getName() != null ? (account.getName() != null ?

View File

@ -62,8 +62,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
@Override @Override
public synchronized OwnCloudClient getClientFor(OwnCloudAccount account, Context context, public synchronized OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
String userAgent)
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException, throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
IOException { IOException {
@ -109,8 +108,7 @@ public class SingleSessionManager implements OwnCloudClientManager {
client = OwnCloudClientFactory.createOwnCloudClient( client = OwnCloudClientFactory.createOwnCloudClient(
account.getBaseUri(), account.getBaseUri(),
context.getApplicationContext(), context.getApplicationContext(),
true, true); // TODO remove dependency on OwnCloudClientFactory
userAgent); // TODO remove dependency on OwnCloudClientFactory
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
// enable cookie tracking // enable cookie tracking

View File

@ -81,9 +81,6 @@ public abstract class RemoteOperation implements Runnable {
/** Activity */ /** Activity */
private Activity mCallerActivity; private Activity mCallerActivity;
/** User agent */
private String mUserAgent;
/** /**
* Abstract method to implement the operation in derived classes. * Abstract method to implement the operation in derived classes.
@ -97,15 +94,14 @@ public abstract class RemoteOperation implements Runnable {
* Do not call this method from the main thread. * Do not call this method from the main thread.
* *
* This method should be used whenever an ownCloud account is available, instead of * This method should be used whenever an ownCloud account is available, instead of
* {@link #execute(OwnCloudClient, java.lang.String)}. * {@link #execute(OwnCloudClient)}.
* *
* @param account ownCloud account in remote ownCloud server to reach during the * @param account ownCloud account in remote ownCloud server to reach during the
* execution of the operation. * execution of the operation.
* @param context Android context for the component calling the method. * @param context Android context for the component calling the method.
* @param userAgent userAgent string
* @return Result of the operation. * @return Result of the operation.
*/ */
public RemoteOperationResult execute(Account account, Context context, String userAgent) { public RemoteOperationResult execute(Account account, Context context) {
if (account == null) if (account == null)
throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " +
"Account"); "Account");
@ -114,11 +110,10 @@ public abstract class RemoteOperation implements Runnable {
"Context"); "Context");
mAccount = account; mAccount = account;
mContext = context.getApplicationContext(); mContext = context.getApplicationContext();
mUserAgent = userAgent;
try { try {
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext); OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, mContext, mUserAgent); getClientFor(ocAccount, mContext);
} catch (Exception e) { } catch (Exception e) {
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e); Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e);
return new RemoteOperationResult(e); return new RemoteOperationResult(e);
@ -134,15 +129,13 @@ public abstract class RemoteOperation implements Runnable {
* *
* @param client Client object to reach an ownCloud server during the execution of * @param client Client object to reach an ownCloud server during the execution of
* the operation. * the operation.
* @param userAgent userAgent string
* @return Result of the operation. * @return Result of the operation.
*/ */
public RemoteOperationResult execute(OwnCloudClient client, String userAgent) { public RemoteOperationResult execute(OwnCloudClient client) {
if (client == null) if (client == null)
throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " + throw new IllegalArgumentException("Trying to execute a remote operation with a NULL " +
"OwnCloudClient"); "OwnCloudClient");
mClient = client; mClient = client;
mUserAgent = userAgent;
return run(client); return run(client);
} }
@ -151,10 +144,10 @@ public abstract class RemoteOperation implements Runnable {
* Asynchronously executes the remote operation * Asynchronously executes the remote operation
* *
* This method should be used whenever an ownCloud account is available, instead of * This method should be used whenever an ownCloud account is available, instead of
* {@link #execute(OwnCloudClient, java.lang.String)}. * {@link #execute(OwnCloudClient)}.
* *
* @deprecated This method will be removed in version 1.0. * @deprecated This method will be removed in version 1.0.
* Use {@link #execute(Account, Context, String, OnRemoteOperationListener, * Use {@link #execute(Account, Context, OnRemoteOperationListener,
* Handler)} instead. * Handler)} instead.
* *
* @param account ownCloud account in remote ownCloud server to reach during * @param account ownCloud account in remote ownCloud server to reach during
@ -193,18 +186,17 @@ public abstract class RemoteOperation implements Runnable {
* Asynchronously executes the remote operation * Asynchronously executes the remote operation
* *
* This method should be used whenever an ownCloud account is available, * This method should be used whenever an ownCloud account is available,
* instead of {@link #execute(OwnCloudClient, String, OnRemoteOperationListener, Handler))}. * instead of {@link #execute(OwnCloudClient, OnRemoteOperationListener, Handler))}.
* *
* @param account ownCloud account in remote ownCloud server to reach during the * @param account ownCloud account in remote ownCloud server to reach during the
* execution of the operation. * execution of the operation.
* @param context Android context for the component calling the method. * @param context Android context for the component calling the method.
* @param userAgent userAgent string
* @param listener Listener to be notified about the execution of the operation. * @param listener Listener to be notified about the execution of the operation.
* @param listenerHandler Handler associated to the thread where the methods of the listener * @param listenerHandler Handler associated to the thread where the methods of the listener
* objects must be called. * objects must be called.
* @return Thread were the remote operation is executed. * @return Thread were the remote operation is executed.
*/ */
public Thread execute(Account account, Context context, String userAgent, public Thread execute(Account account, Context context,
OnRemoteOperationListener listener, Handler listenerHandler) { OnRemoteOperationListener listener, Handler listenerHandler) {
if (account == null) if (account == null)
@ -234,20 +226,18 @@ public abstract class RemoteOperation implements Runnable {
* *
* @param client Client object to reach an ownCloud server * @param client Client object to reach an ownCloud server
* during the execution of the operation. * during the execution of the operation.
* @param userAgent userAgent string
* @param listener Listener to be notified about the execution of the operation. * @param listener Listener to be notified about the execution of the operation.
* @param listenerHandler Handler associated to the thread where the methods of * @param listenerHandler Handler associated to the thread where the methods of
* the listener objects must be called. * the listener objects must be called.
* @return Thread were the remote operation is executed. * @return Thread were the remote operation is executed.
*/ */
public Thread execute(OwnCloudClient client, String userAgent, public Thread execute(OwnCloudClient client,
OnRemoteOperationListener listener, Handler listenerHandler) { OnRemoteOperationListener listener, Handler listenerHandler) {
if (client == null) { if (client == null) {
throw new IllegalArgumentException throw new IllegalArgumentException
("Trying to execute a remote operation with a NULL OwnCloudClient"); ("Trying to execute a remote operation with a NULL OwnCloudClient");
} }
mClient = client; mClient = client;
mUserAgent = userAgent;
if (listener == null) { if (listener == null) {
throw new IllegalArgumentException throw new IllegalArgumentException
@ -270,7 +260,7 @@ public abstract class RemoteOperation implements Runnable {
/** /**
* Asynchronous execution of the operation * Asynchronous execution of the operation
* started by {@link RemoteOperation#execute(OwnCloudClient, String, * started by {@link RemoteOperation#execute(OwnCloudClient,
* OnRemoteOperationListener, Handler)}, * OnRemoteOperationListener, Handler)},
* and result posting. * and result posting.
* *
@ -287,12 +277,12 @@ public abstract class RemoteOperation implements Runnable {
/** DEPRECATED BLOCK - will be removed at version 1.0 */ /** DEPRECATED BLOCK - will be removed at version 1.0 */
if (mCallerActivity != null) { if (mCallerActivity != null) {
mClient = OwnCloudClientFactory.createOwnCloudClient( mClient = OwnCloudClientFactory.createOwnCloudClient(
mAccount, mContext, mCallerActivity, mUserAgent); mAccount, mContext, mCallerActivity);
} else { } else {
/** EOF DEPRECATED */ /** EOF DEPRECATED */
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext); OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, mContext, mUserAgent); getClientFor(ocAccount, mContext);
} }
} else { } else {
@ -371,13 +361,4 @@ public abstract class RemoteOperation implements Runnable {
return mClient; return mClient;
} }
/**
* Returns the user agent string
* @return
*/
public final String getUserAgent() {
return mUserAgent;
}
} }

View File

@ -75,7 +75,6 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
} }
mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex); mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER); mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
mPutMethod.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
((ChunkFromFileChannelRequestEntity)mEntity).setOffset(offset); ((ChunkFromFileChannelRequestEntity)mEntity).setOffset(offset);
mPutMethod.setRequestEntity(mEntity); mPutMethod.setRequestEntity(mEntity);
status = client.executeMethod(mPutMethod); status = client.executeMethod(mPutMethod);

View File

@ -78,8 +78,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
result = createFolder(client); result = createFolder(client);
if (!result.isSuccess() && mCreateFullPath && if (!result.isSuccess() && mCreateFullPath &&
RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) {
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client, result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
getUserAgent());
if (result.isSuccess()) { if (result.isSuccess()) {
result = createFolder(client); // second (and last) try result = createFolder(client); // second (and last) try
} }
@ -98,7 +97,6 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
MkColMethod mkcol = null; MkColMethod mkcol = null;
try { try {
mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
mkcol.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders()); result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
@ -115,11 +113,10 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
return result; return result;
} }
private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client, private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) {
String userAgent) {
RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, RemoteOperation operation = new CreateRemoteFolderOperation(parentPath,
mCreateFullPath); mCreateFullPath);
return operation.execute(client, userAgent); return operation.execute(client);
} }

View File

@ -102,7 +102,6 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
int status = -1; int status = -1;
boolean savedFile = false; boolean savedFile = false;
mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
mGet.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
Iterator<OnDatatransferProgressListener> it = null; Iterator<OnDatatransferProgressListener> it = null;
FileOutputStream fos = null; FileOutputStream fos = null;

View File

@ -77,7 +77,6 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
HeadMethod head = null; HeadMethod head = null;
try { try {
head = new HeadMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath)); head = new HeadMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath));
head.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(head, TIMEOUT, TIMEOUT); int status = client.executeMethod(head, TIMEOUT, TIMEOUT);
client.exhaustResponse(head.getResponseBodyAsStream()); client.exhaustResponse(head.getResponseBodyAsStream());
boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) ||

View File

@ -113,7 +113,6 @@ public class MoveRemoteFileOperation extends RemoteOperation {
client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath),
mOverwrite mOverwrite
); );
move.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT); int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT);
/// process response /// process response

View File

@ -79,7 +79,6 @@ public class ReadRemoteFileOperation extends RemoteOperation {
propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
WebdavUtils.getFilePropSet(), // PropFind Properties WebdavUtils.getFilePropSet(), // PropFind Properties
DavConstants.DEPTH_0); DavConstants.DEPTH_0);
propfind.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status; int status;
status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);

View File

@ -76,7 +76,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
WebdavUtils.getAllPropSet(), // PropFind Properties WebdavUtils.getAllPropSet(), // PropFind Properties
DavConstants.DEPTH_1); DavConstants.DEPTH_1);
query.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(query); int status = client.executeMethod(query);
// check and process response // check and process response

View File

@ -68,7 +68,6 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
try { try {
delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
delete.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
delete.getResponseBodyAsString(); // exhaust the response, although not interesting delete.getResponseBodyAsString(); // exhaust the response, although not interesting

View File

@ -107,7 +107,6 @@ public class RenameRemoteFileOperation extends RemoteOperation {
move = new LocalMoveMethod( client.getWebdavUri() + move = new LocalMoveMethod( client.getWebdavUri() +
WebdavUtils.encodePath(mOldRemotePath), WebdavUtils.encodePath(mOldRemotePath),
client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath)); client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath));
move.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
int status = client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT); int status = client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT);
move.getResponseBodyAsString(); // exhaust response, although not interesting move.getResponseBodyAsString(); // exhaust response, although not interesting

View File

@ -82,7 +82,6 @@ public class UploadRemoteFileOperation extends RemoteOperation {
} else { } else {
mPutMethod = new PutMethod(client.getWebdavUri() + mPutMethod = new PutMethod(client.getWebdavUri() +
WebdavUtils.encodePath(mRemotePath)); WebdavUtils.encodePath(mRemotePath));
mPutMethod.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
} }
} }

View File

@ -106,7 +106,6 @@ public class CreateRemoteShareOperation extends RemoteOperation {
post.setRequestHeader( "Content-Type", post.setRequestHeader( "Content-Type",
"application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters
post.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
post.addParameter(PARAM_PATH, mRemoteFilePath); post.addParameter(PARAM_PATH, mRemoteFilePath);
post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue()));

View File

@ -86,7 +86,6 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
try { try {
// Get Method // Get Method
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
// Add Parameters to Get Method // Add Parameters to Get Method
get.setQueryString(new NameValuePair[] { get.setQueryString(new NameValuePair[] {

View File

@ -67,7 +67,6 @@ public class GetRemoteSharesOperation extends RemoteOperation {
try{ try{
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
status = client.executeMethod(get); status = client.executeMethod(get);
if(isSuccess(status)) { if(isSuccess(status)) {
String response = get.getResponseBodyAsString(); String response = get.getResponseBodyAsString();

View File

@ -72,7 +72,6 @@ public class RemoveRemoteShareOperation extends RemoteOperation {
delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id); delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id);
delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
delete.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
status = client.executeMethod(delete); status = client.executeMethod(delete);

View File

@ -38,6 +38,7 @@ import android.net.ConnectivityManager;
import android.net.Uri; import android.net.Uri;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -77,10 +78,10 @@ public class GetRemoteStatusOperation extends RemoteOperation {
String baseUrlSt = client.getBaseUri().toString(); String baseUrlSt = client.getBaseUri().toString();
try { try {
get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH); get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH);
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
HttpParams params = get.getParams().getDefaultParams(); HttpParams params = get.getParams().getDefaultParams();
params.setParameter(HttpMethodParams.USER_AGENT, getUserAgent()); params.setParameter(HttpMethodParams.USER_AGENT,
OwnCloudClientManagerFactory.getUserAgent());
get.getParams().setDefaults(params); get.getParams().setDefaults(params);
client.setFollowRedirects(false); client.setFollowRedirects(false);

View File

@ -79,7 +79,6 @@ public class GetRemoteUserNameOperation extends RemoteOperation {
try { try {
get = new GetMethod(client.getBaseUri() + OCS_ROUTE); get = new GetMethod(client.getBaseUri() + OCS_ROUTE);
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
status = client.executeMethod(get); status = client.executeMethod(get);
if(isSuccess(status)) { if(isSuccess(status)) {
String response = get.getResponseBodyAsString(); String response = get.getResponseBodyAsString();

View File

@ -72,7 +72,6 @@ public class TestActivity extends Activity {
private String mServerUri; private String mServerUri;
private String mUser; private String mUser;
private String mPass; private String mPass;
private static String mUserAgent;
private static final int BUFFER_SIZE = 1024; private static final int BUFFER_SIZE = 1024;
@ -91,7 +90,6 @@ public class TestActivity extends Activity {
mServerUri = getString(R.string.server_base_url); mServerUri = getString(R.string.server_base_url);
mUser = getString(R.string.username); mUser = getString(R.string.username);
mPass = getString(R.string.password); mPass = getString(R.string.password);
mUserAgent = getString(R.string.user_agent);
Protocol pr = Protocol.getProtocol("https"); Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
@ -106,8 +104,7 @@ public class TestActivity extends Activity {
} }
} }
mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager(), mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
mClient.setDefaultTimeouts( mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
@ -159,7 +156,7 @@ public class TestActivity extends Activity {
CreateRemoteFolderOperation createOperation = CreateRemoteFolderOperation createOperation =
new CreateRemoteFolderOperation(remotePath, createFullPath); new CreateRemoteFolderOperation(remotePath, createFullPath);
RemoteOperationResult result = createOperation.execute(client, mUserAgent); RemoteOperationResult result = createOperation.execute(client);
return result; return result;
} }
@ -177,7 +174,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) { public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) {
RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder); RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder);
RemoteOperationResult result = renameOperation.execute(mClient, mUserAgent); RemoteOperationResult result = renameOperation.execute(mClient);
return result; return result;
} }
@ -190,7 +187,7 @@ public class TestActivity extends Activity {
*/ */
public RemoteOperationResult removeFile(String remotePath) { public RemoteOperationResult removeFile(String remotePath) {
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
RemoteOperationResult result = removeOperation.execute(mClient, mUserAgent); RemoteOperationResult result = removeOperation.execute(mClient);
return result; return result;
} }
@ -202,7 +199,7 @@ public class TestActivity extends Activity {
*/ */
public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) { public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) {
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
RemoteOperationResult result = removeOperation.execute(client, mUserAgent); RemoteOperationResult result = removeOperation.execute(client);
return result; return result;
} }
@ -216,7 +213,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult readFile(String remotePath) { public RemoteOperationResult readFile(String remotePath) {
ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath); ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath);
RemoteOperationResult result = readOperation.execute(mClient, mUserAgent); RemoteOperationResult result = readOperation.execute(mClient);
return result; return result;
} }
@ -235,7 +232,7 @@ public class TestActivity extends Activity {
folder.mkdirs(); folder.mkdirs();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remoteFile.getRemotePath(), folder.getAbsolutePath()); DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remoteFile.getRemotePath(), folder.getAbsolutePath());
RemoteOperationResult result = downloadOperation.execute(mClient, mUserAgent); RemoteOperationResult result = downloadOperation.execute(mClient);
return result; return result;
} }
@ -276,7 +273,7 @@ public class TestActivity extends Activity {
); );
} }
RemoteOperationResult result = uploadOperation.execute(client, mUserAgent); RemoteOperationResult result = uploadOperation.execute(client);
return result; return result;
} }
@ -287,7 +284,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult getShares(){ public RemoteOperationResult getShares(){
GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation(); GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation();
RemoteOperationResult result = getOperation.execute(mClient, mUserAgent); RemoteOperationResult result = getOperation.execute(mClient);
return result; return result;
} }
@ -315,7 +312,7 @@ public class TestActivity extends Activity {
String password, int permissions){ String password, int permissions){
CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, publicUpload, password, permissions); CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, publicUpload, password, permissions);
RemoteOperationResult result = createOperation.execute(mClient, mUserAgent); RemoteOperationResult result = createOperation.execute(mClient);
return result; return result;
} }
@ -329,7 +326,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult removeShare(int idShare) { public RemoteOperationResult removeShare(int idShare) {
RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare); RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare);
RemoteOperationResult result = removeOperation.execute(mClient, mUserAgent); RemoteOperationResult result = removeOperation.execute(mClient);
return result; return result;

View File

@ -279,8 +279,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FILE_1, mBaseFolderPath + TARGET_PATH_TO_FILE_1,
false false
); );
RemoteOperationResult result = moveOperation.execute(mClient, RemoteOperationResult result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move & rename file, different location // move & rename file, different location
@ -289,8 +288,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED, mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move & rename file, same location (rename file) // move & rename file, same location (rename file)
@ -299,8 +297,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED, mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move empty folder // move empty folder
@ -309,8 +306,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER, mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move non-empty folder // move non-empty folder
@ -319,8 +315,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1, mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move & rename folder, different location // move & rename folder, different location
@ -329,8 +324,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED, mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move & rename folder, same location (rename folder) // move & rename folder, same location (rename folder)
@ -339,8 +333,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED, mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move for nothing (success, but no interaction with network) // move for nothing (success, but no interaction with network)
@ -349,8 +342,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_FILE_4, mBaseFolderPath + SRC_PATH_TO_FILE_4,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
// move overwriting // move overwriting
@ -359,8 +351,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
true true
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
@ -372,8 +363,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE, mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND); assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND);
// folder to move into does no exist // folder to move into does no exist
@ -382,8 +372,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER, mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT); assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT);
// target location (renaming) has invalid characters // target location (renaming) has invalid characters
@ -392,8 +381,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS, mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
// name collision // name collision
@ -402,8 +390,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7, mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE); assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE);
// move a folder into a descendant // move a folder into a descendant
@ -412,8 +399,7 @@ public class MoveFileTest extends RemoteTest {
mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER, mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
false false
); );
result = moveOperation.execute(mClient, result = moveOperation.execute(mClient);
getContext().getString(R.string.user_agent));
assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT); assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT);
} }
@ -450,8 +436,7 @@ public class MoveFileTest extends RemoteTest {
mClient = new OwnCloudClient( mClient = new OwnCloudClient(
Uri.parse(mServerUri), Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager(), NetworkUtils.getMultiThreadedConnManager()
getContext().getString(R.string.user_agent)
); );
mClient.setDefaultTimeouts( mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,

View File

@ -97,8 +97,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testConstructor() { public void testConstructor() {
try { try {
new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager(), new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
throw new AssertionFailedError("Accepted NULL parameter"); throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) { } catch(Exception e) {
@ -107,7 +106,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
} }
try { try {
new OwnCloudClient(mServerUri, null, mUserAgent); new OwnCloudClient(mServerUri, null);
throw new AssertionFailedError("Accepted NULL parameter"); throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) { } catch(Exception e) {
@ -116,8 +115,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
} }
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
assertNotNull("OwnCloudClient instance not built", client); assertNotNull("OwnCloudClient instance not built", client);
assertEquals("Wrong user agent", assertEquals("Wrong user agent",
client.getParams().getParameter(HttpMethodParams.USER_AGENT), client.getParams().getParameter(HttpMethodParams.USER_AGENT),
@ -127,8 +125,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetSetCredentials() { public void testGetSetCredentials() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
assertNotNull("Returned NULL credentials", client.getCredentials()); assertNotNull("Returned NULL credentials", client.getCredentials());
assertEquals("Not instanced without credentials", assertEquals("Not instanced without credentials",
@ -151,8 +148,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testExecuteMethodWithTimeouts() throws HttpException, IOException { public void testExecuteMethodWithTimeouts() throws HttpException, IOException {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
int connectionTimeout = client.getConnectionTimeout(); int connectionTimeout = client.getConnectionTimeout();
int readTimeout = client.getDataTimeout(); int readTimeout = client.getDataTimeout();
@ -200,8 +196,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testExecuteMethod() { public void testExecuteMethod() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
int status = -1; int status = -1;
try { try {
@ -222,8 +217,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testExhaustResponse() { public void testExhaustResponse() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
PropFindMethod propfind = null; PropFindMethod propfind = null;
try { try {
@ -265,8 +259,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetSetDefaultTimeouts() { public void testGetSetDefaultTimeouts() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
int oldDataTimeout = client.getDataTimeout(); int oldDataTimeout = client.getDataTimeout();
int oldConnectionTimeout = client.getConnectionTimeout(); int oldConnectionTimeout = client.getConnectionTimeout();
@ -306,8 +299,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetWebdavUri() { public void testGetWebdavUri() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken")); client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken"));
Uri webdavUri = client.getWebdavUri(); Uri webdavUri = client.getWebdavUri();
assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " + assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " +
@ -345,8 +337,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
public void testGetSetBaseUri() { public void testGetSetBaseUri() {
OwnCloudClient client = OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
mUserAgent);
assertEquals("Returned base URI different that URI passed to constructor", assertEquals("Returned base URI different that URI passed to constructor",
mServerUri, client.getBaseUri()); mServerUri, client.getBaseUri());

View File

@ -95,16 +95,13 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
public void testGetClientFor() { public void testGetClientFor() {
try { try {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext(), OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
getContext().getString(R.string.user_agent));
assertNotSame("Got same client instances for same account", assertNotSame("Got same client instances for same account",
client, mSFMgr.getClientFor(mValidAccount, getContext(), client, mSFMgr.getClientFor(mValidAccount, getContext()));
getContext().getString(R.string.user_agent)));
assertNotSame("Got same client instances for different accounts", assertNotSame("Got same client instances for different accounts",
client, mSFMgr.getClientFor(mAnonymousAccount, getContext(), client, mSFMgr.getClientFor(mAnonymousAccount, getContext()));
getContext().getString(R.string.user_agent)));
} catch (Exception e) { } catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
@ -114,12 +111,10 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
public void testRemoveClientFor() { public void testRemoveClientFor() {
try { try {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext(), OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
getContext().getString(R.string.user_agent));
mSFMgr.removeClientFor(mValidAccount); mSFMgr.removeClientFor(mValidAccount);
assertNotSame("Got same client instance after removing it from manager", assertNotSame("Got same client instance after removing it from manager",
client, mSFMgr.getClientFor(mValidAccount, getContext(), client, mSFMgr.getClientFor(mValidAccount, getContext()));
getContext().getString(R.string.user_agent)));
} catch (Exception e) { } catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());

View File

@ -94,16 +94,13 @@ public class SingleSessionManagerTest extends AndroidTestCase {
public void testGetClientFor() { public void testGetClientFor() {
try { try {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext(), OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
getContext().getString(R.string.user_agent)); OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext());
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext(),
getContext().getString(R.string.user_agent));
assertNotSame("Got same client instances for different accounts", assertNotSame("Got same client instances for different accounts",
client1, client2); client1, client2);
assertSame("Got different client instances for same account", assertSame("Got different client instances for same account",
client1, mSSMgr.getClientFor(mValidAccount, getContext(), client1, mSSMgr.getClientFor(mValidAccount, getContext()));
getContext().getString(R.string.user_agent)));
} catch (Exception e) { } catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
@ -114,12 +111,10 @@ public class SingleSessionManagerTest extends AndroidTestCase {
public void testRemoveClientFor() { public void testRemoveClientFor() {
try { try {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext(), OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
getContext().getString(R.string.user_agent));
mSSMgr.removeClientFor(mValidAccount); mSSMgr.removeClientFor(mValidAccount);
assertNotSame("Got same client instance after removing it from manager", assertNotSame("Got same client instance after removing it from manager",
client1, mSSMgr.getClientFor(mValidAccount, getContext(), client1, mSSMgr.getClientFor(mValidAccount, getContext()));
getContext().getString(R.string.user_agent)));
} catch (Exception e) { } catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
} }