Persoenliche Mediazentrale
ulrich
2021-04-05 5f70da71c8e71990715dcb4be5cc433284abdede
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * 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.mediaz.api;
 
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import de.uhilger.mediaz.App;
import de.uhilger.mediaz.store.FileStorage;
import de.uhilger.mediaz.entity.Ablageort;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import de.uhilger.mediaz.entity.Entity;
 
/**
 *
 * @author ulrich
 */
public class StoreTestHandler implements HttpHandler {
  
  private static final Logger logger = Logger.getLogger(StoreTestHandler.class.getName());
  
 
  @Override
  public void handle(HttpExchange e) throws IOException {
    Ablageort ort = new Ablageort();
    ort.setName("Katalog");
    ort.setOrt("/home/ulrich/Videos");
    ort.setUrl("/media/test");
    FileStorage store = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
    File file = store.writeToFile(ort);
    try {
      Entity elem = store.entityFromFile(file);
      logger.log(Level.INFO, "Typ: {0}, Name: {1}", 
              new Object[]{elem.getClass().getSimpleName(), elem.getName()});
    } catch (ClassNotFoundException ex) {
      logger.log(Level.SEVERE, null, ex);
    }
    
    String response = "OK";
    e.sendResponseHeaders(200, response.length());
    OutputStream os = e.getResponseBody();
    os.write(response.getBytes());
    os.close();        
    
  }
  
}