From c259d990ad63b38140985ba6e25b5046dd767833 Mon Sep 17 00:00:00 2001 From: ulrich Date: Fri, 22 Nov 2024 08:16:48 +0000 Subject: [PATCH] Build-Anweisungen in Readme aktualisiert. --- src/de/uhilger/tango/Server.java | 52 ++++++++++++++++++++++++++++++++-------------------- 1 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/de/uhilger/tango/Server.java b/src/de/uhilger/tango/Server.java index 7c47baf..1a56b0d 100644 --- a/src/de/uhilger/tango/Server.java +++ b/src/de/uhilger/tango/Server.java @@ -25,6 +25,7 @@ import de.uhilger.tango.api.MediaSteuerung; import de.uhilger.tango.api.StopServerHandler; import de.uhilger.tango.api.StorageHandler; +import de.uhilger.tango.api.StreamHandler; import de.uhilger.tango.store.FileStorage; import de.uhilger.tango.entity.Ablageort; import java.io.File; @@ -36,6 +37,7 @@ import de.uhilger.tango.entity.Entity; import java.util.Iterator; import java.util.List; +import java.util.ResourceBundle; /** * Die Klasse Server stellt Methoden zur Ausführung eines HTTP-Servers @@ -53,18 +55,20 @@ public static final String RB_STORE = "store"; public static final String RB_STRG = "strg"; public static final String RB_GSTRG = "gstrg"; - public static final String RB_ALIST= "alist"; + public static final String RB_ALIST = "alist"; + public static final String RB_STRM = "strm"; //public static final String RB_UI_ROOT = "uiroot"; public static final String RB_STOP_SERVER = "stopServer"; //public static final String RB_ABLAGE_TEST = "testAblage"; //public static final String RB_STORE_TEST = "testStore"; public static final String SLASH = "/"; + public static final String NEWLINE = "\n"; private int port; private String ctx; - private HttpServer server; + //private HttpServer server; /** * Ein neues Objekt der Kalsse Server erzeugen @@ -73,7 +77,7 @@ */ public Server(int port) { this.port = port; - } + } /** * Den Port angeben, unter dem der Server erreichbar sein soll @@ -106,37 +110,45 @@ * Objekt * @throws java.lang.ClassNotFoundException */ - public void start() throws IOException, ClassNotFoundException { - logger.log(Level.INFO, App.getRs(RB_SERVER_START_MSG), Integer.toString(port)); + public void start(String wwwData, String conf) throws IOException, ClassNotFoundException { + ResourceBundle rb = ResourceBundle.getBundle(App.RB_NAME); + logger.log(Level.INFO, rb.getString(RB_SERVER_START_MSG), Integer.toString(port)); - String wwwData = App.getInitParameter(App.getRs(App.RB_AP_WWW_DATA)); + //String wwwData = App.getInitParameter(rb.getString(App.RB_AP_WWW_DATA)); File wwwDir = new File(wwwData); - server = HttpServer.create(new InetSocketAddress(port), 0); - server.createContext(ctx + App.getRs(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath())); - ablageorteEinklinken(server); - server.createContext(ctx + App.getRs(RB_STORE), new StorageHandler()); - server.createContext(ctx + App.getRs(RB_STRG), new MediaSteuerung()); - server.createContext(ctx + App.getRs(RB_GSTRG), new GeraetSteuerung()); - server.createContext(ctx + App.getRs(RB_ALIST), new ListHandler()); - server.createContext(ctx + App.getRs(RB_STOP_SERVER), new StopServerHandler()); - server.setExecutor(Executors.newFixedThreadPool(20)); + HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); + server.createContext(ctx + rb.getString(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath())); + ablageorteEinklinken(server, rb, conf); + server.createContext(ctx + rb.getString(RB_STORE), new StorageHandler(conf)); + MediaSteuerung ms = new MediaSteuerung(conf); + server.createContext(ctx + rb.getString(RB_STRG), ms); + server.createContext(ctx + rb.getString(RB_GSTRG), new GeraetSteuerung(conf)); + ListHandler lh = new ListHandler(conf); + lh.addPlaylistListener(ms); + server.createContext(ctx + rb.getString(RB_ALIST), lh); + server.createContext(ctx + rb.getString(RB_STRM), new StreamHandler(conf)); + server.createContext(ctx + rb.getString(RB_STOP_SERVER), new StopServerHandler()); + //server.setExecutor(Executors.newFixedThreadPool(20)); + server.setExecutor(Executors.newFixedThreadPool(5)); server.start(); } + /* public void ablageortEntfernen(String url) { server.removeContext(ctx + url); } - public void ablageortHinzufuegen(Ablageort ort) { + public void ablageortHinzufuegen(Ablageort ort, String conf) { server.createContext(ctx + ort.getUrl(), - new ListFileHandler(new File(ort.getOrt()).getAbsolutePath())); + new ListFileHandler(new File(ort.getOrt()).getAbsolutePath(), conf)); } + */ - private void ablageorteEinklinken(HttpServer server) + private void ablageorteEinklinken(HttpServer server, ResourceBundle rb, String conf) throws ClassNotFoundException, IOException { String typ = Ablageort.class.getSimpleName(); - FileStorage store = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); + FileStorage store = new FileStorage(conf); List<String> orte = store.list(typ); Iterator<String> i = orte.iterator(); while(i.hasNext()) { @@ -147,7 +159,7 @@ logger.log(Level.FINE, "{0}{1}", new Object[]{ctx, ablageort.getUrl()}); logger.fine(ablageort.getOrt()); server.createContext(ctx + ablageort.getUrl(), - new ListFileHandler(new File(ablageort.getOrt()).getAbsolutePath())); + new ListFileHandler(new File(ablageort.getOrt()).getAbsolutePath(), conf)); } } } -- Gitblit v1.9.3