Implementata lettura errore chiamate http in login
This commit is contained in:
parent
746838010a
commit
d142f0c868
@ -30,23 +30,27 @@ public class ServerStatusChecker {
|
||||
private Runnable runnableCode = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(shouldExecute && !UtilityString.isNullOrEmpty(SettingsManager.i().getServer().getHost())) {
|
||||
UtilityServer.isEmsApiAvailable(SettingsManager.i().getServer().getHost(), SettingsManager.i().getServer().getPort(), mInternalCallback);
|
||||
if (shouldExecute && !UtilityString.isNullOrEmpty(SettingsManager.i().getServer().getHost())) {
|
||||
UtilityServer.isEmsApiAvailable(
|
||||
SettingsManager.i().getServer().getHost(),
|
||||
SettingsManager.i().getServer().getPort(),
|
||||
() -> mInternalCallback.run(true),
|
||||
ex -> mInternalCallback.run(false));
|
||||
handler.postDelayed(this, MILLIS_DELAY);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void addCallback(RunnableArgs<Boolean> callback){
|
||||
public void addCallback(RunnableArgs<Boolean> callback) {
|
||||
this.mCallback.add(callback);
|
||||
}
|
||||
|
||||
public void removeCallback(RunnableArgs<Boolean> callback){
|
||||
public void removeCallback(RunnableArgs<Boolean> callback) {
|
||||
this.mCallback.remove(callback);
|
||||
}
|
||||
|
||||
|
||||
public static void init(){
|
||||
public static void init() {
|
||||
instance.shouldExecute = true;
|
||||
|
||||
instance.handler.post(instance.runnableCode);
|
||||
|
||||
@ -6,13 +6,14 @@ import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.gest.login.exception.ServerNotReachableException;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class UtilityServer {
|
||||
|
||||
public static void isHostReachable(final String serverAddress, final int serverTCPport, final RunnableArgs<Boolean> callback){
|
||||
public static void isHostReachable(final String serverAddress, final int serverTCPport, final RunnableArgs<Boolean> callback) {
|
||||
new Thread(() -> {
|
||||
|
||||
boolean connected = false;
|
||||
@ -36,7 +37,7 @@ public class UtilityServer {
|
||||
}).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(() -> {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@ -46,11 +47,16 @@ public class UtilityServer {
|
||||
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
boolean status = response.isSuccessful();
|
||||
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) {
|
||||
callback.run(false);
|
||||
onFailed.run(new ServerNotReachableException(serverAddress, serverTCPport, e));
|
||||
}
|
||||
|
||||
}).start();
|
||||
|
||||
@ -15,7 +15,6 @@ import it.integry.integrywmsnative.core.utility.UtilityServer;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||
import it.integry.integrywmsnative.gest.login.exception.InvalidServerCodAziendaException;
|
||||
import it.integry.integrywmsnative.gest.login.exception.InvalidUserDepositException;
|
||||
import it.integry.integrywmsnative.gest.login.exception.ServerNotReachableException;
|
||||
import it.integry.integrywmsnative.gest.login.rest.LoginRESTConsumer;
|
||||
|
||||
public class LoginViewModel {
|
||||
@ -52,9 +51,8 @@ public class LoginViewModel {
|
||||
final String host = u.getHost();
|
||||
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 -> {
|
||||
|
||||
SettingsManager.iDB().setAvailableProfiles(loginDTO.getAvailableProfiles());
|
||||
@ -73,11 +71,7 @@ public class LoginViewModel {
|
||||
}, this::sendError);
|
||||
|
||||
|
||||
} else { //Is not online
|
||||
this.sendError(new ServerNotReachableException(host, port, null));
|
||||
}
|
||||
|
||||
});
|
||||
}, this::sendError);
|
||||
}, ex -> {
|
||||
this.sendError(new InvalidServerCodAziendaException(codAzienda, ex));
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user