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

Keep http phrase in RemoteOperationResult as last chance for a detailed user message

This commit is contained in:
David A. Velasco 2017-01-12 17:32:50 +01:00
parent 67665b8691
commit 14d646ea1d
24 changed files with 991 additions and 1000 deletions

View File

@ -45,6 +45,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.jackrabbit.webdav.DavException;
import org.json.JSONException;
@ -63,9 +64,8 @@ import javax.net.ssl.SSLException;
public class RemoteOperationResult implements Serializable {
/** Generated - should be refreshed every time the class changes!! */
;
private static final long serialVersionUID = 4968939884332372230L;
private static final long serialVersionUID = -1909603208238358633L;
private static final String TAG = RemoteOperationResult.class.getSimpleName();
public enum ResultCode {
@ -120,6 +120,7 @@ public class RemoteOperationResult implements Serializable {
private boolean mSuccess = false;
private int mHttpCode = -1;
private String mHttpPhrase = null;
private Exception mException = null;
private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
private String mRedirectedLocation;
@ -128,6 +129,13 @@ public class RemoteOperationResult implements Serializable {
private ArrayList<Object> mData;
/**
* Public constructor from result code.
*
* To be used when the caller takes the responsibility of interpreting the result of a {@link RemoteOperation}
*
* @param code {@link ResultCode} decided by the caller.
*/
public RemoteOperationResult(ResultCode code) {
mCode = code;
mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL ||
@ -136,96 +144,15 @@ public class RemoteOperationResult implements Serializable {
mData = null;
}
private RemoteOperationResult(boolean success, int httpCode) {
mSuccess = success;
mHttpCode = httpCode;
if (success) {
mCode = ResultCode.OK;
} else if (httpCode > 0) {
switch (httpCode) {
case HttpStatus.SC_UNAUTHORIZED:
mCode = ResultCode.UNAUTHORIZED;
break;
case HttpStatus.SC_NOT_FOUND:
mCode = ResultCode.FILE_NOT_FOUND;
break;
case HttpStatus.SC_INTERNAL_SERVER_ERROR:
mCode = ResultCode.INSTANCE_NOT_CONFIGURED;
break;
case HttpStatus.SC_CONFLICT:
mCode = ResultCode.CONFLICT;
break;
case HttpStatus.SC_INSUFFICIENT_STORAGE:
mCode = ResultCode.QUOTA_EXCEEDED;
break;
case HttpStatus.SC_FORBIDDEN:
mCode = ResultCode.FORBIDDEN;
break;
case HttpStatus.SC_SERVICE_UNAVAILABLE:
mCode = ResultCode.MAINTENANCE_MODE;
break;
default:
mCode = ResultCode.UNHANDLED_HTTP_CODE;
Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " +
httpCode);
}
}
}
public RemoteOperationResult(boolean success, int httpCode, Header[] headers) {
this(success, httpCode);
if (headers != null) {
Header current;
for (int i = 0; i < headers.length; i++) {
current = headers[i];
if ("location".equals(current.getName().toLowerCase())) {
mRedirectedLocation = current.getValue();
continue;
}
if ("www-authenticate".equals(current.getName().toLowerCase())) {
mAuthenticate = current.getValue();
continue;
}
}
}
if (isIdPRedirection()) {
mCode = ResultCode.UNAUTHORIZED; // overrides default ResultCode.UNKNOWN
}
}
public RemoteOperationResult(boolean success, String bodyResponse, int httpCode) {
mSuccess = success;
mHttpCode = httpCode;
if (success) {
mCode = ResultCode.OK;
} else if (httpCode > 0) {
switch (httpCode) {
case HttpStatus.SC_BAD_REQUEST:
InputStream is = new ByteArrayInputStream(bodyResponse.getBytes());
InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser();
try {
if (xmlParser.parseXMLResponse(is))
mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER;
} catch (Exception e) {
mCode = ResultCode.UNHANDLED_HTTP_CODE;
Log_OC.e(TAG, "Exception reading exception from server", e);
}
break;
default:
mCode = ResultCode.UNHANDLED_HTTP_CODE;
Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " +
httpCode);
}
}
}
/**
* Public constructor from exception.
*
* To be used when an exception prevented the end of the {@link RemoteOperation}.
*
* Determines a {@link ResultCode} depending on the type of the exception.
*
* @param e Exception that interrupted the {@link RemoteOperation}
*/
public RemoteOperationResult(Exception e) {
mException = e;
@ -276,6 +203,133 @@ public class RemoteOperationResult implements Serializable {
}
/**
* Public constructor from separate elements of an HTTP or DAV response.
*
* To be used when the result needs to be interpreted from the response of an HTTP/DAV method.
*
* Determines a {@link ResultCode} from the already executed method received as a parameter. Generally,
* will depend on the HTTP code and HTTP response headers received. In some cases will inspect also the
* response body.
*
* @param success The operation was considered successful or not.
* @param httpMethod HTTP/DAV method already executed which response will be examined to interpret the
* result.
*/
public RemoteOperationResult(boolean success, HttpMethod httpMethod) throws IOException {
this(
success,
httpMethod.getStatusCode(),
httpMethod.getStatusText(),
httpMethod.getResponseHeaders()
);
if (mHttpCode == HttpStatus.SC_BAD_REQUEST) { // 400
String bodyResponse = httpMethod.getResponseBodyAsString();
// do not get for other HTTP codes!; could not be available
if (bodyResponse != null && bodyResponse.length() > 0) {
InputStream is = new ByteArrayInputStream(bodyResponse.getBytes());
InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser();
try {
if (xmlParser.parseXMLResponse(is)) {
mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER;
}
} catch (Exception e) {
Log_OC.w(TAG, "Error reading exception from server: " + e.getMessage());
// mCode stays as set in this(success, httpCode, headers)
}
}
}
}
/**
* Public constructor from separate elements of an HTTP or DAV response.
*
* To be used when the result needs to be interpreted from HTTP response elements that could come from
* different requests (WARNING: black magic, try to avoid).
*
* If all the fields come from the same HTTP/DAV response, {@link #RemoteOperationResult(boolean, HttpMethod)}
* should be used instead.
*
* Determines a {@link ResultCode} depending on the HTTP code and HTTP response headers received.
*
* @param success The operation was considered successful or not.
* @param httpCode HTTP status code returned by an HTTP/DAV method.
* @param httpPhrase HTTP status line phrase returned by an HTTP/DAV method
* @param httpHeaders HTTP response header returned by an HTTP/DAV method
*/
public RemoteOperationResult(boolean success, int httpCode, String httpPhrase, Header[] httpHeaders) {
this(success, httpCode, httpPhrase);
if (httpHeaders != null) {
Header current;
for (Header httpHeader : httpHeaders) {
current = httpHeader;
if ("location".equals(current.getName().toLowerCase())) {
mRedirectedLocation = current.getValue();
continue;
}
if ("www-authenticate".equals(current.getName().toLowerCase())) {
mAuthenticate = current.getValue();
break;
}
}
}
if (isIdPRedirection()) {
mCode = ResultCode.UNAUTHORIZED; // overrides default ResultCode.UNKNOWN
}
}
/**
* Private constructor for results built interpreting a HTTP or DAV response.
*
* Determines a {@link ResultCode} depending of the type of the exception.
*
* @param success Operation was successful or not.
* @param httpCode HTTP status code returned by the HTTP/DAV method.
* @param httpPhrase HTTP status line phrase returned by the HTTP/DAV method
*/
private RemoteOperationResult(boolean success, int httpCode, String httpPhrase) {
mSuccess = success;
mHttpCode = httpCode;
mHttpPhrase = httpPhrase;
if (success) {
mCode = ResultCode.OK;
} else if (httpCode > 0) {
switch (httpCode) {
case HttpStatus.SC_UNAUTHORIZED: // 401
mCode = ResultCode.UNAUTHORIZED;
break;
case HttpStatus.SC_FORBIDDEN: // 403
mCode = ResultCode.FORBIDDEN;
break;
case HttpStatus.SC_NOT_FOUND: // 404
mCode = ResultCode.FILE_NOT_FOUND;
break;
case HttpStatus.SC_CONFLICT: // 409
mCode = ResultCode.CONFLICT;
break;
case HttpStatus.SC_INTERNAL_SERVER_ERROR: // 500
mCode = ResultCode.INSTANCE_NOT_CONFIGURED; // assuming too much...
break;
case HttpStatus.SC_SERVICE_UNAVAILABLE: // 503
mCode = ResultCode.MAINTENANCE_MODE;
break;
case HttpStatus.SC_INSUFFICIENT_STORAGE: // 507
mCode = ResultCode.QUOTA_EXCEEDED; // surprise!
break;
default:
mCode = ResultCode.UNHANDLED_HTTP_CODE; // UNKNOWN ERROR
Log_OC.d(TAG,
"RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " +
mHttpCode + " " + mHttpPhrase
);
}
}
}
public void setData(ArrayList<Object> files) {
mData = files;
@ -297,6 +351,10 @@ public class RemoteOperationResult implements Serializable {
return mHttpCode;
}
public String getHttpPhrase() {
return mHttpPhrase;
}
public ResultCode getCode() {
return mCode;
}

View File

@ -39,6 +39,7 @@ import com.owncloud.android.lib.common.network.ChunkFromFileChannelRequestEntity
import com.owncloud.android.lib.common.network.ProgressiveDataTransferer;
import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.operations.InvalidCharacterExceptionParser;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
@ -53,20 +54,21 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName();
public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType,
String fileLastModifTimestamp){
String fileLastModifTimestamp) {
super(storagePath, remotePath, mimeType, fileLastModifTimestamp);
}
public ChunkedUploadRemoteFileOperation(
String storagePath, String remotePath, String mimeType, String requiredEtag,
String fileLastModifTimestamp
){
) {
super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp);
}
@Override
protected int uploadFile(OwnCloudClient client) throws IOException {
protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException {
int status = -1;
RemoteOperationResult result = null;
FileChannel channel = null;
RandomAccessFile raf = null;
@ -76,18 +78,18 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
channel = raf.getChannel();
mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file);
synchronized (mDataTransferListeners) {
((ProgressiveDataTransferer)mEntity)
((ProgressiveDataTransferer) mEntity)
.addDatatransferProgressListeners(mDataTransferListeners);
}
long offset = 0;
String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) +
"-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ;
"-chunking-" + Math.abs((new Random()).nextInt(9000) + 1000) + "-";
long totalLength = file.length();
long chunkCount = (long) Math.ceil((double)totalLength / CHUNK_SIZE);
long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE);
String chunkSizeStr = String.valueOf(CHUNK_SIZE);
String totalLengthStr = String.valueOf(file.length());
for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) {
for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) {
if (chunkIndex == chunkCount - 1) {
chunkSizeStr = String.valueOf(CHUNK_SIZE * chunkCount - totalLength);
}
@ -121,19 +123,10 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
status = client.executeMethod(mPutMethod);
if (status == 400) {
InvalidCharacterExceptionParser xmlParser =
new InvalidCharacterExceptionParser();
InputStream is = new ByteArrayInputStream(
mPutMethod.getResponseBodyAsString().getBytes());
try {
mForbiddenCharsInServer = xmlParser.parseXMLResponse(is);
} catch (Exception e) {
mForbiddenCharsInServer = false;
Log_OC.e(TAG, "Exception reading exception from server", e);
}
}
result = new RemoteOperationResult(
isSuccess(status),
mPutMethod
);
client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath +
@ -152,7 +145,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
if (mPutMethod != null)
mPutMethod.releaseConnection(); // let the connection available for other methods
}
return status;
return result;
}
}

