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; |
|
10 |
import de.uhilger.mediaz.conf.Store; |
cfa858
|
11 |
import de.uhilger.mediaz.entity.Ablageort; |
d86ba2
|
12 |
import de.uhilger.mediaz.entity.ConfigurationElement; |
U |
13 |
import java.io.File; |
|
14 |
import java.io.IOException; |
|
15 |
import java.io.OutputStream; |
|
16 |
import java.util.logging.Level; |
|
17 |
import java.util.logging.Logger; |
|
18 |
|
|
19 |
/** |
|
20 |
* |
|
21 |
* @author ulrich |
|
22 |
*/ |
|
23 |
public class StoreTestHandler implements HttpHandler { |
|
24 |
|
|
25 |
private static final Logger logger = Logger.getLogger(StoreTestHandler.class.getName()); |
|
26 |
|
|
27 |
|
|
28 |
@Override |
|
29 |
public void handle(HttpExchange e) throws IOException { |
cfa858
|
30 |
Ablageort ort = new Ablageort(); |
U |
31 |
ort.setName("Katalog"); |
|
32 |
ort.setOrt("/home/ulrich/Videos"); |
d86ba2
|
33 |
Store store = new Store(); |
cfa858
|
34 |
File file = store.writeToFile(ort); |
d86ba2
|
35 |
try { |
U |
36 |
ConfigurationElement elem = store.readFromFile(file); |
|
37 |
logger.log(Level.INFO, "Typ: {0}, Name: {1}", |
|
38 |
new Object[]{elem.getClass().getSimpleName(), elem.getName()}); |
|
39 |
} catch (ClassNotFoundException ex) { |
|
40 |
logger.log(Level.SEVERE, null, ex); |
|
41 |
} |
|
42 |
|
|
43 |
String response = "OK"; |
|
44 |
e.sendResponseHeaders(200, response.length()); |
|
45 |
OutputStream os = e.getResponseBody(); |
|
46 |
os.write(response.getBytes()); |
|
47 |
os.close(); |
|
48 |
|
|
49 |
} |
|
50 |
|
|
51 |
} |