From 94c45ccb52cff4fe8e4fc8b31cef9eb16da80c85 Mon Sep 17 00:00:00 2001 From: ulrich Date: Wed, 31 Mar 2021 21:32:43 +0000 Subject: [PATCH] OMXPlayer Log verarbeiten --- src/de/uhilger/avdirektor/handler/LogHandler.java | 25 ++++++++++++++++++++++++- 1 files changed, 24 insertions(+), 1 deletions(-) diff --git a/src/de/uhilger/avdirektor/handler/LogHandler.java b/src/de/uhilger/avdirektor/handler/LogHandler.java index 8d49d27..b77b5da 100644 --- a/src/de/uhilger/avdirektor/handler/LogHandler.java +++ b/src/de/uhilger/avdirektor/handler/LogHandler.java @@ -3,7 +3,10 @@ import com.sun.net.httpserver.HttpExchange; import de.uhilger.avdirektor.OMXLogLeser; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.OutputStream; +import java.text.ParseException; import java.util.logging.Level; import java.util.logging.Logger; @@ -14,15 +17,35 @@ public class LogHandler extends AbstractHandler { private static final Logger logger = Logger.getLogger(LogHandler.class.getName()); + + @Override + public void handle(HttpExchange t) throws IOException { + logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); + StringBuilder params = buildParams(t); + String antwort = process(t, params.toString()); + sendResponse(t, cmd, antwort); + } + + @Override + protected void sendResponse(HttpExchange t, String cmd, String antwort) throws IOException { + t.sendResponseHeaders(200, antwort.length()); + OutputStream os = t.getResponseBody(); + os.write(antwort.getBytes()); + os.close(); + } + @Override protected String process(HttpExchange t, String params) { OMXLogLeser leser = new OMXLogLeser(); String lines = "Log nicht lesbar."; try { - lines = leser.lesen(new File("/home/ulrich/work/avd/omxplayer.log")); + logger.info(new File(".").getAbsolutePath()); + lines = leser.lesen(new File("omxplayer.log")); } catch (IOException ex) { Logger.getLogger(LogHandler.class.getName()).log(Level.SEVERE, null, ex); + } catch (ParseException ex) { + Logger.getLogger(LogHandler.class.getName()).log(Level.SEVERE, null, ex); } return lines; } -- Gitblit v1.9.3