class superServer
{
- public static void main(String[] args)
- {
- String ksName = global.home+global.keyStoreName;
+ public static void main(String[] args) {
+ String ksName = global.home + global.keyStoreName;
char ksPass[] = global.keyStorePass.toCharArray();
char ctPass[] = global.keyStorePass.toCharArray();
-
+ global.request=new dbConnect();
//thread di controllo directory esercizi
Path pathToWatch = FileSystems.getDefault().getPath(global.locationEsercizi);
DirectoryWatcher dirWatcher = new DirectoryWatcher(pathToWatch);
dirWatcherThread.start();
//thread che si occupa del lato http
- httpget regServer=new httpget();
- Thread httpServer=new Thread(regServer);
+ httpget regServer = new httpget();
+ Thread httpServer = new Thread(regServer);
httpServer.start();
-
- while(true)
- {
- try
- {
- KeyStore ks = KeyStore.getInstance("JKS");
- ks.load(new FileInputStream(ksName), ksPass);
- KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
- kmf.init(ks, ctPass);
- SSLContext sc = SSLContext.getInstance("TLS");
- sc.init(kmf.getKeyManagers(), null, null);
- SSLServerSocketFactory ssf = sc.getServerSocketFactory();
- SSLServerSocket s= (SSLServerSocket) ssf.createServerSocket(global.portaServer);
- System.out.println("Server started:");
- while(true)
- {
+ SSLServerSocket s = null;
+ try {
+ KeyStore ks = KeyStore.getInstance("JKS");
+ ks.load(new FileInputStream(ksName), ksPass);
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
+ kmf.init(ks, ctPass);
+ SSLContext sc = SSLContext.getInstance("TLS");
+ sc.init(kmf.getKeyManagers(), null, null);
+ SSLServerSocketFactory ssf = sc.getServerSocketFactory();
+ s = (SSLServerSocket) ssf.createServerSocket(global.portaServer);
+ } catch (CertificateException e) {
+ e.printStackTrace();
+ } catch (UnrecoverableKeyException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (KeyStoreException e) {
+ e.printStackTrace();
+ } catch (KeyManagementException e) {
+ e.printStackTrace();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ if (s != null) {
+ System.out.println("Server started:");
+ while (true) {
+ try {
SSLSocket c = (SSLSocket) s.accept();
- System.out.println("CSC: debug 1");
- guestServer guest=new guestServer(c);
- Thread t=new Thread(guest);
+ guestServer guest = new guestServer(c);
+ Thread t = new Thread(guest);
t.start();
+ } catch (IOException e) {
+ e.printStackTrace();
}
}
- catch (Exception e)
- {
- e.printStackTrace();
- }
}
+ System.out.println("Server die!");
}
}