package com.owncloud.android.operations;
import java.io.IOException;
+import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
-
-import android.util.Log;
+import org.apache.jackrabbit.webdav.DavException;
import com.owncloud.android.network.CertificateCombinedException;
/**
* The result of a remote operation required to an ownCloud server.
*
- * Provides a common classification of resulst for all the application.
+ * Provides a common classification of remote operation results for all the application.
*
* @author David A. Velasco
*/
-public class RemoteOperationResult {
+public class RemoteOperationResult implements Serializable {
+
+ /** Generated - to refresh every time the class changes */
+ private static final long serialVersionUID = -7805531062432602444L;
+
public enum ResultCode {
OK,
OK_SSL,
OK_NO_SSL,
UNHANDLED_HTTP_CODE,
+ UNAUTHORIZED,
FILE_NOT_FOUND,
INSTANCE_NOT_CONFIGURED,
UNKNOWN_ERROR,
HOST_NOT_AVAILABLE,
NO_NETWORK_CONNECTION,
SSL_ERROR,
- BAD_OC_VERSION,
+ SSL_RECOVERABLE_PEER_UNVERIFIED,
+ BAD_OC_VERSION,
+ STORAGE_ERROR_MOVING_FROM_TMP,
+ CANCELLED,
+ INVALID_LOCAL_FILE_NAME,
+ INVALID_OVERWRITE,
+ CONFLICT
}
- private static final String TAG = null;
-
private boolean mSuccess = false;
private int mHttpCode = -1;
private Exception mException = null;
private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
+ private Object mExtraData = null;
public RemoteOperationResult(ResultCode code) {
mCode = code;
} 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;
default:
mCode = ResultCode.UNHANDLED_HTTP_CODE;
}
public RemoteOperationResult(Exception e) {
mException = e;
- if (e instanceof SocketException) {
+ if (e instanceof OperationCancelledException) {
+ mCode = ResultCode.CANCELLED;
+
+ } else if (e instanceof SocketException) {
mCode = ResultCode.WRONG_CONNECTION;
} else if (e instanceof SocketTimeoutException) {
} else if (e instanceof UnknownHostException) {
mCode = ResultCode.HOST_NOT_AVAILABLE;
- } else if (e instanceof SSLException) {
- mCode = ResultCode.SSL_ERROR;
+ } else if (e instanceof SSLException || e instanceof RuntimeException) {
+ CertificateCombinedException se = getCertificateCombinedException(e);
+ if (se != null) {
+ mException = se;
+ if (se.isRecoverable()) {
+ mCode = ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED;
+ }
+
+ } else {
+ mCode = ResultCode.SSL_ERROR;
+ }
} else {
mCode = ResultCode.UNKNOWN_ERROR;
return mSuccess;
}
+ public boolean isCancelled() {
+ return mCode == ResultCode.CANCELLED;
+ }
+
public int getHttpCode() {
return mHttpCode;
}
}
public boolean isSslRecoverableException() {
- return (getSslRecoverableException() != null);
+ return mCode == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED;
}
- public CertificateCombinedException getSslRecoverableException() {
+ public void setExtraData(Object data) {
+ mExtraData = data;
+ }
+
+ public Object getExtraData() {
+ return mExtraData;
+ }
+
+ private CertificateCombinedException getCertificateCombinedException(Exception e) {
CertificateCombinedException result = null;
- if (mCode == ResultCode.SSL_ERROR) {
- if (mException instanceof CertificateCombinedException)
- result = (CertificateCombinedException)mException;
- Throwable cause = mException.getCause();
- Throwable previousCause = null;
- while (cause != null && cause != previousCause && !(cause instanceof CertificateCombinedException)) {
- previousCause = cause;
- cause = cause.getCause();
- }
- if (cause != null && cause instanceof CertificateCombinedException)
- result = (CertificateCombinedException)cause;
+ if (e instanceof CertificateCombinedException) {
+ return (CertificateCombinedException)e;
+ }
+ Throwable cause = mException.getCause();
+ Throwable previousCause = null;
+ while (cause != null && cause != previousCause && !(cause instanceof CertificateCombinedException)) {
+ previousCause = cause;
+ cause = cause.getCause();
}
- if (result != null && result.isRecoverable())
- return result;
- else
- return null;
+ if (cause != null && cause instanceof CertificateCombinedException) {
+ result = (CertificateCombinedException)cause;
+ }
+ return result;
}
public String getLogMessage() {
if (mException != null) {
- if (mException instanceof SocketException) {
+ if (mException instanceof OperationCancelledException) {
+ return "Operation cancelled by the caller";
+
+ } else if (mException instanceof SocketException) {
return "Socket exception";
} else if (mException instanceof SocketTimeoutException) {
} else if (mException instanceof UnknownHostException) {
return "Unknown host exception";
+ } else if (mException instanceof CertificateCombinedException) {
+ if (((CertificateCombinedException) mException).isRecoverable())
+ return "SSL recoverable exception";
+ else
+ return "SSL exception";
+
} else if (mException instanceof SSLException) {
return "SSL exception";
+ } else if (mException instanceof DavException) {
+ return "Unexpected WebDAV exception";
+
} else if (mException instanceof HttpException) {
return "HTTP violation";
}
}
+ if (mCode == ResultCode.INSTANCE_NOT_CONFIGURED) {
+ return "The ownCloud server is not configured!";
+
+ } else if (mCode == ResultCode.NO_NETWORK_CONNECTION) {
+ return "No network connection";
+
+ } else if (mCode == ResultCode.BAD_OC_VERSION) {
+ return "No valid ownCloud version was found at the server";
+
+ } else if (mCode == ResultCode.STORAGE_ERROR_MOVING_FROM_TMP) {
+ return "Error while moving file from temporal to final directory";
+ }
+
return "Operation finished with HTTP status code " + mHttpCode + " (" + (isSuccess()?"success":"fail") + ")";
-
+
}
}