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; |
|
11 |
import de.uhilger.mediaz.entity.Ablage; |
|
12 |
import de.uhilger.mediaz.entity.ConfigurationElement; |
|
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 { |
|
30 |
Ablage ablage = new Ablage(); |
|
31 |
ablage.setName("Katalog"); |
|
32 |
ablage.setOrt("/home/ulrich/Videos"); |
|
33 |
Store store = new Store(); |
|
34 |
File file = store.writeToFile(ablage); |
|
35 |
try { |
|
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 |
} |