Nicht erforderliche globale Variablen entfernt
| | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.ResourceBundle; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | |
| | | |
| | | private static final Logger logger = Logger.getLogger(App.class.getName()); |
| | | |
| | | private static HashMap initParams; |
| | | |
| | | /* ResourceBundle dieser App */ |
| | | private static ResourceBundle rb; |
| | | |
| | | /* Name des ResourceBundles dieser App */ |
| | | private static final String RB_NAME = "tango"; |
| | | |
| | | /* Der Server dieser App */ |
| | | private static Server server; |
| | | public static final String RB_NAME = "tango"; |
| | | |
| | | /* ResourceBundle-Kennungen */ |
| | | public static final String RB_PARAM_FEHLT = "msgParamFehlt"; |
| | |
| | | * @throws java.lang.ClassNotFoundException |
| | | */ |
| | | public static void main(String[] args) throws ClassNotFoundException { |
| | | rb = ResourceBundle.getBundle(RB_NAME); |
| | | ResourceBundle rb = ResourceBundle.getBundle(RB_NAME); |
| | | logger.fine(new File(".").getAbsolutePath()); |
| | | |
| | | initParams = new HashMap(); |
| | | HashMap<String,String> initParams = new HashMap(); |
| | | for (String arg : args) { |
| | | String[] argParts = arg.split("="); |
| | | initParams.put(argParts[0], argParts[1]); |
| | | } |
| | | |
| | | String portStr = getInitParameter(getRs(RB_AP_PORT)); |
| | | String portStr = initParams.get(rb.getString(RB_AP_PORT)); |
| | | if (portStr != null) { |
| | | //Server server = new Server(Integer.parseInt(portStr)); |
| | | server = new Server(Integer.parseInt(portStr)); |
| | | Server server = new Server(Integer.parseInt(portStr)); |
| | | try { |
| | | String ctxName = getInitParameter(getRs(RB_AP_CTX)); |
| | | String ctxName = initParams.get(rb.getString(RB_AP_CTX)); |
| | | if (ctxName != null) { |
| | | server.setContextName(ctxName); |
| | | server.start(); |
| | | server.start(initParams.get(rb.getString(RB_AP_WWW_DATA)), |
| | | initParams.get(rb.getString(RB_AP_CONF))); |
| | | } else { |
| | | logger.log(Level.INFO, getRs(RB_PARAM_FEHLT), getRs(RB_AP_CTX)); |
| | | logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CTX)); |
| | | } |
| | | String conf = getInitParameter(getRs(RB_AP_CONF)); |
| | | String conf = initParams.get(rb.getString(RB_AP_CONF)); |
| | | if(conf != null) { |
| | | File confDir = new File(conf); |
| | | confDir.mkdirs(); |
| | | } else { |
| | | logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_CONF)); |
| | | logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CONF)); |
| | | } |
| | | } catch (IOException ex) { |
| | | logger.log(Level.SEVERE, null, ex); |
| | | } |
| | | } else { |
| | | logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_PORT)); |
| | | logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_PORT)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Diese Anwendung stoppen |
| | | */ |
| | | public static void stop() { |
| | | System.exit(0); |
| | | } |
| | | |
| | | /** |
| | | * Einen Kommandozeilenparameter ermitteln |
| | | * |
| | | * @param pname Names des Parameters |
| | | * @return Inhalt des Parameters oder null, wenn der Parameter nicht gefunden |
| | | * wurde |
| | | */ |
| | | public static String getInitParameter(String pname) { |
| | | String param = null; |
| | | Object o = initParams.get(pname); |
| | | if (o != null) { |
| | | param = o.toString(); |
| | | } |
| | | return param; |
| | | } |
| | | |
| | | public static String getRs(String key) { |
| | | return rb.getString(key); |
| | | } |
| | | |
| | | public static Server getServer() { |
| | | return server; |
| | | } |
| | | |
| | | } |
| | |
| | | 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 |
| | |
| | | |
| | | private String ctx; |
| | | |
| | | private HttpServer server; |
| | | //private HttpServer server; |
| | | |
| | | /** |
| | | * Ein neues Objekt der Kalsse Server erzeugen |
| | |
| | | */ |
| | | public Server(int port) { |
| | | this.port = port; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Den Port angeben, unter dem der Server erreichbar sein soll |
| | |
| | | * 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()); |
| | | 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)); |
| | | server.createContext(ctx + rb.getString(RB_STRG), new MediaSteuerung(conf)); |
| | | server.createContext(ctx + rb.getString(RB_GSTRG), new GeraetSteuerung(conf)); |
| | | server.createContext(ctx + rb.getString(RB_ALIST), new ListHandler(conf)); |
| | | server.createContext(ctx + rb.getString(RB_STOP_SERVER), new StopServerHandler()); |
| | | //server.setExecutor(Executors.newFixedThreadPool(20)); |
| | | server.setExecutor(Executors.newCachedThreadPool()); |
| | | 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()) { |
| | |
| | | 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)); |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.sun.net.httpserver.Headers; |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import com.sun.net.httpserver.HttpHandler; |
| | | import de.uhilger.tango.App; |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStream; |
| | | import java.util.ResourceBundle; |
| | | import java.util.logging.Logger; |
| | | |
| | | |
| | |
| | | public static final int RTC_NOT_FOUND = 404; |
| | | |
| | | protected int returnCode; |
| | | |
| | | private ResourceBundle rb; |
| | | |
| | | public AbstractHandler() { |
| | | this.returnCode = RTC_OK; |
| | |
| | | protected abstract boolean delete(HttpExchange e); |
| | | */ |
| | | |
| | | protected String getResString(String key) { |
| | | if(rb == null) { |
| | | rb = ResourceBundle.getBundle(App.RB_NAME); |
| | | } |
| | | return rb.getString(key); |
| | | } |
| | | |
| | | } |
| | |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.ResourceBundle; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | |
| | | |
| | | /* Ablageort fuer Webinhalte */ |
| | | protected final String fileBase; |
| | | |
| | | private ResourceBundle rb; |
| | | |
| | | /** |
| | | * Ein neues Objekt der Klasse FileHandler erzeugen |
| | |
| | | serveFileParts(e, new File(fileBase, fName)); |
| | | } else { |
| | | if (fName.length() < 1 || fName.endsWith(Server.SLASH)) { |
| | | fName += App.getRs(RB_WELCOME_FILE); |
| | | ResourceBundle rb = ResourceBundle.getBundle(App.RB_NAME); |
| | | fName += getResString(RB_WELCOME_FILE); |
| | | } |
| | | serveFile(e, new File(fileBase, fName)); |
| | | } |
| | |
| | | Der regulaere Ausdruck "[^\\d-,]" bezeichnet alle Zeichen, die keine |
| | | Ziffern 0-9, Bindestrich oder Komma sind. |
| | | */ |
| | | rangeHeader = rangeHeader.replaceAll(App.getRs(RB_RANGE_PATTERN), ""); |
| | | rangeHeader = rangeHeader.replaceAll(getResString(RB_RANGE_PATTERN), ""); |
| | | |
| | | /* |
| | | Die Ranges ermitteln. |
| | |
| | | String[] rangeArray = rangeHeader.split(STR_COMMA); |
| | | for (String rangeStr : rangeArray) { |
| | | Range range = new Range(); |
| | | String[] values = rangeStr.split(App.getRs(RB_DASH)); |
| | | String[] values = rangeStr.split(getResString(RB_DASH)); |
| | | if (values.length < 2) { |
| | | // Fall 3 |
| | | range.setStart(Long.parseLong(values[0])); |
| | |
| | | */ |
| | | protected String contentRangeHdr(Range range, File file) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append(App.getRs(RB_BYTES)); |
| | | sb.append(getResString(RB_BYTES)); |
| | | sb.append(STR_BLANK); |
| | | sb.append(range.getStart()); |
| | | sb.append(App.getRs(RB_DASH)); |
| | | sb.append(getResString(RB_DASH)); |
| | | sb.append(range.getEnd()); |
| | | sb.append(Server.SLASH); |
| | | sb.append(file.length()); |
| | |
| | | */ |
| | | protected void setHeaders(HttpExchange e, File file) throws IOException { |
| | | Headers resHeaders = e.getResponseHeaders(); |
| | | resHeaders.add(ACCEPT_RANGES_HEADER, App.getRs(RB_BYTES)); |
| | | resHeaders.add(ACCEPT_RANGES_HEADER, getResString(RB_BYTES)); |
| | | String mimeType = Files.probeContentType(file.toPath()); |
| | | if (mimeType != null) { |
| | | resHeaders.add(CONTENT_TYPE, mimeType); |
| | | } |
| | | SimpleDateFormat sdf = new SimpleDateFormat(App.getRs(RB_LM_PATTERN)); |
| | | SimpleDateFormat sdf = new SimpleDateFormat(getResString(RB_LM_PATTERN)); |
| | | Date date = new Date(file.lastModified()); |
| | | resHeaders.add(LAST_MODIFIED_DATE_HEADER, sdf.format(date)); |
| | | } |
| | |
| | | */ |
| | | protected void sendNotFound(HttpExchange e, String fname) throws IOException { |
| | | OutputStream os = e.getResponseBody(); |
| | | String response = fname + STR_BLANK + App.getRs(RB_NOT_FOUND); |
| | | String response = fname + STR_BLANK + getResString(RB_NOT_FOUND); |
| | | byte[] bytes = response.getBytes(StandardCharsets.UTF_8); |
| | | e.sendResponseHeaders(SC_NOT_FOUND, bytes.length); |
| | | os.write(bytes); |
| | |
| | | return ranges.iterator(); |
| | | } |
| | | } |
| | | |
| | | protected String getResString(String key) { |
| | | if(rb == null) { |
| | | rb = ResourceBundle.getBundle(App.RB_NAME); |
| | | } |
| | | return rb.getString(key); |
| | | } |
| | | } |
| | |
| | | public static final String KMD_AUS = "aus"; |
| | | public static final String KMD_STATUS = "status"; |
| | | |
| | | private String conf; |
| | | |
| | | public GeraetSteuerung(String conf) { |
| | | this.conf = conf; |
| | | } |
| | | |
| | | @Override |
| | | protected String get(HttpExchange e) { |
| | | String response; |
| | | String path = e.getRequestURI().toString(); |
| | | String[] elems = path.split(Server.SLASH); |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | FileStorage fs = new FileStorage(conf); |
| | | logger.fine(path); |
| | | |
| | | String geraetName = elems[5]; |
| | |
| | | |
| | | Map extMap = new HashMap(); |
| | | |
| | | public ListFileHandler(String absoluteDirectoryPathAndName) { |
| | | private String conf; |
| | | |
| | | public ListFileHandler(String absoluteDirectoryPathAndName, String conf) { |
| | | super(absoluteDirectoryPathAndName); |
| | | /* |
| | | Ermittlung von Dateifiltern. |
| | |
| | | jeweils als Dateierweiterungen mit Komma getrennt |
| | | z.B. "mp4,m4v" |
| | | */ |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | initMap(fs, App.getRs(App.RB_AUDIOEXTS), StorageFile.TYP_AUDIO); |
| | | initMap(fs, App.getRs(App.RB_VIDEOEXTS), StorageFile.TYP_VIDEO); |
| | | FileStorage fs = new FileStorage(conf); |
| | | initMap(fs, getResString(App.RB_AUDIOEXTS), StorageFile.TYP_AUDIO); |
| | | initMap(fs, getResString(App.RB_VIDEOEXTS), StorageFile.TYP_VIDEO); |
| | | } |
| | | |
| | | private void initMap(Storage s, String key, String typ) { |
| | |
| | | private static final Logger logger = Logger.getLogger(ListHandler.class.getName()); |
| | | |
| | | public static final String ALLE_TITEL = "alle"; |
| | | |
| | | |
| | | private String conf; |
| | | |
| | | public ListHandler(String conf) { |
| | | this.conf = conf; |
| | | } |
| | | |
| | | @Override |
| | | protected String get(HttpExchange e) { |
| | | String path = e.getRequestURI().toString(); |
| | | String[] elems = path.split(Server.SLASH); |
| | | String plname = elems[elems.length - 1]; |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | FileStorage fs = new FileStorage(conf); |
| | | String json = fs.readJson(FileStorage.ST_ABSPIELLISTE, plname); |
| | | return embedInCustomType(json, FileStorage.ST_ABSPIELLISTE); |
| | | } |
| | |
| | | } |
| | | |
| | | private String addTitel(HttpExchange e, String plname) throws IOException { |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | FileStorage fs = new FileStorage(conf); |
| | | Entity entity = fs.read(FileStorage.ST_ABSPIELLISTE, plname); |
| | | String response = "Titel konnte nicht hinzugefuegt werden."; |
| | | if(entity instanceof Abspielliste) { |
| | |
| | | String path = e.getRequestURI().toString(); |
| | | String[] elems = path.split(Server.SLASH); |
| | | String listName = elems[elems.length - 2]; |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | FileStorage fs = new FileStorage(conf); |
| | | Entity entity = fs.read(Abspielliste.class.getSimpleName(), listName); |
| | | if(entity instanceof Abspielliste) { |
| | | Abspielliste liste = (Abspielliste) entity; |
| | |
| | | public static final String DEFAULT_HOST = "http://localhost:9090"; |
| | | |
| | | private final Map spielt = new HashMap(); |
| | | |
| | | private String conf; |
| | | |
| | | public MediaSteuerung(String conf) { |
| | | this.conf = conf; |
| | | } |
| | | |
| | | @Override |
| | | protected String get(HttpExchange e) { |
| | | String response; |
| | | String path = e.getRequestURI().toString(); |
| | | String[] elems = path.split(Server.SLASH); |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | FileStorage fs = new FileStorage(conf); |
| | | logger.fine(path); |
| | | |
| | | // Faustregel: Anzahl Elemente eines URL plus 1 ist die Anzahl der Elemente des |
| | |
| | | private String urlAbspielen(HttpExchange e, String abspielerKmd) throws IOException { |
| | | String path = e.getRequestURI().toString(); |
| | | String[] elems = path.split(Server.SLASH); |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | FileStorage fs = new FileStorage(conf); |
| | | if(elems[6].equalsIgnoreCase("titel")) { |
| | | String titelJson = bodyLesen(e); |
| | | Gson gson = new Gson(); |
| | |
| | | Entity entity = fs.read(FileStorage.ST_ABSPIELER, elems[4]); |
| | | if (entity instanceof Abspieler) { |
| | | Abspieler abspieler = (Abspieler) entity; |
| | | String server = getEinstellung(fs, App.getRs(App.RB_HOST), DEFAULT_HOST); |
| | | String server = getEinstellung(fs, getResString(App.RB_HOST), DEFAULT_HOST); |
| | | String signal = abspielKommando(fs, abspieler, server, titelUrl, abspielerKmd).toString(); |
| | | abspielerKommandoSenden(signal); |
| | | return signal + "gesendet."; |
| | |
| | | vorgang.setTitelNr(titelNr); |
| | | spielt.put(abspieler.getName(), vorgang); |
| | | |
| | | String server = getEinstellung(s, App.getRs(App.RB_HOST), DEFAULT_HOST); |
| | | String server = getEinstellung(s, getResString(App.RB_HOST), DEFAULT_HOST); |
| | | |
| | | /* |
| | | |
| | |
| | | //kmd.append(PL_CMD_PLAY); |
| | | kmd.append(abspielKmd); |
| | | // Parameter fuer den Abspieler holen |
| | | kmd.append(getEinstellung(s, App.getRs(App.RB_PLAYERPARAMS), PL_DEFAULT_PARAMS)); |
| | | kmd.append(getEinstellung(s, getResString(App.RB_PLAYERPARAMS), PL_DEFAULT_PARAMS)); |
| | | kmd.append(server); |
| | | kmd.append(titelUrl); |
| | | |
| | |
| | | import de.uhilger.tango.App; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.ResourceBundle; |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | import java.util.logging.Logger; |
| | |
| | | public static final String RB_SERVER_STOPPED = "serverStopped"; |
| | | public static final String RB_MEDIAZ_END = "mediazEnd"; |
| | | |
| | | private ResourceBundle rb; |
| | | |
| | | /** |
| | | * Den Server geordnet herunterfahren und |
| | | * dann die Anwendung beenden. |
| | |
| | | @Override |
| | | public void handle(HttpExchange e) throws IOException { |
| | | Logger.getLogger(StopServerHandler.class.getName()).info(e.getRequestURI().toString()); |
| | | String response = App.getRs(RB_SERVER_STOPPED); |
| | | String response = getResString(RB_SERVER_STOPPED); |
| | | e.sendResponseHeaders(200, response.length()); |
| | | OutputStream os = e.getResponseBody(); |
| | | os.write(response.getBytes()); |
| | | os.flush(); |
| | | os.close(); |
| | | logger.info(App.getRs(RB_STOPPING_SERVER)); |
| | | logger.info(getResString(RB_STOPPING_SERVER)); |
| | | e.getHttpContext().getServer().stop(1); |
| | | Timer timer = new Timer(); |
| | | timer.schedule(new AppStopper(), 2000); |
| | |
| | | |
| | | @Override |
| | | public void run() { |
| | | logger.info(App.getRs(RB_MEDIAZ_END)); |
| | | App.stop(); |
| | | logger.info(getResString(RB_MEDIAZ_END)); |
| | | System.exit(0); |
| | | } |
| | | } |
| | | |
| | | protected String getResString(String key) { |
| | | if(rb == null) { |
| | | rb = ResourceBundle.getBundle(App.RB_NAME); |
| | | } |
| | | return rb.getString(key); |
| | | } |
| | | } |
| | |
| | | package de.uhilger.tango.api; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.sun.net.httpserver.HttpContext; |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import de.uhilger.tango.App; |
| | | import static de.uhilger.tango.App.RB_EP_LISTE; |
| | |
| | | import static de.uhilger.tango.store.FileStorage.ST_ABLAGEORT; |
| | | import static de.uhilger.tango.store.FileStorage.ST_GERAET; |
| | | import de.uhilger.tango.store.Storage; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.URI; |
| | | import java.util.Iterator; |
| | |
| | | public class StorageHandler extends AbstractHandler { |
| | | |
| | | private static final Logger logger = Logger.getLogger(StorageHandler.class.getName()); |
| | | |
| | | private String conf; |
| | | |
| | | public StorageHandler(String conf) { |
| | | this.conf = conf; |
| | | } |
| | | |
| | | @Override |
| | | protected String put(HttpExchange e) throws IOException { |
| | |
| | | String[] elems = path.split(Server.SLASH); |
| | | String type = elems[elems.length - 2]; |
| | | String elemName = elems[elems.length - 1]; // alter Name, wenn Aenderung |
| | | if(!elemName.equalsIgnoreCase(App.getRs(RB_EP_LISTE))) { |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | if(!elemName.equalsIgnoreCase(getResString(RB_EP_LISTE))) { |
| | | FileStorage fs = new FileStorage(conf); |
| | | Gson gson = new Gson(); |
| | | logger.log(Level.FINE, "type: {0}, token: {1}", new Object[]{type, fs.typeFromName(type).getType().getTypeName()}); |
| | | Object o = gson.fromJson(bodyLesen(e), fs.typeFromName(type).getType()); |
| | |
| | | Entity aoe = fs.read(type, elemName); |
| | | if(aoe instanceof Ablageort) { |
| | | Ablageort ablageort = (Ablageort) aoe; |
| | | App.getServer().ablageortEntfernen(ablageort.getUrl()); |
| | | //App.getServer().ablageortEntfernen(ablageort.getUrl()); |
| | | e.getHttpContext().getServer().removeContext(ablageort.getUrl()); |
| | | } |
| | | } |
| | | fs.write(entity, true); |
| | |
| | | if(type.equalsIgnoreCase(FileStorage.ST_ABLAGEORT)) { |
| | | if(entity instanceof Ablageort) { |
| | | Ablageort ablageort = (Ablageort) entity; |
| | | App.getServer().ablageortHinzufuegen(ablageort); |
| | | //App.getServer().ablageortHinzufuegen(ablageort); |
| | | ablageortHinzufuegen(e, ablageort); |
| | | } |
| | | } |
| | | } else { // Neu |
| | |
| | | if(type.equalsIgnoreCase(FileStorage.ST_ABLAGEORT)) { |
| | | if(entity instanceof Ablageort) { |
| | | Ablageort ablageort = (Ablageort) entity; |
| | | App.getServer().ablageortHinzufuegen(ablageort); |
| | | //App.getServer().ablageortHinzufuegen(ablageort); |
| | | ablageortHinzufuegen(e, ablageort); |
| | | } |
| | | } |
| | | } |
| | |
| | | return "Ungueltiges Objekt im Body."; |
| | | } |
| | | } else { |
| | | return "Ungueltiger Elementname: " + App.getRs(RB_EP_LISTE); |
| | | return "Ungueltiger Elementname: " + getResString(RB_EP_LISTE); |
| | | } |
| | | } |
| | | |
| | | private void ablageortHinzufuegen(HttpExchange e, Ablageort ort) { |
| | | HttpContext c = e.getHttpContext(); |
| | | String ctx = c.getPath(); |
| | | c.getServer().createContext(ctx + ort.getUrl(), |
| | | new ListFileHandler(new File(ort.getOrt()).getAbsolutePath(), conf)); |
| | | } |
| | | |
| | | private boolean loeschen(HttpExchange e) { |
| | |
| | | String[] elems = path.split(Server.SLASH); |
| | | String type = elems[elems.length - 2]; |
| | | String elemName = elems[elems.length - 1]; |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | FileStorage fs = new FileStorage(conf); |
| | | if(type.equalsIgnoreCase(FileStorage.ST_ABLAGEORT)) { |
| | | // im laufenden Server den Context entfernen |
| | | Entity entity = fs.read(type, elemName); |
| | | if(entity instanceof Ablageort) { |
| | | Ablageort ablageort = (Ablageort) entity; |
| | | App.getServer().ablageortEntfernen(ablageort.getUrl()); |
| | | //App.getServer().ablageortEntfernen(ablageort.getUrl()); |
| | | e.getHttpContext().getServer().removeContext(ablageort.getUrl()); |
| | | } |
| | | } |
| | | return fs.delete(type, elemName); |
| | |
| | | private String lesen(HttpExchange e) throws IOException, InterruptedException { |
| | | String path = e.getRequestURI().toString(); |
| | | String[] elems = path.split(Server.SLASH); |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | FileStorage fs = new FileStorage(conf); |
| | | if(path.endsWith(Server.SLASH)) { |
| | | List list = null; |
| | | if(elems[elems.length - 1].equalsIgnoreCase(App.getRs(RB_EP_LISTE_ALLES))) { |
| | | if(elems[elems.length - 1].equalsIgnoreCase(getResString(RB_EP_LISTE_ALLES))) { |
| | | String type = elems[elems.length - 2]; |
| | | logger.fine(type); |
| | | if(type.equalsIgnoreCase(ST_GERAET)) { |
| | |
| | | Object o = gson.fromJson(bodyLesen(e), fs.typeFromName(type).getType()); |
| | | return gson.toJson(list); |
| | | } |
| | | } else if(elems[elems.length - 1].equalsIgnoreCase(App.getRs(RB_EP_LISTE))) { |
| | | } else if(elems[elems.length - 1].equalsIgnoreCase(getResString(RB_EP_LISTE))) { |
| | | String type = elems[elems.length - 2]; |
| | | logger.fine(type); |
| | | list = fs.list(type); |