|
1 |
| package net.sf.crispy.impl.http; |
|
2 |
| |
|
3 |
| import net.sf.crispy.impl.MiniServer; |
|
4 |
| import net.sf.crispy.impl.ServiceManager; |
|
5 |
| |
|
6 |
| public class MiniHttpServer implements MiniServer { |
|
7 |
| |
|
8 |
| public static final int DEFAULT_PORT = 8111; |
|
9 |
| |
|
10 |
| private static net.sf.crispy.impl.MiniHttpServer server = null; |
|
11 |
| private String servletName = HttpServlet.class.getName(); |
|
12 |
| private String servletContext = "/httpserializer/*"; |
|
13 |
| |
|
14 |
3
| public MiniHttpServer() {
|
|
15 |
3
| this(DEFAULT_PORT);
|
|
16 |
| } |
|
17 |
| |
|
18 |
3
| public MiniHttpServer(int pvPort) {
|
|
19 |
3
| try {
|
|
20 |
3
| server = new net.sf.crispy.impl.MiniHttpServer(pvPort);
|
|
21 |
3
| server.setContext("/crispy");
|
|
22 |
| } catch (Exception e) { |
|
23 |
| if (ServiceManager.DEBUG_MODE_ON) { |
|
24 |
| e.printStackTrace(); |
|
25 |
| } |
|
26 |
| } |
|
27 |
| } |
|
28 |
| |
|
29 |
1
| public net.sf.crispy.impl.MiniHttpServer getInternalHttpServer() {
|
|
30 |
1
| return server;
|
|
31 |
| } |
|
32 |
| |
|
33 |
1
| public void setServletName(String pvServletName) { servletName = pvServletName; }
|
|
34 |
5
| public String getServletName() { return servletName; }
|
|
35 |
| |
|
36 |
1
| public void setServletContext(String pvServletContext) { servletContext = pvServletContext; }
|
|
37 |
5
| public String getServletContext() {
|
|
38 |
5
| if (servletContext.endsWith("*") == false) {
|
|
39 |
1
| servletContext = servletContext + "*";
|
|
40 |
| } |
|
41 |
5
| return servletContext;
|
|
42 |
| } |
|
43 |
| |
|
44 |
4
| public void addService (String pvServiceInterface, String pvServiceObject) {
|
|
45 |
4
| server.addServlet(getServletContext(), getServletName(), pvServiceInterface, pvServiceObject);
|
|
46 |
| } |
|
47 |
| |
|
48 |
1
| public void start() {
|
|
49 |
1
| try {
|
|
50 |
1
| server.start();
|
|
51 |
| } catch (Exception e) { |
|
52 |
| if (ServiceManager.DEBUG_MODE_ON) { |
|
53 |
| e.printStackTrace(); |
|
54 |
| } |
|
55 |
| } |
|
56 |
| } |
|
57 |
| |
|
58 |
| public void stop() { |
|
59 |
| try { |
|
60 |
| server.stop(); |
|
61 |
| } catch (Exception e) { |
|
62 |
| if (ServiceManager.DEBUG_MODE_ON) { |
|
63 |
| e.printStackTrace(); |
|
64 |
| } |
|
65 |
| } |
|
66 |
| } |
|
67 |
| |
|
68 |
| } |