|
1 |
| package net.sf.crispy.impl.rest; |
|
2 |
| |
|
3 |
| import net.sf.crispy.impl.MiniHttpServer; |
|
4 |
| import net.sf.crispy.impl.MiniServer; |
|
5 |
| import net.sf.crispy.impl.ServiceManager; |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| public class MiniRestServer implements MiniServer { |
|
14 |
| |
|
15 |
| public static final int DEFAULT_PORT = 8095; |
|
16 |
| |
|
17 |
| private MiniHttpServer server = null; |
|
18 |
| |
|
19 |
2
| public MiniRestServer() {
|
|
20 |
2
| this(DEFAULT_PORT);
|
|
21 |
| } |
|
22 |
| |
|
23 |
3
| public MiniRestServer(int pvPort) {
|
|
24 |
3
| try {
|
|
25 |
3
| server = new MiniHttpServer(pvPort);
|
|
26 |
3
| server.setContext("/crispy");
|
|
27 |
| } catch (Exception e) { |
|
28 |
0
| e.printStackTrace();
|
|
29 |
| } |
|
30 |
| } |
|
31 |
| |
|
32 |
4
| public void addService (String pvServiceInterface, String pvServiceObject) {
|
|
33 |
4
| server.addServlet("/rest/*", RestServlet.class.getName(), pvServiceInterface, pvServiceObject);
|
|
34 |
| } |
|
35 |
| |
|
36 |
3
| public void start() {
|
|
37 |
3
| try {
|
|
38 |
3
| server.start();
|
|
39 |
| } catch (Exception e) { |
|
40 |
| if (ServiceManager.DEBUG_MODE_ON) { |
|
41 |
| e.printStackTrace(); |
|
42 |
| } |
|
43 |
| } |
|
44 |
| } |
|
45 |
| |
|
46 |
| public void stop() { |
|
47 |
| try { |
|
48 |
| server.stop(); |
|
49 |
| } catch (Exception e) { |
|
50 |
| if (ServiceManager.DEBUG_MODE_ON) { |
|
51 |
| e.printStackTrace(); |
|
52 |
| } |
|
53 |
| } |
|
54 |
| } |
|
55 |
| |
|
56 |
| } |