made some preferences configurable
This commit is contained in:
8
backend/Readme.md
Normal file
8
backend/Readme.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Backend
|
||||||
|
|
||||||
|
This module manages all backend services, i.e.:
|
||||||
|
|
||||||
|
* it loads the configuration
|
||||||
|
* starts a webserver
|
||||||
|
* binds all other api modules to the webserver
|
||||||
|
* binds the web module to the webserver
|
||||||
@@ -16,9 +16,11 @@ dependencies{
|
|||||||
implementation(project(":translations"))
|
implementation(project(":translations"))
|
||||||
implementation(project(":user"))
|
implementation(project(":user"))
|
||||||
implementation(project(":web"))
|
implementation(project(":web"))
|
||||||
|
implementation("de.srsoftware:configuration.api:1.0.2")
|
||||||
|
implementation("de.srsoftware:configuration.json:1.0.3")
|
||||||
implementation("de.srsoftware:tools.optionals:1.0.0")
|
implementation("de.srsoftware:tools.optionals:1.0.0")
|
||||||
implementation("de.srsoftware:tools.util:2.0.3")
|
implementation("de.srsoftware:tools.util:2.0.3")
|
||||||
|
implementation("org.json:json:20240303")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.jar {
|
tasks.jar {
|
||||||
|
|||||||
@@ -1,39 +1,58 @@
|
|||||||
/* © SRSoftware 2025 */
|
/* © SRSoftware 2025 */
|
||||||
package de.srsoftware.umbrella.backend;
|
package de.srsoftware.umbrella.backend;
|
||||||
|
|
||||||
|
import static de.srsoftware.umbrella.core.Constants.UMBRELLA;
|
||||||
|
import static de.srsoftware.umbrella.core.Util.mapLogLevel;
|
||||||
import static java.lang.System.Logger.Level.DEBUG;
|
import static java.lang.System.Logger.Level.DEBUG;
|
||||||
import static java.lang.System.Logger.Level.INFO;
|
import static java.lang.System.Logger.Level.INFO;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpServer;
|
import com.sun.net.httpserver.HttpServer;
|
||||||
|
import de.srsoftware.configuration.JsonConfig;
|
||||||
import de.srsoftware.tools.ColorLogger;
|
import de.srsoftware.tools.ColorLogger;
|
||||||
import de.srsoftware.umbrella.core.ConnectionProvider;
|
import de.srsoftware.umbrella.core.ConnectionProvider;
|
||||||
import de.srsoftware.umbrella.translations.Translations;
|
import de.srsoftware.umbrella.translations.Translations;
|
||||||
import de.srsoftware.umbrella.user.UserModule;
|
import de.srsoftware.umbrella.user.UserModule;
|
||||||
import de.srsoftware.umbrella.user.sqlite.SqliteDB;
|
import de.srsoftware.umbrella.user.sqlite.SqliteDB;
|
||||||
import de.srsoftware.umbrella.web.WebHandler;
|
import de.srsoftware.umbrella.web.WebHandler;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
private static final System.Logger LOG = System.getLogger("Umbrella");
|
private static final System.Logger LOG = System.getLogger("Umbrella");
|
||||||
private static final String USER_DB = "/home/srichter/workspace/umbrella/data/umbrella.db";
|
|
||||||
private static final String LOGIN_SERVICE_DB = "/home/srichter/workspace/umbrella/data/umbrella.db";
|
private static void configureLogging(JsonConfig jsonConfig) {
|
||||||
|
var rootLevel = jsonConfig.get("umbrella.logging.rootLevel", "INFO");
|
||||||
|
ColorLogger.setRootLogLevel(mapLogLevel(rootLevel));
|
||||||
|
|
||||||
|
var loggers = jsonConfig.get("umbrella.logging.loggers").orElse(null);
|
||||||
|
if (loggers instanceof JSONObject json){
|
||||||
|
json.keySet().forEach(key -> {
|
||||||
|
var lvl = mapLogLevel(json.getString(key));
|
||||||
|
ColorLogger.setLogLevel(key,lvl);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
ColorLogger.setRootLogLevel(DEBUG);
|
|
||||||
LOG.log(INFO, "Starting Umbrella:");
|
LOG.log(INFO, "Starting Umbrella:");
|
||||||
var port = 8080;
|
var jsonConfig = new JsonConfig(UMBRELLA);
|
||||||
var threads = 16;
|
configureLogging(jsonConfig);
|
||||||
|
var port = jsonConfig.get("umbrella.http.port", 8080);
|
||||||
|
var threads = jsonConfig.get("umbrella.threads", 16);
|
||||||
|
var userDB = jsonConfig.get("umbrella.database.user", jsonConfig.file().getParent()+"/umbrella.db");
|
||||||
|
var loginDB = jsonConfig.get("umbrella.database.login_services",jsonConfig.file().getParent()+"/umbrella.db");
|
||||||
var connectionProvider = new ConnectionProvider();
|
var connectionProvider = new ConnectionProvider();
|
||||||
var userDb = new SqliteDB(connectionProvider.get(USER_DB));
|
var userDb = new SqliteDB(connectionProvider.get(userDB));
|
||||||
var loginServicedb = new SqliteDB(connectionProvider.get(LOGIN_SERVICE_DB));
|
var loginServicedb = new SqliteDB(connectionProvider.get(loginDB));
|
||||||
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
|
var server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||||
server.setExecutor(Executors.newFixedThreadPool(threads));
|
server.setExecutor(Executors.newFixedThreadPool(threads));
|
||||||
new WebHandler().bindPath("/").on(server);
|
new WebHandler().bindPath("/").on(server);
|
||||||
new UserModule(userDb,loginServicedb).bindPath("/api/user").on(server);
|
new UserModule(userDb,loginServicedb).bindPath("/api/user").on(server);
|
||||||
new Translations().bindPath("/api/translations").on(server);
|
new Translations().bindPath("/api/translations").on(server);
|
||||||
LOG.log(INFO,"Started web server at {0}",port);
|
|
||||||
server.start();
|
server.start();
|
||||||
|
LOG.log(INFO,"Started web server at {0}",port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,16 @@ public class Util {
|
|||||||
public static final System.Logger LOG = System.getLogger("Util");
|
public static final System.Logger LOG = System.getLogger("Util");
|
||||||
private Util(){}
|
private Util(){}
|
||||||
|
|
||||||
|
public static System.Logger.Level mapLogLevel(String lbl) {
|
||||||
|
return switch (lbl){
|
||||||
|
case "ERROR" -> ERROR;
|
||||||
|
case "WARN" -> WARNING;
|
||||||
|
case "DEBUG" -> DEBUG;
|
||||||
|
case "TRACE" -> TRACE;
|
||||||
|
default -> INFO;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static HttpURLConnection open(URL url) throws IOException {
|
public static HttpURLConnection open(URL url) throws IOException {
|
||||||
var conn = (HttpURLConnection) url.openConnection();
|
var conn = (HttpURLConnection) url.openConnection();
|
||||||
conn.setRequestProperty("Accept","*/*");
|
conn.setRequestProperty("Accept","*/*");
|
||||||
|
|||||||
Reference in New Issue
Block a user