import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
-import android.util.Log;
-
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
*/
HOST_NOT_AVAILABLE,
NO_NETWORK_CONNECTION,
SSL_ERROR,
- BAD_OC_VERSION,
+ SSL_RECOVERABLE_PEER_UNVERIFIED,
+ BAD_OC_VERSION,
+ STORAGE_ERROR_MOVING_FROM_TMP,
+ CANCELLED
}
- private static final String TAG = null;
-
private boolean mSuccess = false;
private int mHttpCode = -1;
private Exception mException = null;
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() {
+ 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;
}
- if (result != null && result.isRecoverable())
- return result;
- else
- return null;
+ 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;
+ }
+ 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) {
return "Unknown host exception";
} else if (mException instanceof SSLException) {
- return "SSL exception";
+ if (mCode == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)
+ return "SSL recoverable exception";
+ else
+ return "SSL 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") + ")";
}