commit | author | age
|
15ed25
|
1 |
package de.uhilger.avdirektor.handler; |
U |
2 |
|
|
3 |
import com.sun.net.httpserver.HttpExchange; |
|
4 |
import de.uhilger.avdirektor.OMXLogLeser; |
|
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) { |
|
40 |
OMXLogLeser leser = new OMXLogLeser(); |
|
41 |
String lines = "Log nicht lesbar."; |
|
42 |
try { |
94c45c
|
43 |
logger.info(new File(".").getAbsolutePath()); |
U |
44 |
lines = leser.lesen(new File("omxplayer.log")); |
15ed25
|
45 |
} catch (IOException ex) { |
U |
46 |
Logger.getLogger(LogHandler.class.getName()).log(Level.SEVERE, null, ex); |
94c45c
|
47 |
} catch (ParseException ex) { |
U |
48 |
Logger.getLogger(LogHandler.class.getName()).log(Level.SEVERE, null, ex); |
15ed25
|
49 |
} |
U |
50 |
return lines; |
|
51 |
} |
|
52 |
|
|
53 |
} |