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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
package org.openslx.dozmod.thrift;
import java.awt.Component;
import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.AuthorizationError;
import org.openslx.bwlp.thrift.iface.InvocationError;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
import org.openslx.bwlp.thrift.iface.TInvalidDateParam;
import org.openslx.bwlp.thrift.iface.TInvocationException;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.TTransferRejectedException;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.MessageType;
public class ThriftError {
public static void showMessage(final Component parent, Logger logger, TException ex, String messageText) {
if (ex instanceof TNotFoundException) {
messageText += "\n\nNicht gefunden";
} else if (ex instanceof TAuthorizationException) {
String reason = getString(((TAuthorizationException) ex).getNumber());
messageText += "\n\nZugriff verweigert: " + reason + "\n" + ex.getMessage();
} else if (ex instanceof TInvocationException) {
messageText += "\n\nDer Funktionsaufruf konnte nicht durchgeführt werden: "
+ getString(((TInvocationException) ex).getNumber()) + "\n" + ex.getMessage();
} else if (ex instanceof TInvalidDateParam) {
messageText += "\n\nEin angegebenes Datum ist ungültig:\n" + ex.getMessage();
} else if (ex instanceof TTransferRejectedException) {
messageText += "\n\nDie Transferanfrage wurde vom Server abgelehnt:\n" + ex.getMessage();
} else {
messageText += "\n\nUnerwartete Ausnahme " + ex.getClass().getSimpleName() + " ist aufgetreten.";
}
if (logger != null) {
logger.warn("A thrift call raised an exception", ex);
}
if (SwingUtilities.isEventDispatchThread()) {
Gui.showMessageBox(parent, messageText, MessageType.ERROR, null, null);
return;
}
final String msg = messageText;
Gui.asyncExec(new Runnable() {
@Override
public void run() {
Gui.showMessageBox(parent, msg, MessageType.ERROR, null, null);
}
});
}
private static String getString(InvocationError error) {
if (error == null)
return "Interner serverseitiger Fehler";
switch (error) {
case INTERNAL_SERVER_ERROR:
return "Interner serverseitiger Fehler";
case INVALID_DATA:
return "Ein Parameter hat einen ungültigen Wert";
case INVALID_SHARE_MODE:
return "Ungültiger Share-Mode";
case MISSING_DATA:
return "Ein Parameter fehlt (null?)";
case UNKNOWN_IMAGE:
return "Unbekannte VM/Image";
case UNKNOWN_LECTURE:
return "Unbekannte Veranstaltung";
case UNKNOWN_USER:
return "Unbekannter Benutzer";
default:
return "Unbekannter Fehlercode: " + error.toString();
}
}
public static String getString(AuthorizationError error) {
if (error == null)
return "(AuthorizationError=null)";
switch (error) {
case ACCOUNT_SUSPENDED:
return "Das Benutzerkonto ist gesperrt";
case BANNED_NETWORK:
return "Das Netzwerk, aus dem Sie operieren, ist gesperrt";
case CHALLENGE_FAILED:
return "Challenge fehlgeschlagen";
case GENERIC_ERROR:
return "Generischer Fehler";
case INVALID_CREDENTIALS:
return "Ungültige Zugangsdaten\nStellen Sie sicher, dass Benutzername und Passwort korrekt sind";
case INVALID_KEY:
return "Ungültiger Schlüssel";
case INVALID_ORGANIZATION:
return "Ungültige oder unbekannte Organisation";
case INVALID_TOKEN:
return "Ungültiges Sitzungstoken";
case NOT_AUTHENTICATED:
return "Nicht authentifiziert";
case NO_PERMISSION:
return "Keine ausreichenden Berechtigungen";
case ORGANIZATION_SUSPENDED:
return "Ihre zugehörige Organisation ist gesperrt";
default:
return "Unbekannter Fehlercode: " + error.toString();
}
}
private static final String[] ignoredMethods = { "ping", "getStatus", "updateBlockHashes",
"cancelUpload", "cancelDownload" };
public static boolean failSilently(String methodName) {
for (int i = 0; i < ignoredMethods.length; ++i) {
if (ignoredMethods[i].equals(methodName))
return true;
}
return false;
}
}
|