/*
|
* 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();
|
|
}
|
|
}
|