package eu.alefzero.owncloud.authenticator;
import java.net.ConnectException;
+import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import javax.net.ssl.SSLHandshakeException;
import android.util.Log;
public class ConnectionCheckerRunnable implements Runnable {
+
+ /** Maximum time to wait for a response from the server when the connection is being tested, in MILLISECONDs. */
+ public static final int TRY_CONNECTION_TIMEOUT = 5000;
+
private static final String TAG = "ConnectionCheckerRunnable";
private OnConnectCheckListener mListener;
private String mUrl;
}
private boolean tryConnection(Uri uri) {
- WebdavClient wc = new WebdavClient(uri);
+ WebdavClient wc = new WebdavClient();
wc.allowSelfsignedCertificates();
GetMethod get = new GetMethod(uri.toString());
boolean retval = false;
try {
- int status = wc.executeMethod(get);
+ int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT);
switch (status) {
case HttpStatus.SC_OK: {
String response = get.getResponseBodyAsString();
} catch (Exception e) {
if (e instanceof UnknownHostException
- || e instanceof ConnectException) {
+ || e instanceof ConnectException
+ || e instanceof SocketTimeoutException) {
mLatestResult = ResultType.HOST_NOT_AVAILABLE;
} else if (e instanceof JSONException) {
mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;