This repository was archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJapache.java
More file actions
55 lines (43 loc) · 2.03 KB
/
Japache.java
File metadata and controls
55 lines (43 loc) · 2.03 KB
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
package projekt.japache;
import java.io.IOException;
import java.net.BindException;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import com.sun.net.httpserver.HttpServer;
import projekt.japache.logger.EventLogger;
import projekt.japache.logger.EventLogger.LogLevel;
import projekt.japache.logger.FileLogger;
import projekt.japache.config.ConfigLoader;
import projekt.japache.handler.JapacheHandler;
public class Japache {
public final static String JAPACHE_VERSION = "1.0a";
public static void main(String[] args) throws IOException {
EventLogger.log(LogLevel.NORMAL, "Uruchomiono serwer (wersja " + JAPACHE_VERSION + ")");
//Pobranie konfiguracji z pliku config.properties
//oraz przeparsowanie danych na port i hostname serwera
ConfigLoader config = new ConfigLoader("config.properties");
int port = Integer.parseInt(config.get("port"));
String hostname = config.get("hostname");
//Logowanie do pliku
if (config.get("log_enable").equals("true")) {
//Pobranie konfiguracji
String logfile = config.get("log_file");
Boolean clearlog = config.get("log_clear").equals("true");
//Rozpoczęcie zapisu
EventLogger.addLogger(new FileLogger(logfile, clearlog));
} else {
EventLogger.log(LogLevel.NORMAL, "Logowanie do pliku jest wyłączone");
}
try {
//Utworzenie instancji serwera pod danym hostname i portem
HttpServer server = HttpServer.create();
server.bind(new InetSocketAddress(hostname, port), 0);
server.setExecutor(Executors.newFixedThreadPool(2));
server.createContext("/", new JapacheHandler(config));
server.start();
EventLogger.log(LogLevel.NORMAL, "Adres serwera: " + hostname + ":" + port);
} catch (BindException ex) {
EventLogger.log(LogLevel.ERROR, "Wystąpił błąd podczas bindowania pod adres " + hostname + ":" + port);
}
}
}