Implementata lettura errore chiamate http in login
This commit is contained in:
parent
746838010a
commit
d142f0c868
@ -31,7 +31,11 @@ public class ServerStatusChecker {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (shouldExecute && !UtilityString.isNullOrEmpty(SettingsManager.i().getServer().getHost())) {
|
if (shouldExecute && !UtilityString.isNullOrEmpty(SettingsManager.i().getServer().getHost())) {
|
||||||
UtilityServer.isEmsApiAvailable(SettingsManager.i().getServer().getHost(), SettingsManager.i().getServer().getPort(), mInternalCallback);
|
UtilityServer.isEmsApiAvailable(
|
||||||
|
SettingsManager.i().getServer().getHost(),
|
||||||
|
SettingsManager.i().getServer().getPort(),
|
||||||
|
() -> mInternalCallback.run(true),
|
||||||
|
ex -> mInternalCallback.run(false));
|
||||||
handler.postDelayed(this, MILLIS_DELAY);
|
handler.postDelayed(this, MILLIS_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import java.net.Socket;
|
|||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||||
|
import it.integry.integrywmsnative.gest.login.exception.ServerNotReachableException;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
@ -36,7 +37,7 @@ public class UtilityServer {
|
|||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void isEmsApiAvailable(final String serverAddress, final int serverTCPport, final RunnableArgs<Boolean> callback) {
|
public static void isEmsApiAvailable(final String serverAddress, final int serverTCPport, final Runnable onComplete, final RunnableArgs<Exception> onFailed) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
OkHttpClient client = new OkHttpClient();
|
OkHttpClient client = new OkHttpClient();
|
||||||
|
|
||||||
@ -46,11 +47,16 @@ public class UtilityServer {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
boolean status = response.isSuccessful();
|
|
||||||
response.close();
|
response.close();
|
||||||
callback.run(status);
|
|
||||||
|
if (response.code() == 200) onComplete.run();
|
||||||
|
else if (response.code() == 404)
|
||||||
|
onFailed.run(new ServerNotReachableException(serverAddress, serverTCPport, null));
|
||||||
|
else if (response.code() == 550)
|
||||||
|
onFailed.run(new Exception("Licenza non valida"));
|
||||||
|
else onFailed.run(new Exception("Errore non identificato (STATUS: " + response.code() + ")"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
callback.run(false);
|
onFailed.run(new ServerNotReachableException(serverAddress, serverTCPport, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
}).start();
|
}).start();
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import it.integry.integrywmsnative.core.utility.UtilityServer;
|
|||||||
import it.integry.integrywmsnative.core.utility.UtilityString;
|
import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||||
import it.integry.integrywmsnative.gest.login.exception.InvalidServerCodAziendaException;
|
import it.integry.integrywmsnative.gest.login.exception.InvalidServerCodAziendaException;
|
||||||
import it.integry.integrywmsnative.gest.login.exception.InvalidUserDepositException;
|
import it.integry.integrywmsnative.gest.login.exception.InvalidUserDepositException;
|
||||||
import it.integry.integrywmsnative.gest.login.exception.ServerNotReachableException;
|
|
||||||
import it.integry.integrywmsnative.gest.login.rest.LoginRESTConsumer;
|
import it.integry.integrywmsnative.gest.login.rest.LoginRESTConsumer;
|
||||||
|
|
||||||
public class LoginViewModel {
|
public class LoginViewModel {
|
||||||
@ -52,9 +51,8 @@ public class LoginViewModel {
|
|||||||
final String host = u.getHost();
|
final String host = u.getHost();
|
||||||
final int port = u.getPort();
|
final int port = u.getPort();
|
||||||
|
|
||||||
UtilityServer.isEmsApiAvailable(host, port, value1 -> {
|
UtilityServer.isEmsApiAvailable(host, port, () -> {
|
||||||
|
|
||||||
if (value1) { //Is online
|
|
||||||
mLoginRESTConsumer.authenticate(host, port, username, password, loginDTO -> {
|
mLoginRESTConsumer.authenticate(host, port, username, password, loginDTO -> {
|
||||||
|
|
||||||
SettingsManager.iDB().setAvailableProfiles(loginDTO.getAvailableProfiles());
|
SettingsManager.iDB().setAvailableProfiles(loginDTO.getAvailableProfiles());
|
||||||
@ -73,11 +71,7 @@ public class LoginViewModel {
|
|||||||
}, this::sendError);
|
}, this::sendError);
|
||||||
|
|
||||||
|
|
||||||
} else { //Is not online
|
}, this::sendError);
|
||||||
this.sendError(new ServerNotReachableException(host, port, null));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}, ex -> {
|
}, ex -> {
|
||||||
this.sendError(new InvalidServerCodAziendaException(codAzienda, ex));
|
this.sendError(new InvalidServerCodAziendaException(codAzienda, ex));
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user