mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 00:16:09 +00:00
Parse and show the error of invalid characters coming from the server side: Move, Rename, Uploads
This commit is contained in:
parent
2b09aa2a89
commit
16c9147383
@ -42,7 +42,6 @@ import org.apache.commons.httpclient.HttpException;
|
|||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.jackrabbit.webdav.DavException;
|
import org.apache.jackrabbit.webdav.DavException;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountsException;
|
import android.accounts.AccountsException;
|
||||||
@ -50,7 +49,6 @@ import android.accounts.AccountsException;
|
|||||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||||
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.lib.resources.shares.ShareXMLParser;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,9 +62,9 @@ import com.owncloud.android.lib.resources.shares.ShareXMLParser;
|
|||||||
public class RemoteOperationResult implements Serializable {
|
public class RemoteOperationResult implements Serializable {
|
||||||
|
|
||||||
/** Generated - should be refreshed every time the class changes!! */;
|
/** Generated - should be refreshed every time the class changes!! */;
|
||||||
private static final long serialVersionUID = -9003837206000993465L;
|
private static final long serialVersionUID = -4184015692120731701L;
|
||||||
|
|
||||||
private static final String TAG = "RemoteOperationResult";
|
private static final String TAG = RemoteOperationResult.class.getSimpleName();
|
||||||
|
|
||||||
public enum ResultCode {
|
public enum ResultCode {
|
||||||
OK,
|
OK,
|
||||||
|
@ -46,7 +46,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
|||||||
private static final String OC_CHUNKED_HEADER = "OC-Chunked";
|
private static final String OC_CHUNKED_HEADER = "OC-Chunked";
|
||||||
private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName();
|
private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName();
|
||||||
|
|
||||||
public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType) {
|
public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType){
|
||||||
super(storagePath, remotePath, mimeType);
|
super(storagePath, remotePath, mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,17 +61,21 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
|||||||
raf = new RandomAccessFile(file, "r");
|
raf = new RandomAccessFile(file, "r");
|
||||||
channel = raf.getChannel();
|
channel = raf.getChannel();
|
||||||
mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file);
|
mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file);
|
||||||
//((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(getDataTransferListeners());
|
//((ProgressiveDataTransferer)mEntity).
|
||||||
|
// addDatatransferProgressListeners(getDataTransferListeners());
|
||||||
synchronized (mDataTransferListeners) {
|
synchronized (mDataTransferListeners) {
|
||||||
((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(mDataTransferListeners);
|
((ProgressiveDataTransferer)mEntity)
|
||||||
|
.addDatatransferProgressListeners(mDataTransferListeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
long offset = 0;
|
long offset = 0;
|
||||||
String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + "-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ;
|
String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) +
|
||||||
|
"-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ;
|
||||||
long chunkCount = (long) Math.ceil((double)file.length() / CHUNK_SIZE);
|
long chunkCount = (long) Math.ceil((double)file.length() / CHUNK_SIZE);
|
||||||
for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) {
|
for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) {
|
||||||
if (mPutMethod != null) {
|
if (mPutMethod != null) {
|
||||||
mPutMethod.releaseConnection(); // let the connection available for other methods
|
mPutMethod.releaseConnection(); // let the connection available
|
||||||
|
// for other methods
|
||||||
}
|
}
|
||||||
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);
|
||||||
@ -80,7 +84,8 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
|||||||
mPutMethod.setRequestEntity(mEntity);
|
mPutMethod.setRequestEntity(mEntity);
|
||||||
status = client.executeMethod(mPutMethod);
|
status = client.executeMethod(mPutMethod);
|
||||||
client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
|
client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
|
||||||
Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ", chunk index " + chunkIndex + ", count " + chunkCount + ", HTTP result status " + status);
|
Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ", chunk index " +
|
||||||
|
chunkIndex + ", count " + chunkCount + ", HTTP result status " + status);
|
||||||
if (!isSuccess(status))
|
if (!isSuccess(status))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ import com.owncloud.android.lib.common.network.WebdavUtils;
|
|||||||
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;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,15 +130,18 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
/// for other errors that could be explicitly handled, check first:
|
/// for other errors that could be explicitly handled, check first:
|
||||||
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
||||||
|
|
||||||
} else {
|
} else if (status == 400) {
|
||||||
|
result = new RemoteOperationResult(move.succeeded(),
|
||||||
result = new RemoteOperationResult(
|
move.getResponseBodyAsString(), status);
|
||||||
isSuccess(status), // move.succeeded()? trustful?
|
Log_OC.d(TAG, move.getResponseBodyAsString());
|
||||||
status,
|
} else {
|
||||||
move.getResponseHeaders()
|
result = new RemoteOperationResult(
|
||||||
);
|
isSuccess(status), // move.succeeded()? trustful?
|
||||||
client.exhaustResponse(move.getResponseBodyAsStream());
|
status,
|
||||||
}
|
move.getResponseHeaders()
|
||||||
|
);
|
||||||
|
client.exhaustResponse(move.getResponseBodyAsStream());
|
||||||
|
}
|
||||||
|
|
||||||
Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
||||||
result.getLogMessage());
|
result.getLogMessage());
|
||||||
|
@ -94,12 +94,10 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
if (noInvalidChars) {
|
if (noInvalidChars) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (mNewName.equals(mOldName)) {
|
if (mNewName.equals(mOldName)) {
|
||||||
return new RemoteOperationResult(ResultCode.OK);
|
return new RemoteOperationResult(ResultCode.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// check if a file with the new name already exists
|
// check if a file with the new name already exists
|
||||||
if (client.existsFile(mNewRemotePath)) {
|
if (client.existsFile(mNewRemotePath)) {
|
||||||
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
||||||
@ -110,11 +108,17 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath));
|
client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath));
|
||||||
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
|
if (status == 400) {
|
||||||
result = new RemoteOperationResult(move.succeeded(), status, move.getResponseHeaders());
|
result = new RemoteOperationResult(move.succeeded(),
|
||||||
Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " +
|
move.getResponseBodyAsString(), status);
|
||||||
result.getLogMessage());
|
Log_OC.d(TAG, move.getResponseBodyAsString());
|
||||||
|
} else {
|
||||||
|
move.getResponseBodyAsString(); // exhaust response, although not interesting
|
||||||
|
result = new RemoteOperationResult(move.succeeded(), status,
|
||||||
|
move.getResponseHeaders());
|
||||||
|
Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " +
|
||||||
|
result.getLogMessage());
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " +
|
Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " +
|
||||||
|
@ -43,6 +43,7 @@ import com.owncloud.android.lib.common.network.WebdavUtils;
|
|||||||
import com.owncloud.android.lib.common.operations.OperationCancelledException;
|
import com.owncloud.android.lib.common.operations.OperationCancelledException;
|
||||||
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;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the upload of a remote file to the ownCloud server.
|
* Remote operation performing the upload of a remote file to the ownCloud server.
|
||||||
@ -53,6 +54,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|||||||
|
|
||||||
public class UploadRemoteFileOperation extends RemoteOperation {
|
public class UploadRemoteFileOperation extends RemoteOperation {
|
||||||
|
|
||||||
|
private static final String TAG = UploadRemoteFileOperation.class.getSimpleName();
|
||||||
|
|
||||||
protected static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length";
|
protected static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length";
|
||||||
|
|
||||||
protected String mLocalPath;
|
protected String mLocalPath;
|
||||||
@ -87,10 +90,14 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int status = uploadFile(client);
|
int status = uploadFile(client);
|
||||||
|
if (status == 400) {
|
||||||
result = new RemoteOperationResult(isSuccess(status), status,
|
result = new RemoteOperationResult(isSuccess(status),
|
||||||
(mPutMethod != null ? mPutMethod.getResponseHeaders() : null));
|
mPutMethod.getResponseBodyAsString(), status);
|
||||||
|
Log_OC.d(TAG, mPutMethod.getResponseBodyAsString());
|
||||||
|
} else {
|
||||||
|
result = new RemoteOperationResult(isSuccess(status), status,
|
||||||
|
(mPutMethod != null ? mPutMethod.getResponseHeaders() : null));
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO something cleaner with cancellations
|
// TODO something cleaner with cancellations
|
||||||
if (mCancellationRequested.get()) {
|
if (mCancellationRequested.get()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user