commit | author | age
|
d86ba2
|
1 |
/* |
U |
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package de.uhilger.mediaz.api; |
|
7 |
|
|
8 |
import com.sun.net.httpserver.HttpExchange; |
|
9 |
import com.sun.net.httpserver.HttpHandler; |
081606
|
10 |
import de.uhilger.mediaz.App; |
U |
11 |
import de.uhilger.mediaz.store.FileStorage; |
cfa858
|
12 |
import de.uhilger.mediaz.entity.Ablageort; |
d86ba2
|
13 |
import java.io.File; |
U |
14 |
import java.io.IOException; |
|
15 |
import java.io.OutputStream; |
|
16 |
import java.util.logging.Level; |
|
17 |
import java.util.logging.Logger; |
081606
|
18 |
import de.uhilger.mediaz.entity.Entity; |
d86ba2
|
19 |
|
U |
20 |
/** |
|
21 |
* |
|
22 |
* @author ulrich |
|
23 |
*/ |
|
24 |
public class StoreTestHandler implements HttpHandler { |
|
25 |
|
|
26 |
private static final Logger logger = Logger.getLogger(StoreTestHandler.class.getName()); |
|
27 |
|
|
28 |
|
|
29 |
@Override |
|
30 |
public void handle(HttpExchange e) throws IOException { |
cfa858
|
31 |
Ablageort ort = new Ablageort(); |
U |
32 |
ort.setName("Katalog"); |
|
33 |
ort.setOrt("/home/ulrich/Videos"); |
b379f5
|
34 |
ort.setUrl("/media/test"); |
081606
|
35 |
FileStorage store = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
cfa858
|
36 |
File file = store.writeToFile(ort); |
d86ba2
|
37 |
try { |
5f70da
|
38 |
Entity elem = store.entityFromFile(file); |
d86ba2
|
39 |
logger.log(Level.INFO, "Typ: {0}, Name: {1}", |
U |
40 |
new Object[]{elem.getClass().getSimpleName(), elem.getName()}); |
|
41 |
} catch (ClassNotFoundException ex) { |
|
42 |
logger.log(Level.SEVERE, null, ex); |
|
43 |
} |
|
44 |
|
|
45 |
String response = "OK"; |
|
46 |
e.sendResponseHeaders(200, response.length()); |
|
47 |
OutputStream os = e.getResponseBody(); |
|
48 |
os.write(response.getBytes()); |
|
49 |
os.close(); |
|
50 |
|
|
51 |
} |
|
52 |
|
|
53 |
} |