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 public MiniHttpServer() { 15 this(DEFAULT_PORT); 16 } 17 18 public MiniHttpServer(int pvPort) { 19 try { 20 server = new net.sf.crispy.impl.MiniHttpServer(pvPort); 21 server.setContext("/crispy"); 22 } catch (Exception e) { 23 if (ServiceManager.DEBUG_MODE_ON) { 24 e.printStackTrace(); 25 } 26 } 27 } 28 29 public net.sf.crispy.impl.MiniHttpServer getInternalHttpServer() { 30 return server; 31 } 32 33 public void setServletName(String pvServletName) { servletName = pvServletName; } 34 public String getServletName() { return servletName; } 35 36 public void setServletContext(String pvServletContext) { servletContext = pvServletContext; } 37 public String getServletContext() { 38 if (servletContext.endsWith("*") == false) { 39 servletContext = servletContext + "*"; 40 } 41 return servletContext; 42 } 43 44 public void addService (String pvServiceInterface, String pvServiceObject) { 45 server.addServlet(getServletContext(), getServletName(), pvServiceInterface, pvServiceObject); 46 } 47 48 public void start() { 49 try { 50 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 }