commit | author | age
|
0c8d27
|
1 |
package de.uhilger.avdirektor.handler; |
U |
2 |
|
|
3 |
import com.sun.net.httpserver.HttpExchange; |
|
4 |
import com.sun.net.httpserver.HttpHandler; |
|
5 |
import java.io.IOException; |
|
6 |
import java.io.OutputStream; |
|
7 |
import java.util.Map; |
|
8 |
import java.util.logging.Level; |
|
9 |
import java.util.logging.Logger; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author ulrich |
|
14 |
*/ |
cc2a32
|
15 |
public class CmdHandler extends OMXPlayer implements HttpHandler { |
0c8d27
|
16 |
|
U |
17 |
private static final Logger logger = Logger.getLogger(CmdHandler.class.getName()); |
|
18 |
|
63b711
|
19 |
protected String cmd; |
U |
20 |
protected Map map; |
0c8d27
|
21 |
|
cc2a32
|
22 |
public CmdHandler(String cmd) { |
U |
23 |
this.cmd = cmd; |
63b711
|
24 |
} |
U |
25 |
|
|
26 |
@Override |
|
27 |
public void handle(HttpExchange t) throws IOException { |
|
28 |
logger.log(Level.FINE, "RequestURI: {0}", t.getRequestURI().toString()); |
|
29 |
StringBuilder params = buildParams(t); |
|
30 |
String antwort = process(t, params.toString()); |
|
31 |
sendResponse(t, cmd, antwort); |
|
32 |
} |
|
33 |
|
|
34 |
protected String process(HttpExchange t, String params) { |
|
35 |
String antwort = this.kommando(cmd); |
|
36 |
logger.log(Level.FINE, antwort); |
|
37 |
return antwort; |
|
38 |
} |
|
39 |
|
|
40 |
protected StringBuilder buildParams(HttpExchange t) { |
|
41 |
map = getQueryMap(t); |
|
42 |
StringBuilder params = new StringBuilder(); |
|
43 |
return params; |
|
44 |
} |
|
45 |
|
|
46 |
protected void sendResponse(HttpExchange t, String cmd, String antwort) throws IOException { |
|
47 |
String response = getResponseString(map, cmd, antwort); |
|
48 |
t.sendResponseHeaders(200, response.length()); |
|
49 |
OutputStream os = t.getResponseBody(); |
|
50 |
os.write(response.getBytes()); |
|
51 |
os.close(); |
cc2a32
|
52 |
} |
U |
53 |
|
|
54 |
public void setCmd(String cmd) { |
|
55 |
this.cmd = cmd; |
|
56 |
} |
|
57 |
|
|
58 |
public String getCmd(String cmd) { |
|
59 |
return this.cmd; |
|
60 |
} |
0c8d27
|
61 |
|
U |
62 |
} |