X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=server%2Fcom%2Fcompany%2FsuperServer.java;h=20100a1022d48b7cb98c7ad1615d4e7d2356fa7b;hb=2a08ef802fd497e1d699e67204c8d42c137146da;hp=bac54fda29d9966e64a24eea8bb417116eea775d;hpb=39f6e6d4d05ad6819318e8a372147dd3d4ec6af7;p=logicplayer.git diff --git a/server/com/company/superServer.java b/server/com/company/superServer.java index bac54fd..20100a1 100644 --- a/server/com/company/superServer.java +++ b/server/com/company/superServer.java @@ -3,6 +3,7 @@ package com.company; import java.io.*; import java.lang.Thread; import java.security.*; +import java.security.cert.*; import javax.net.ssl.*; import java.nio.file.FileSystems; @@ -11,12 +12,11 @@ import java.nio.file.Path; 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); @@ -24,35 +24,47 @@ class superServer 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(); - 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!"); } }