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 * Mini web server implementation with a REST servlets (RestServlet).
9 *
10 * @author Linke
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 public MiniRestServer() {
20 this(DEFAULT_PORT);
21 }
22
23 public MiniRestServer(int pvPort) {
24 try {
25 server = new MiniHttpServer(pvPort);
26 server.setContext("/crispy");
27 } catch (Exception e) {
28 e.printStackTrace();
29 }
30 }
31
32 public void addService (String pvServiceInterface, String pvServiceObject) {
33 server.addServlet("/rest/*", RestServlet.class.getName(), pvServiceInterface, pvServiceObject);
34 }
35
36 public void start() {
37 try {
38 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 }