diff options
author | Simon Rettberg | 2015-09-28 18:54:51 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-09-28 18:54:51 +0200 |
commit | 16c692fffb51a1fb3d2f9bf8592e45ade7a37d6d (patch) | |
tree | 56af67e56b3118d92ebfbf464dde12735df876c4 /dozentenmodul/src/main/java/org/openslx/dozmod/App.java | |
parent | [client] Added window for opening webpage in browser if user is not registere... (diff) | |
download | tutor-module-16c692fffb51a1fb3d2f9bf8592e45ade7a37d6d.tar.gz tutor-module-16c692fffb51a1fb3d2f9bf8592e45ade7a37d6d.tar.xz tutor-module-16c692fffb51a1fb3d2f9bf8592e45ade7a37d6d.zip |
[client] Cleanup no-SSL fallback for master server connection
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/App.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/App.java | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java index 4a1f6fe3..ed2645ff 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java @@ -7,6 +7,7 @@ import java.awt.event.AWTEventListener; import java.awt.event.ContainerEvent; import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.util.HashSet; import java.util.Set; import java.util.regex.Matcher; @@ -37,6 +38,8 @@ public class App { // Logger private final static Logger LOGGER = Logger.getLogger(App.class); + public static final String MASTER_SERVER_ADDRESS = "bwlp-masterserver.ruf.uni-freiburg.de"; + public static final int THRIFT_PORT = 9090; public static final int THRIFT_SSL_PORT = THRIFT_PORT + 1; @@ -112,7 +115,7 @@ public class App { LOGGER.info("Starting logging to: " + logFilePath); } - public static void main(final String[] args) { + public static void main(final String[] args) throws InvocationTargetException, InterruptedException { if (args.length >= 2 && args[0].equals("--json")) { writeJsonUpdateFile(args[1]); return; @@ -151,64 +154,61 @@ public class App { // Adjust font size adjustFontSize(Config.getFontScaling()); + // Set up connection to master server final String host; - final int port; + int port; boolean useSsl; if (args.length == 3) { host = args[0]; port = Util.parseInt(args[1], -1); useSsl = Boolean.getBoolean(args[2]); } else { - host = "bwlp-masterserver.ruf.uni-freiburg.de"; + host = MASTER_SERVER_ADDRESS; port = THRIFT_SSL_PORT; useSsl = true; } - SSLContext ctx = null; if (useSsl) { try { - ctx = SSLContext.getInstance("TLSv1.2"); + SSLContext ctx = SSLContext.getInstance("TLSv1.2"); ctx.init(null, null, null); + ThriftManager.setMasterServerAddress(ctx, host, port, THRIFT_TIMEOUT_MS); } catch (final Exception e1) { - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { - boolean ret = Gui.showMessageBox(null, "SSL nicht verfügbar. Wollen Sie sich trotzdem unverschlüsselt verbinden?", MessageType.QUESTION_YESNO, LOGGER, e1); - if (ret) { - connectAndRun(null, host, THRIFT_PORT); - } else { + boolean ret = Gui.showMessageBox(null, + "SSL nicht verfügbar. Wollen Sie sich trotzdem unverschlüsselt verbinden?", + MessageType.QUESTION_YESNO, LOGGER, e1); + if (!ret) { System.exit(1); } } }); - return; + useSsl = false; + port = port - 1; // This assumes SSL port is always plain port + 1 } - connectAndRun(ctx, host, port); } - } - public static void connectAndRun(SSLContext ctx, String host, int port) { - // Set master server to use - ThriftManager.setMasterServerAddress(ctx, host, port, THRIFT_TIMEOUT_MS); + // No "else", might be fallback for failed SSL + if (!useSsl) { + ThriftManager.setMasterServerAddress(null, host, port, THRIFT_TIMEOUT_MS); + } - // setup global thrift connection error handler before anything else + // Setup global thrift connection error handler and then open the GUI SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { - Gui.showMessageBox( - null, - "Ungefangene Ausnahme in Faden " - + t.getName() - + "\n\n" - + "Die Anwendung könnte instabil laufen.\nZur Sicherheit sollten Sie sie neustarten.", - MessageType.WARNING, LOGGER, e); + Gui.showMessageBox(null, "Ungefangene Ausnahme in Faden " + t.getName() + "\n\n" + + "Die Anwendung könnte instabil laufen.\n" + + "Zur Sicherheit sollten Sie sie neustarten.", MessageType.WARNING, LOGGER, + e); } }); MainWindow.open(); } }); - Util.sleep(1000); } private static void writeJsonUpdateFile(String destination) { |