]> matita.cs.unibo.it Git - logicplayer.git/blob - server/com/company/superServer.java
New version
[logicplayer.git] / server / com / company / superServer.java
1 package com.company;
2
3 import java.io.*;
4 import java.lang.Thread;
5 import java.security.*;
6 import javax.net.ssl.*;
7
8 import java.nio.file.FileSystems;
9 import java.nio.file.Path;
10
11
12 class superServer
13 {
14         public static void main(String[] args) {
15                 String ksName = global.home + global.keyStoreName;
16                 char ksPass[] = global.keyStorePass.toCharArray();
17                 char ctPass[] = global.keyStorePass.toCharArray();
18                 global.request=new dbConnect();
19                 //thread di controllo directory esercizi
20                 Path pathToWatch = FileSystems.getDefault().getPath(global.locationEsercizi);
21                 DirectoryWatcher dirWatcher = new DirectoryWatcher(pathToWatch);
22                 Thread dirWatcherThread = new Thread(dirWatcher);
23                 dirWatcherThread.start();
24
25                 //thread che si occupa del lato http
26                 httpget regServer = new httpget();
27                 Thread httpServer = new Thread(regServer);
28                 httpServer.start();
29                 SSLServerSocket s = null;
30                 try {
31                         KeyStore ks = KeyStore.getInstance("JKS");
32                         ks.load(new FileInputStream(ksName), ksPass);
33                         KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
34                         kmf.init(ks, ctPass);
35                         SSLContext sc = SSLContext.getInstance("TLS");
36                         sc.init(kmf.getKeyManagers(), null, null);
37                         SSLServerSocketFactory ssf = sc.getServerSocketFactory();
38                         s = (SSLServerSocket) ssf.createServerSocket(global.portaServer);
39                 } catch (CertificateException e) {
40                         e.printStackTrace();
41                 } catch (UnrecoverableKeyException e) {
42                         e.printStackTrace();
43                 } catch (NoSuchAlgorithmException e) {
44                         e.printStackTrace();
45                 } catch (KeyStoreException e) {
46                         e.printStackTrace();
47                 } catch (KeyManagementException e) {
48                         e.printStackTrace();
49                 } catch (FileNotFoundException e) {
50                         e.printStackTrace();
51                 } catch (IOException e) {
52                         e.printStackTrace();
53                 }
54                 if (s != null) {
55                         System.out.println("Server started:");
56                         while (true) {
57                                 try {
58                                         SSLSocket c = (SSLSocket) s.accept();
59                                         guestServer guest = new guestServer(c);
60                                         Thread t = new Thread(guest);
61                                         t.start();
62                                 } catch (IOException e) {
63                                         e.printStackTrace();
64                                 }
65                         }
66                 }
67                 System.out.println("Server die!");
68         }
69 }