1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
package org.openslx.dozmod.thrift;
import java.awt.Frame;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;
import org.openslx.bwlp.thrift.iface.AuthorizationError;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
import org.openslx.dozmod.Config;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.Gui.GuiCallable;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.thrifthelper.ThriftManager.ErrorCallback;
public class GuiErrorCallback implements ErrorCallback {
private static final Logger LOGGER = Logger.getLogger(GuiErrorCallback.class);
private final Frame parent;
private final String serverString;
public GuiErrorCallback(Frame parent, String serverString) {
this.parent = parent;
this.serverString = serverString;
}
@Override
public boolean thriftError(int failCount, final String method, final Throwable t) {
// if it's not a transport exception, do not retry
if (t != null && !(t instanceof TException))
return false;
// if it's the first fail, retry immediately
if (failCount == 1)
return true;
// Some methods are non-critical, so don't show a pop-up
if (ThriftError.failSilently(method))
return failCount == 2; // As it's silent, give it a second try...
if (t instanceof TAuthorizationException) {
final TAuthorizationException taex = (TAuthorizationException) t;
if (taex.getNumber() == AuthorizationError.NOT_AUTHENTICATED || taex.getNumber() == AuthorizationError.INVALID_TOKEN) {
// TODO somehow reauth the user :)
return Gui.syncExec(new GuiCallable<Boolean>() {
@Override
public Boolean run() {
if (Gui.showMessageBox(parent, "Ungültiges Sitzungstoken oder fehlerhafte Authentifizierung am " + serverString + "!" +
//"\n" + errMsg + "\n" +
"\nBitte starten Sie das Programm neu. Jetzt beenden?", MessageType.ERROR_RETRY, LOGGER, t)) {
// user confirmed exit
Config.saveCurrentSession("", "", "");
Gui.exit(0);
}
return false;
}
});
}
}
if (t instanceof TTransportException) {
// Otherwise, ask user if we should retry
final TTransportException tex = (TTransportException) t;
return Gui.syncExec(new GuiCallable<Boolean>() {
@Override
public Boolean run() {
String errMsg = null;
if (tex != null) {
errMsg = " (Fehler " + tex.getType() + ")";
}
return Gui.showMessageBox(parent, "Die Kommunikation mit " + serverString + " ist"
+ " gestört. Der Aufruf der Funktion " + method + " ist fehlgeschlagen" + errMsg
+ ".\n\n" + "Möchten Sie den Aufruf wiederholen?", MessageType.ERROR_RETRY, LOGGER, t);
}
});
}
return false;
}
}
|