4 files modified
3 files added
| | |
| | | package de.uhilger.avdirektor; |
| | | |
| | | import com.sun.net.httpserver.HttpServer; |
| | | import de.uhilger.avdirektor.handler.PingHandler; |
| | | import de.uhilger.avdirektor.handler.PlayHandler; |
| | | import de.uhilger.avdirektor.handler.StopHandler; |
| | | import de.uhilger.avdirektor.handler.StopServerHandler; |
| | | import java.io.IOException; |
| | | import java.util.logging.Logger; |
| | |
| | | |
| | | public void start() throws IOException { |
| | | logger.info("Server starting on port " + port); |
| | | |
| | | StopHandler sh = new StopHandler(); |
| | | sh.setCmd(App.CMD_STOP); |
| | | |
| | | HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
| | | server.createContext("/avd/play", new PlayHandler()); |
| | | server.createContext("/avd/stop", sh); |
| | | server.createContext("/avd/ping", new PingHandler()); |
| | | server.createContext("/avd/server/stop", new StopServerHandler()); |
| | | server.setExecutor(null); // creates a default executor |
| | | server.start(); |
New file |
| | |
| | | /* |
| | | * To change this license header, choose License Headers in Project Properties. |
| | | * To change this template file, choose Tools | Templates |
| | | * and open the template in the editor. |
| | | */ |
| | | package de.uhilger.avdirektor.handler; |
| | | |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import com.sun.net.httpserver.HttpHandler; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.Map; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * |
| | | * @author ulrich |
| | | */ |
| | | public abstract class CmdHandler extends OMXPlayer implements HttpHandler { |
| | | |
| | | private static final Logger logger = Logger.getLogger(CmdHandler.class.getName()); |
| | | |
| | | protected String cmd; |
| | | |
| | | public abstract void setCmd(String cmd); |
| | | |
| | | @Override |
| | | public void handle(HttpExchange t) throws IOException { |
| | | logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); |
| | | Map map = getQueryMap(t); |
| | | |
| | | String antwort = this.kommando(t, cmd); |
| | | logger.log(Level.FINE, antwort); |
| | | |
| | | String response = getResponseString(map, "cmd", antwort); |
| | | t.sendResponseHeaders(200, response.length()); |
| | | OutputStream os = t.getResponseBody(); |
| | | os.write(response.getBytes()); |
| | | os.close(); |
| | | } |
| | | |
| | | } |
| | |
| | | import java.net.URL; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | |
| | | public abstract class OMXPlayer implements ProzessLauscher { |
| | | |
| | | private static final Logger logger = Logger.getLogger(OMXPlayer.class.getName()); |
| | | |
| | | protected String getParam(Map map, String key) { |
| | | Object o = map.get(key); |
| | | if(o != null) { |
| | | return o.toString(); |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | protected Map getQueryMap(HttpExchange t) { |
| | | HashMap map = new HashMap(); |
| | |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | protected String getResponseString(Map map, String cmd, String antwort) { |
| | | Set keys = map.keySet(); |
| | | StringBuilder buf = new StringBuilder(); |
| | | buf.append("play"); |
| | | buf.append(System.lineSeparator()); |
| | | keys.forEach((Object key) -> { |
| | | buf.append("key: "); |
| | | buf.append(key); |
| | | buf.append(System.lineSeparator()); |
| | | buf.append("value: "); |
| | | buf.append(map.get(key)); |
| | | buf.append(System.lineSeparator()); |
| | | //logger.log(Level.FINE, "key {0} value {1}", new Object[]{key, map.get(key)}); |
| | | }); |
| | | buf.append(antwort); |
| | | return buf.toString(); |
| | | } |
| | | |
| | | /** |
| | |
| | | mt.start(); |
| | | } |
| | | //servletContext.setAttribute(App.PI_PLAYER, player_process); |
| | | t.setAttribute(App.PI_PLAYER, player_process); |
| | | //Runtime.getRuntime().exec("killall dbus-daemon"); |
| | | antwort = "Abspielen gestartet, url: " + urlStr; |
| | | } |
New file |
| | |
| | | /* |
| | | * To change this license header, choose License Headers in Project Properties. |
| | | * To change this template file, choose Tools | Templates |
| | | * and open the template in the editor. |
| | | */ |
| | | package de.uhilger.avdirektor.handler; |
| | | |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import com.sun.net.httpserver.HttpHandler; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * |
| | | * @author ulrich |
| | | */ |
| | | public class PingHandler implements HttpHandler { |
| | | |
| | | private static final Logger logger = Logger.getLogger(PingHandler.class.getName()); |
| | | |
| | | |
| | | @Override |
| | | public void handle(HttpExchange t) throws IOException { |
| | | logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); |
| | | |
| | | String antwort = "ping Antwort"; |
| | | |
| | | String response = antwort; |
| | | t.sendResponseHeaders(200, response.length()); |
| | | OutputStream os = t.getResponseBody(); |
| | | os.write(response.getBytes()); |
| | | os.close(); |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void handle(HttpExchange t) throws IOException { |
| | | logger.log(Level.FINE, "RequestURI.getPath: {0}", t.getRequestURI().getPath()); |
| | | logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); |
| | | Map map = getQueryMap(t); |
| | | Set keys = map.keySet(); |
| | | StringBuffer buf = new StringBuffer(); |
| | | buf.append("play"); |
| | | buf.append(System.lineSeparator()); |
| | | keys.forEach((Object key) -> { |
| | | buf.append("key: "); |
| | | buf.append(key); |
| | | buf.append(System.lineSeparator()); |
| | | buf.append("value: "); |
| | | buf.append(map.get(key)); |
| | | buf.append(System.lineSeparator()); |
| | | logger.log(Level.FINE, "key {0} value {1}", new Object[]{key, map.get(key)}); |
| | | }); |
| | | |
| | | String response = buf.toString(); |
| | | String antwort = abspielenMitParameternUndRueckmeldung(t, |
| | | getParam(map, "t"), getParam(map, "p"), getParam(map, "r"), "1"); |
| | | |
| | | String response = getResponseString(map, "play", antwort); |
| | | t.sendResponseHeaders(200, response.length()); |
| | | OutputStream os = t.getResponseBody(); |
| | | os.write(response.getBytes()); |
New file |
| | |
| | | /* |
| | | * To change this license header, choose License Headers in Project Properties. |
| | | * To change this template file, choose Tools | Templates |
| | | * and open the template in the editor. |
| | | */ |
| | | package de.uhilger.avdirektor.handler; |
| | | |
| | | /** |
| | | * |
| | | * @author ulrich |
| | | */ |
| | | public class StopHandler extends CmdHandler { |
| | | |
| | | @Override |
| | | public void setCmd(String cmd) { |
| | | this.cmd = cmd; |
| | | } |
| | | |
| | | } |
| | |
| | | # de.uhilger.filecms.level = FINEST |
| | | # de.uhilger.wbx.handlers = java.util.logging.ConsoleHandler |
| | | # de.uhilger.wbx.level = FINEST |
| | | de.uhilger.avdirektor.handlers = java.util.logging.FileHandler, java.util.logging.ConsoleHandler |
| | | de.uhilger.avdirektor.level = INFO |