| | |
| | | |
| | | private static final Logger logger = Logger.getLogger(Server.class.getName()); |
| | | |
| | | public static final String STR_SLASH = "/"; |
| | | |
| | | |
| | | private int port; |
| | | |
| | | private String ctxName; |
| | | private String ctx; |
| | | |
| | | /** |
| | | * Ein neues Objekt der Kalsse Server erzeugen |
| | | * @param port der Port, über den dieser Server erreichbar sein soll |
| | | */ |
| | | public Server(int port) { |
| | | this.port = port; |
| | | } |
| | |
| | | this.port = port; |
| | | } |
| | | |
| | | /** |
| | | * Den Namen des Kontexts angeben, über den dieser Server |
| | | * erreichbar sein soll |
| | | * @param ctxName |
| | | */ |
| | | public void setContextName(String ctxName) { |
| | | this.ctxName = ctxName; |
| | | if(!ctxName.startsWith(STR_SLASH)) { |
| | | this.ctx = STR_SLASH + ctxName; |
| | | } else { |
| | | this.ctx = ctxName; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | logger.info("Server starting on port " + port); |
| | | |
| | | HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
| | | server.createContext(ctxName + "/av", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); |
| | | server.createContext(ctxName + "/server/stop", new StopServerHandler()); |
| | | server.createContext(ctx + "/av", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); |
| | | server.createContext(ctx + "/server/stop", new StopServerHandler()); |
| | | server.setExecutor(Executors.newFixedThreadPool(20)); |
| | | server.start(); |
| | | } |