commit | author | age
|
229976
|
1 |
package de.uhilger.calypso.handler; |
15ed25
|
2 |
|
U |
3 |
import com.sun.net.httpserver.HttpExchange; |
229976
|
4 |
import de.uhilger.calypso.OMXLogLeser; |
15ed25
|
5 |
import java.io.File; |
94c45c
|
6 |
import java.io.FileNotFoundException; |
15ed25
|
7 |
import java.io.IOException; |
94c45c
|
8 |
import java.io.OutputStream; |
U |
9 |
import java.text.ParseException; |
15ed25
|
10 |
import java.util.logging.Level; |
U |
11 |
import java.util.logging.Logger; |
|
12 |
|
|
13 |
/** |
|
14 |
* |
|
15 |
* @author ulrich |
|
16 |
*/ |
|
17 |
public class LogHandler extends AbstractHandler { |
|
18 |
|
|
19 |
private static final Logger logger = Logger.getLogger(LogHandler.class.getName()); |
94c45c
|
20 |
|
U |
21 |
@Override |
|
22 |
public void handle(HttpExchange t) throws IOException { |
|
23 |
logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); |
|
24 |
StringBuilder params = buildParams(t); |
|
25 |
String antwort = process(t, params.toString()); |
|
26 |
sendResponse(t, cmd, antwort); |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
protected void sendResponse(HttpExchange t, String cmd, String antwort) throws IOException { |
|
31 |
t.sendResponseHeaders(200, antwort.length()); |
|
32 |
OutputStream os = t.getResponseBody(); |
|
33 |
os.write(antwort.getBytes()); |
|
34 |
os.close(); |
|
35 |
} |
|
36 |
|
15ed25
|
37 |
|
U |
38 |
@Override |
|
39 |
protected String process(HttpExchange t, String params) { |
2dd7a5
|
40 |
/* |
15ed25
|
41 |
OMXLogLeser leser = new OMXLogLeser(); |
U |
42 |
String lines = "Log nicht lesbar."; |
|
43 |
try { |
94c45c
|
44 |
logger.info(new File(".").getAbsolutePath()); |
U |
45 |
lines = leser.lesen(new File("omxplayer.log")); |
15ed25
|
46 |
} catch (IOException ex) { |
U |
47 |
Logger.getLogger(LogHandler.class.getName()).log(Level.SEVERE, null, ex); |
94c45c
|
48 |
} catch (ParseException ex) { |
U |
49 |
Logger.getLogger(LogHandler.class.getName()).log(Level.SEVERE, null, ex); |
15ed25
|
50 |
} |
2dd7a5
|
51 |
*/ |
U |
52 |
return ""; |
15ed25
|
53 |
} |
U |
54 |
|
|
55 |
} |