/* Proto - Ein Rumpf-Konstrukt fuer Webapps Copyright (C) 2021 Ulrich Hilger This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package de.uhilger.proto; import com.sun.net.httpserver.HttpServer; import java.io.IOException; import java.net.InetSocketAddress; import java.util.HashMap; import java.util.ResourceBundle; import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; /** * Die Hauptklasse der Proto-App * * Starten mit * java -jar proto.jar ctx=/proto www=./www port=8008 * * @author Ulrich Hilger * @version 1, 11.5.2021 */ public class App { /* Name des ResourceBundles dieser App */ public static final String RB_NAME = "proto"; public static final String RB_SERVER_START_MSG = "msgServerStart"; public static final String API_SERVER_STOP = "/api/server/stop"; public static final String STR_SLASH = "/"; public static final String ARG_WWW = "www"; public static final String ARG_CTX = "ctx"; public static final String ARG_PORT = "port"; /** * Parameter: * port=[portnr] (9123) * ctx=[context] (/proto) * www=[www-dir] ("./www") * * @param args the command line arguments */ public static void main(String[] args) { try { ResourceBundle rb = ResourceBundle.getBundle(RB_NAME); HashMap initParams = new HashMap(); for (String arg : args) { String[] argParts = arg.split("="); initParams.put(argParts[0], argParts[1]); } Logger.getLogger(App.class.getName()).log(Level.INFO, rb.getString(RB_SERVER_START_MSG), initParams.get(ARG_PORT)); String ctx = initParams.get(ARG_CTX); HttpServer server = HttpServer.create(new InetSocketAddress(Integer.parseInt(initParams.get(ARG_PORT))), 0); server.createContext(ctx + STR_SLASH, new FileHandler(initParams.get(ARG_WWW))); server.createContext(ctx + API_SERVER_STOP, new StopServerHandler()); server.setExecutor(Executors.newCachedThreadPool()); server.start(); } catch (IOException ex) { Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); } } }