protected HttpServer createHttpServer() throws IOException { HttpServer server = new HttpServer(); SocketListener listener = new SocketListener(); listener.setPort(SysConfig.getHttpPortAsInt()); server.addListener(listener); return server; }
private static void startJettytHttpServer() throws MultiException { // Set up Jetty HTTP server with our servlet; this accidental // complexity is annoying for a demo app, but much less so than the // steps in deploying this in to Tomcat or whatever HttpServer webServer = new HttpServer(); SocketListener listener = new SocketListener(); listener.setPort(8080); webServer.addListener(listener); ServletHandler sh = new ServletHandler(); sh.addServlet("service1", "/service1", ServerImpl.class.getName()); HttpContext context = new HttpContext(webServer, "/"); context.addHandler(sh); webServer.start(); }
public void stopHttpServer(HttpServer httpServer) { try { httpServer.stop(true); } catch (InterruptedException ie) { SysLog.logThrowable(ie); } SysLog.logInfo("http server was stopped"); }
public void startHttpServer(HttpServer httpServer) throws Exception { httpServer.start(); SysLog.logInfo("http server was started"); }
protected void configureHttpServer(HttpServer server) { // Favicon hack HttpContext faviconContext = new HttpContext(); faviconContext.setContextPath("/favicon.ico"); server.addContext(faviconContext); ResourceHandler faviconHandler = new ResourceHandler(); faviconContext.setResourceBase(SysConfig.getStaticDir().getRootPath()); faviconContext.addHandler(faviconHandler); faviconContext.addHandler(new NotFoundHandler()); // robots.txt hack HttpContext robotsContext = new HttpContext(); robotsContext.setContextPath("/robots.txt"); server.addContext(robotsContext); ResourceHandler robotsHandler = new ResourceHandler(); robotsContext.setResourceBase(SysConfig.getStaticDir().getRootPath()); robotsContext.addHandler(robotsHandler); robotsContext.addHandler(new NotFoundHandler()); // Dynamic content HttpContext servletContext = new HttpContext(); servletContext.setContextPath("/"); server.addContext(servletContext); ServletHandler servlets = new ServletHandler(); servletContext.addHandler(servlets); servlets.addServlet("/*", "org.wahlzeit.main.MainServlet"); servletContext.addHandler(new NotFoundHandler()); // Photos content HttpContext photosContext = new HttpContext(); photosContext.setContextPath(SysConfig.getPhotosDirAsString()); server.addContext(photosContext); ResourceHandler photosHandler = new ResourceHandler(); photosContext.setResourceBase(SysConfig.getPhotosDirAsString()); photosContext.addHandler(photosHandler); photosContext.addHandler(new NotFoundHandler()); // Static content HttpContext staticContext = new HttpContext(); staticContext.setContextPath(SysConfig.getStaticDir().getRootPath()); server.addContext(staticContext); ResourceHandler staticHandler = new ResourceHandler(); staticContext.setResourceBase(SysConfig.getStaticDir().getRootPath()); staticContext.addHandler(staticHandler); staticContext.addHandler(new NotFoundHandler()); }