| | |
| | | import de.uhilger.mediaz.Server; |
| | | import de.uhilger.mediaz.store.FileStorage; |
| | | import de.uhilger.mediaz.entity.Ablageort; |
| | | import de.uhilger.mediaz.entity.Entity; |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | |
| | | String[] elems = path.split(App.getRs(Server.RB_SLASH)); |
| | | String type = ""; |
| | | String elemName = ""; |
| | | String body = ""; |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | switch(method) { |
| | | case HTTP_GET: |
| | |
| | | break; |
| | | |
| | | case HTTP_POST: |
| | | type = elems[elems.length - 1]; |
| | | elemName = bodyLesen(e); |
| | | if(type.equalsIgnoreCase("Ablageort")) { |
| | | Gson gson = new Gson(); |
| | | Ablageort ort = gson.fromJson(elemName, Ablageort.class); |
| | | elemName = ort.getName(); |
| | | Object o = fs.write(ort); |
| | | if(o instanceof File) { |
| | | File file = (File) o; |
| | | logger.log(Level.INFO, "Datei {0} geschrieben.", file.getAbsolutePath()); |
| | | } |
| | | } |
| | | neu(e); |
| | | break; |
| | | |
| | | case HTTP_DELETE: |
| | |
| | | OutputStream os = e.getResponseBody(); |
| | | os.write(response.getBytes()); |
| | | os.close(); |
| | | } |
| | | |
| | | private void neu(HttpExchange e) throws IOException { |
| | | String path = e.getRequestURI().toString(); |
| | | String[] elems = path.split(App.getRs(Server.RB_SLASH)); |
| | | String type = elems[elems.length - 1]; |
| | | String body = bodyLesen(e); |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | Gson gson = new Gson(); |
| | | logger.log(Level.INFO, "type: {0}", type); |
| | | Object o = gson.fromJson(body, fs.typeFromName(type).getType()); |
| | | if(o instanceof Entity) { |
| | | Object antwortObjekt = fs.write((Entity) o); |
| | | if(antwortObjekt instanceof File) { |
| | | File file = (File) antwortObjekt; |
| | | logger.log(Level.INFO, "Datei {0} geschrieben.", file.getAbsolutePath()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void aendern() { |
| | | |
| | | } |
| | | |
| | | private void loeschen() { |
| | | |
| | | } |
| | | |
| | | private Entity lesen() { |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | //String json = data.substring(data.indexOf("{")); |
| | | // {"name":"test1","ort":"test2","url":"test3"} |
| | | String json = sb.toString(); |
| | | logger.info("json: " + json); |
| | | logger.log(Level.INFO, "json: {0}", json); |
| | | return json; |
| | | } |
| | | } |