From 2eeb9e441b99e390067cb5573d858c8bd72902f1 Mon Sep 17 00:00:00 2001 From: ulrich Date: Sat, 27 Mar 2021 11:29:28 +0000 Subject: [PATCH] Unterscheidung HEAD/GET eingebaut --- src/de/uhilger/minsrv/Server.java | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/de/uhilger/minsrv/Server.java b/src/de/uhilger/minsrv/Server.java index 6935d9a..89e425f 100644 --- a/src/de/uhilger/minsrv/Server.java +++ b/src/de/uhilger/minsrv/Server.java @@ -37,10 +37,17 @@ private static final Logger logger = Logger.getLogger(Server.class.getName()); + public static final String STR_SLASH = "/"; + + private int port; - private String ctxName; + private String ctx; + /** + * Ein neues Objekt der Kalsse Server erzeugen + * @param port der Port, über den dieser Server erreichbar sein soll + */ public Server(int port) { this.port = port; } @@ -54,8 +61,17 @@ this.port = port; } + /** + * Den Namen des Kontexts angeben, über den dieser Server + * erreichbar sein soll + * @param ctxName + */ public void setContextName(String ctxName) { - this.ctxName = ctxName; + if(!ctxName.startsWith(STR_SLASH)) { + this.ctx = STR_SLASH + ctxName; + } else { + this.ctx = ctxName; + } } /** @@ -69,8 +85,8 @@ logger.info("Server starting on port " + port); HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); - server.createContext(ctxName + "/av", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); - server.createContext(ctxName + "/server/stop", new StopServerHandler()); + server.createContext(ctx + "/av", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); + server.createContext(ctx + "/server/stop", new StopServerHandler()); server.setExecutor(Executors.newFixedThreadPool(20)); server.start(); } -- Gitblit v1.9.3