summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/App.java
blob: c7d25c4396cdf4abef790ab0c327f5357b71504c (plain) (blame)
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
import gui.intro.Login_GUI;

import java.awt.EventQueue;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Proxy;
import java.net.ProxySelector;
import java.net.URI;

import javax.swing.JOptionPane;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.openslx.network.ProxyConfiguration;

import com.btr.proxy.search.ProxySearch;
import com.btr.proxy.search.ProxySearch.Strategy;
import com.btr.proxy.search.wpad.WpadProxySearchStrategy;
import com.btr.proxy.util.ProxyException;

import util.ShibbolethECP;
import config.Config;
import config.ConfigProxy;


public class App {

	// Logger
	private final static Logger LOGGER = Logger.getLogger(App.class);

	private static void setupLogger() {
		
		// path to the log file
		final String logFilePath = Config.getPath() + System.getProperty("file.separator") + "bwSuite.log";

		// check if we had an old log file
		final File logFile = new File(logFilePath);
		if (logFile.exists() && !logFile.isDirectory()) {
			// we have one, rename it to 'bwSuite.log.old'
			try {
				logFile.renameTo(new File(logFilePath + ".old"));
			} catch (Exception e) {
				LOGGER.error("Could not move '" + logFilePath +
							"' to '" + logFilePath + ".old':");
				e.printStackTrace();
			}
		}

		// add file appender to global logger
		FileAppender fa = null;
		try {
			fa = new FileAppender(new PatternLayout("%d [%F:%M] %m%n"), logFilePath);
			// All classes should log to file, configure global file appender.
			BasicConfigurator.configure(fa);
//			LOGGER.addAppender(fa);
			LOGGER.info("Starting logging to: " + logFilePath);
		} catch (IOException e) {
			e.printStackTrace();
		}
		LOGGER.info("Logger initialised.");
	}

	public static void main(final String[] args) {

		// Pruefe und Erzeuge gegebenfalls Config
		try {
			Config.init();
		} catch (IOException e) {
			e.printStackTrace();
			JOptionPane.showMessageDialog(null, e.getMessage(),
					"Fehler", JOptionPane.ERROR_MESSAGE);
			return;
		}

		// initialise the proxy settings
		try {
			ConfigProxy.init();
		} catch (IOException e) {
			LOGGER.error("IOException when trying to initialise the proxy, see trace: ", e);
		}

		setupLogger();

		// start the GUI
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					// Aufruf und Anzeige des Login Fensters
					Login_GUI frame = new Login_GUI(args);
					frame.setVisible(true);

				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, e.getStackTrace(),
							"Message", JOptionPane.ERROR_MESSAGE);
				}
			}

		});
	}
}