From 8abbcfbb478405ca5f61218018ac5d61104d6f35 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Fri, 26 Mar 2021 14:50:39 +0000
Subject: [PATCH] FileHandler erweitert (not found)

---
 src/de/uhilger/minsrv/Server.java |   53 +++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/src/de/uhilger/minsrv/Server.java b/src/de/uhilger/minsrv/Server.java
index 7cee404..6935d9a 100644
--- a/src/de/uhilger/minsrv/Server.java
+++ b/src/de/uhilger/minsrv/Server.java
@@ -1,19 +1,19 @@
 /*
-    mc2 - Mediacenter neu
-    Copyright (C) 2021  Ulrich Hilger
+  mini-server - Ein minimalistischer HTTP-Server
+  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 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.
+  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 <https://www.gnu.org/licenses/>.
+  You should have received a copy of the GNU Affero General Public License
+  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
 package de.uhilger.minsrv;
@@ -27,8 +27,11 @@
 import java.util.concurrent.Executors;
 
 /**
- *
- * @author ulrich
+ * Die Klasse Server stellt Methoden zur Ausf&uuml;hrung eines 
+ * HTTP-Servers bereit
+ * 
+ * @author Ulrich Hilger
+ * @version 0.1, 25.03.2021
  */
 public class Server {
   
@@ -36,20 +39,38 @@
   
   private int port;
   
+  private String ctxName;
+  
   public Server(int port) {
     this.port = port;
   }
   
+  /**
+   * Den Port angeben, unter dem der Server erreichbar sein soll
+   * 
+   * @param port der Port, unter dem der Server erreichbar sein soll
+   */
   public void setPort(int port) {
     this.port = port;
   }
   
+  public void setContextName(String ctxName) {
+    this.ctxName = ctxName;
+  }
+  
+  /**
+   * Die Endpunkte ('Context'e) einrichten, unter denen die Dienste 
+   * dieses Servers erreichbar sein sollen und den Server starten
+   * 
+   * @throws IOException wenn etwas schief geht, finden sich Angaben 
+   * in diesem Objekt 
+   */
   public void start() throws IOException {
     logger.info("Server starting on port " + port);
 
     HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
-    server.createContext("/mc2/av", new FileHandler(App.getInitParameter(App.IP_WWW_DATA)));
-    server.createContext("/mc2/server/stop", new StopServerHandler());
+    server.createContext(ctxName + "/av", new FileHandler(App.getInitParameter(App.IP_WWW_DATA)));
+    server.createContext(ctxName + "/server/stop", new StopServerHandler());
     server.setExecutor(Executors.newFixedThreadPool(20));
     server.start();
   }

--
Gitblit v1.9.3