View File

@ -129,15 +129,8 @@ public class CopyRemoteFileOperation extends RemoteOperation {
/// for other errors that could be explicitly handled, check first:
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
} else if (status == 400) {
result = new RemoteOperationResult(copyMethod.succeeded(),
copyMethod.getResponseBodyAsString(), status);
} else {
result = new RemoteOperationResult(
isSuccess(status), // copy.succeeded()? trustful?
status,
copyMethod.getResponseHeaders()
);
result = new RemoteOperationResult(isSuccess(status), copyMethod);
client.exhaustResponse(copyMethod.getResponseBodyAsStream());
}
@ -196,11 +189,7 @@ public class CopyRemoteFileOperation extends RemoteOperation {
if (failFound) {
result = new RemoteOperationResult(ResultCode.PARTIAL_COPY_DONE);
} else {
result = new RemoteOperationResult(
true,
HttpStatus.SC_MULTI_STATUS,
copyMethod.getResponseHeaders()
);
result = new RemoteOperationResult(true, copyMethod);
}
return result;

View File

@ -40,7 +40,6 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;
*
* @author David A. Velasco
* @author masensio
*
*/
public class CreateRemoteFolderOperation extends RemoteOperation {
@ -100,17 +99,9 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
MkColMethod mkcol = null;
try {
mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
if ( status == 400 ) {
result = new RemoteOperationResult(mkcol.succeeded(),
mkcol.getResponseBodyAsString(), status);
Log_OC.d(TAG, mkcol.getResponseBodyAsString());
} else {
result = new RemoteOperationResult(mkcol.succeeded(), status,
mkcol.getResponseHeaders());
client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
result = new RemoteOperationResult(mkcol.succeeded(), mkcol);
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
}
client.exhaustResponse(mkcol.getResponseBodyAsStream());
} catch (Exception e) {
@ -131,5 +122,4 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
}
}

View File

@ -83,8 +83,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
try {
tmpFile.getParentFile().mkdirs();
int status = downloadFile(client, tmpFile);
result = new RemoteOperationResult(isSuccess(status), status,
(mGet != null ? mGet.getResponseHeaders() : null));
result = new RemoteOperationResult(isSuccess(status), mGet);
Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " +
result.getLogMessage());
@ -116,13 +115,13 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
Header contentLength = mGet.getResponseHeader("Content-Length");
long totalToTransfer = (contentLength != null &&
contentLength.getValue().length() >0) ?
contentLength.getValue().length() > 0) ?
Long.parseLong(contentLength.getValue()) : 0;
byte[] bytes = new byte[4096];
int readResult = 0;
while ((readResult = bis.read(bytes)) != -1) {
synchronized(mCancellationRequested) {
synchronized (mCancellationRequested) {
if (mCancellationRequested.get()) {
mGet.abort();
throw new OperationCancelledException();
@ -183,7 +182,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
return mLocalFolderPath + mRemotePath;
}
public void addDatatransferProgressListener (OnDatatransferProgressListener listener) {
public void addDatatransferProgressListener(OnDatatransferProgressListener listener) {
synchronized (mDataTransferListeners) {
mDataTransferListeners.add(listener);
}

View File

@ -96,7 +96,12 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
client.exhaustResponse(head.getResponseBodyAsStream());
boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) ||
(status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
result = new RemoteOperationResult(success, status, head.getResponseHeaders());
result = new RemoteOperationResult(
success,
status,
head.getStatusText(),
head.getResponseHeaders()
);
Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() +
WebdavUtils.encodePath(mPath) + " targeting for " +
(mSuccessIfAbsent ? " absence " : " existence ") +

View File

@ -45,7 +45,7 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;
/**
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
* in the same account.
*
* <p>
* Allows renaming the moving file/folder at the same time.
*
* @author David A. Velasco
@ -65,7 +65,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
/**
* Constructor.
*
* <p>
* TODO Paths should finish in "/" in the case of folders. ?
*
* @param srcRemotePath Remote path of the file/folder to move.
@ -109,7 +109,6 @@ public class MoveRemoteFileOperation extends RemoteOperation {
/// perform remote operation
//LocalMoveMethod move = null;
MoveMethod move = null;
RemoteOperationResult result = null;
try {
@ -133,15 +132,8 @@ public class MoveRemoteFileOperation extends RemoteOperation {
/// for other errors that could be explicitly handled, check first:
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
} else if (status == 400) {
result = new RemoteOperationResult(move.succeeded(),
move.getResponseBodyAsString(), status);
} else {
result = new RemoteOperationResult(
isSuccess(status), // move.succeeded()? trustful?
status,
move.getResponseHeaders()
);
result = new RemoteOperationResult(isSuccess(status), move);
client.exhaustResponse(move.getResponseBodyAsStream());
}
@ -164,20 +156,19 @@ public class MoveRemoteFileOperation extends RemoteOperation {
/**
* Analyzes a multistatus response from the OC server to generate an appropriate result.
*
* <p>
* In WebDAV, a MOVE request on collections (folders) can be PARTIALLY successful: some
* children are moved, some other aren't.
*
* <p>
* According to the WebDAV specification, a multistatus response SHOULD NOT include partial
* successes (201, 204) nor for descendants of already failed children (424) in the response
* entity. But SHOULD NOT != MUST NOT, so take carefully.
*
* @param move Move operation just finished with a multistatus response
* @return A result for the {@link MoveRemoteFileOperation} caller
*
* @throws IOException If the response body could not be parsed
* @throws DavException If the status code is other than MultiStatus or if obtaining
* the response XML document fails
* @return A result for the {@link MoveRemoteFileOperation} caller
*/
private RemoteOperationResult processPartialError(MoveMethod move)
throws IOException, DavException {
@ -188,7 +179,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
MultiStatusResponse[] responses = move.getResponseBodyAsMultiStatus().getResponses();
Status[] status = null;
boolean failFound = false;
for (int i = 0; i < responses.length && !failFound; i++ ) {
for (int i = 0; i < responses.length && !failFound; i++) {
status = responses[i].getStatus();
failFound = (
status != null &&
@ -201,11 +192,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
if (failFound) {
result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE);
} else {
result = new RemoteOperationResult(
true,
HttpStatus.SC_MULTI_STATUS,
move.getResponseHeaders()
);
result = new RemoteOperationResult(true, move);
}
return result;

View File

@ -96,12 +96,12 @@ public class ReadRemoteFileOperation extends RemoteOperation {
files.add(remoteFile);
// Result of the operation
result = new RemoteOperationResult(true, status, propfind.getResponseHeaders());
result = new RemoteOperationResult(true, propfind);
result.setData(files);
} else {
result = new RemoteOperationResult(false, propfind);
client.exhaustResponse(propfind.getResponseBodyAsStream());
result = new RemoteOperationResult(false, status, propfind.getResponseHeaders());
}
} catch (Exception e) {

View File

@ -89,7 +89,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
readData(dataInServer, client);
// Result of the operation
result = new RemoteOperationResult(true, status, query.getResponseHeaders());
result = new RemoteOperationResult(true, query);
// Add data to the result
if (result.isSuccess()) {
result.setData(mFolderAndFiles);
@ -97,7 +97,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
} else {
// synchronization failed
client.exhaustResponse(query.getResponseBodyAsStream());
result = new RemoteOperationResult(false, status, query.getResponseHeaders());
result = new RemoteOperationResult(false, query);
}
} catch (Exception e) {
@ -129,7 +129,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
/**
* Read the data retrieved from the server about the contents of the target folder
*
*
* @param remoteData Full response got from the server with the data of the target
* folder and its direct children.
* @param client Client instance to the remote server where the data were

View File

@ -71,8 +71,10 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
delete.getResponseBodyAsString(); // exhaust the response, although not interesting
result = new RemoteOperationResult((delete.succeeded() ||
status == HttpStatus.SC_NOT_FOUND), status, delete.getResponseHeaders());
result = new RemoteOperationResult(
(delete.succeeded() || status == HttpStatus.SC_NOT_FOUND),
delete
);
Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage());
} catch (Exception e) {

View File

@ -106,28 +106,20 @@ public class RenameRemoteFileOperation extends RemoteOperation {
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
}
move = new LocalMoveMethod( client.getWebdavUri() +
move = new LocalMoveMethod(client.getWebdavUri() +
WebdavUtils.encodePath(mOldRemotePath),
client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath));
int status = client.executeMethod(move, RENAME_READ_TIMEOUT,
RENAME_CONNECTION_TIMEOUT);
if (status == 400) {
result = new RemoteOperationResult(move.succeeded(),
move.getResponseBodyAsString(), status);
Log_OC.d(TAG, move.getResponseBodyAsString());
} else {
client.exhaustResponse(move.getResponseBodyAsStream());//exhaust response,
// although not interesting
result = new RemoteOperationResult(move.succeeded(), status,
move.getResponseHeaders());
client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT);
result = new RemoteOperationResult(move.succeeded(), move);
Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " +
result.getLogMessage());
}
result.getLogMessage()
);
client.exhaustResponse(move.getResponseBodyAsStream());
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " +
((mNewRemotePath==null) ? mNewName : mNewRemotePath) + ": " +
((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " +
result.getLogMessage(), e);
} finally {
@ -144,7 +136,6 @@ public class RenameRemoteFileOperation extends RemoteOperation {
/**
* Move operation
*
*/
private class LocalMoveMethod extends DavMethodBase {

View File

@ -69,7 +69,6 @@ public class UploadRemoteFileOperation extends RemoteOperation {
protected String mMimeType;
protected String mFileLastModifTimestamp;
protected PutMethod mPutMethod = null;
protected boolean mForbiddenCharsInServer = false;
protected String mRequiredEtag = null;
protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
@ -112,14 +111,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
} else {
// perform the upload
int status = uploadFile(client);
if (mForbiddenCharsInServer){
result = new RemoteOperationResult(
RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER);
} else {
result = new RemoteOperationResult(isSuccess(status), status,
(mPutMethod != null ? mPutMethod.getResponseHeaders() : null));
}
result = uploadFile(client);
}
} catch (Exception e) {
@ -144,8 +136,9 @@ public class UploadRemoteFileOperation extends RemoteOperation {
status == HttpStatus.SC_NO_CONTENT));
}
protected int uploadFile(OwnCloudClient client) throws IOException {
int status = -1;
protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException {
int status;
RemoteOperationResult result;
try {
File f = new File(mLocalPath);
mEntity = new FileRequestEntity(f, mMimeType);
@ -163,25 +156,16 @@ public class UploadRemoteFileOperation extends RemoteOperation {
mPutMethod.setRequestEntity(mEntity);
status = client.executeMethod(mPutMethod);
if (status == 400) {
InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser();
InputStream is = new ByteArrayInputStream(
mPutMethod.getResponseBodyAsString().getBytes());
try {
mForbiddenCharsInServer = xmlParser.parseXMLResponse(is);
} catch (Exception e) {
mForbiddenCharsInServer = false;
Log_OC.e(TAG, "Exception reading exception from server", e);
}
}
result = new RemoteOperationResult(
isSuccess(status),
mPutMethod
);
client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
} finally {
mPutMethod.releaseConnection(); // let the connection available for other methods
}
return status;
return result;
}
public Set<OnDatatransferProgressListener> getDataTransferListeners() {

View File

@ -58,6 +58,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
/**
* Constructor
*
* @param remoteFilePath Full path of the file/folder being shared. Mandatory argument
* @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument
* @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType
@ -93,7 +94,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
mGetShareDetails = false; // defaults to false for backwards compatibility
}
public boolean isGettingShareDetails () {
public boolean isGettingShareDetails() {
return mGetShareDetails;
}
@ -112,7 +113,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
// Post Method
post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
post.setRequestHeader( "Content-Type",
post.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters
post.addParameter(PARAM_PATH, mRemoteFilePath);
@ -132,7 +133,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
status = client.executeMethod(post);
if(isSuccess(status)) {
if (isSuccess(status)) {
String response = post.getResponseBodyAsString();
ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser(
@ -153,7 +154,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
}
} else {
result = new RemoteOperationResult(false, status, post.getResponseHeaders());
result = new RemoteOperationResult(false, post);
}
} catch (Exception e) {

View File

@ -58,13 +58,13 @@ public class GetRemoteShareOperation extends RemoteOperation {
GetMethod get = null;
// Get the response
try{
try {
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId));
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
status = client.executeMethod(get);
if(isSuccess(status)) {
if (isSuccess(status)) {
String response = get.getResponseBodyAsString();
// Parse xml response and obtain the list of shares
@ -77,7 +77,7 @@ public class GetRemoteShareOperation extends RemoteOperation {
result = parser.parse(response);
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
result = new RemoteOperationResult(false, get);
}
} catch (Exception e) {

View File

@ -166,13 +166,13 @@ public class GetRemoteShareesOperation extends RemoteOperation{
}
// Result
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
result = new RemoteOperationResult(true, get);
result.setData(data);
Log_OC.d(TAG, "*** Get Users or groups completed " );
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
result = new RemoteOperationResult(false, get);
String response = get.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while getting users/groups from the server ");
if (response != null) {

View File

@ -91,7 +91,7 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
status = client.executeMethod(get);
if(isSuccess(status)) {
if (isSuccess(status)) {
String response = get.getResponseBodyAsString();
// Parse xml response and obtain the list of shares
@ -107,7 +107,7 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
}
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
result = new RemoteOperationResult(false, get);
}
} catch (Exception e) {

View File

@ -36,7 +36,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
/**
* Get the data from the server about ALL the known shares owned by the requester.
*
*/
public class GetRemoteSharesOperation extends RemoteOperation {
@ -56,12 +55,12 @@ public class GetRemoteSharesOperation extends RemoteOperation {
GetMethod get = null;
// Get the response
try{
try {
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
status = client.executeMethod(get);
if(isSuccess(status)) {
if (isSuccess(status)) {
String response = get.getResponseBodyAsString();
// Parse xml response and obtain the list of shares
@ -72,7 +71,7 @@ public class GetRemoteSharesOperation extends RemoteOperation {
parser.setServerBaseUri(client.getBaseUri());
result = parser.parse(response);
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
result = new RemoteOperationResult(false, get);
}
} catch (Exception e) {

View File

@ -70,7 +70,7 @@ public class RemoveRemoteShareOperation extends RemoteOperation {
status = client.executeMethod(delete);
if(isSuccess(status)) {
if (isSuccess(status)) {
String response = delete.getResponseBodyAsString();
// Parse xml response and obtain the list of shares
@ -82,7 +82,7 @@ public class RemoveRemoteShareOperation extends RemoteOperation {
Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage());
} else {
result = new RemoteOperationResult(false, status, delete.getResponseHeaders());
result = new RemoteOperationResult(false, delete);
}
} catch (Exception e) {
result = new RemoteOperationResult(e);

View File

@ -216,7 +216,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
result = parser.parse(response);
} else {
result = new RemoteOperationResult(false, status, put.getResponseHeaders());
result = new RemoteOperationResult(false, put);
}
if (!result.isSuccess()) {
break;

View File

@ -242,18 +242,18 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {
}
// Result
data.add(capability);
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
result = new RemoteOperationResult(true, get);
result.setData(data);
Log_OC.d(TAG, "*** Get Capabilities completed ");
} else {
result = new RemoteOperationResult(statusProp, statuscode, null);
result = new RemoteOperationResult(statusProp, statuscode, null, null);
Log_OC.e(TAG, "Failed response while getting capabilities from the server ");
Log_OC.e(TAG, "*** status: " + statusProp + "; message: " + message);
}
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
result = new RemoteOperationResult(false, get);
String response = get.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while getting capabilities from the server ");
if (response != null) {

View File

@ -49,7 +49,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
*
* @author David A. Velasco
* @author masensio
*
*/
public class GetRemoteStatusOperation extends RemoteOperation {
@ -87,11 +86,7 @@ public class GetRemoteStatusOperation extends RemoteOperation {
client.setFollowRedirects(false);
boolean isRedirectToNonSecureConnection = false;
int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
mLatestResult = new RemoteOperationResult(
(status == HttpStatus.SC_OK),
status,
get.getResponseHeaders()
);
mLatestResult = new RemoteOperationResult((status == HttpStatus.SC_OK), get);
String redirectedLocation = mLatestResult.getRedirectedLocation();
while (redirectedLocation != null && redirectedLocation.length() > 0
@ -106,8 +101,7 @@ public class GetRemoteStatusOperation extends RemoteOperation {
status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
mLatestResult = new RemoteOperationResult(
(status == HttpStatus.SC_OK),
status,
get.getResponseHeaders()
get
);
redirectedLocation = mLatestResult.getRedirectedLocation();
}
@ -148,7 +142,7 @@ public class GetRemoteStatusOperation extends RemoteOperation {
}
} else {
mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders());
mLatestResult = new RemoteOperationResult(false, get);
}
} catch (JSONException e) {

View File

@ -143,15 +143,15 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation {
}
// Result
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
result = new RemoteOperationResult(true, get);
ResultData resultData = new ResultData(bos.toByteArray(), mimeType, etag);
ArrayList<Object> data = new ArrayList<Object>();
data.add(resultData);
result.setData(data);
} else {
result = new RemoteOperationResult(false, get);
client.exhaustResponse(get.getResponseBodyAsStream());
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
}
} catch (Exception e) {

View File

@ -86,14 +86,14 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
userInfo.mEmail = respData.getString(NODE_EMAIL);
// Result
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
result = new RemoteOperationResult(true, get);
// Username in result.data
ArrayList<Object> data = new ArrayList<Object>();
data.add(userInfo);
result.setData(data);
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
result = new RemoteOperationResult(false, get);
String response = get.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while getting user information ");
if (response != null) {

View File

@ -107,14 +107,14 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation {
// Result
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
result = new RemoteOperationResult(true, get);
//Quota data in data collection
ArrayList<Object> data = new ArrayList<Object>();
data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative));
result.setData(data);
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
result = new RemoteOperationResult(false, get);
String response = get.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while getting user quota information ");
if (response != null) {