Java Code Examples for org.mortbay.jetty.handler.ResourceHandler#handle()
The following examples show how to use
org.mortbay.jetty.handler.ResourceHandler#handle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SLSWebApp.java From hadoop with Apache License 2.0 | 4 votes |
public void start() throws Exception { // static files final ResourceHandler staticHandler = new ResourceHandler(); staticHandler.setResourceBase("html"); Handler handler = new AbstractHandler() { @Override public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) { try{ // timeunit int timeunit = 1000; // second, divide millionsecond / 1000 String timeunitLabel = "second"; if (request.getParameter("u")!= null && request.getParameter("u").equalsIgnoreCase("m")) { timeunit = 1000 * 60; timeunitLabel = "minute"; } // http request if (target.equals("/")) { printPageIndex(request, response); } else if (target.equals("/simulate")) { printPageSimulate(request, response, timeunit, timeunitLabel); } else if (target.equals("/track")) { printPageTrack(request, response, timeunit, timeunitLabel); } else // js/css request if (target.startsWith("/js") || target.startsWith("/css")) { response.setCharacterEncoding("utf-8"); staticHandler.handle(target, request, response, dispatch); } else // json request if (target.equals("/simulateMetrics")) { printJsonMetrics(request, response); } else if (target.equals("/trackMetrics")) { printJsonTrack(request, response); } } catch (Exception e) { e.printStackTrace(); } } }; server = new Server(port); server.setHandler(handler); server.start(); }
Example 2
Source File: SLSWebApp.java From big-c with Apache License 2.0 | 4 votes |
public void start() throws Exception { // static files final ResourceHandler staticHandler = new ResourceHandler(); staticHandler.setResourceBase("html"); Handler handler = new AbstractHandler() { @Override public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) { try{ // timeunit int timeunit = 1000; // second, divide millionsecond / 1000 String timeunitLabel = "second"; if (request.getParameter("u")!= null && request.getParameter("u").equalsIgnoreCase("m")) { timeunit = 1000 * 60; timeunitLabel = "minute"; } // http request if (target.equals("/")) { printPageIndex(request, response); } else if (target.equals("/simulate")) { printPageSimulate(request, response, timeunit, timeunitLabel); } else if (target.equals("/track")) { printPageTrack(request, response, timeunit, timeunitLabel); } else // js/css request if (target.startsWith("/js") || target.startsWith("/css")) { response.setCharacterEncoding("utf-8"); staticHandler.handle(target, request, response, dispatch); } else // json request if (target.equals("/simulateMetrics")) { printJsonMetrics(request, response); } else if (target.equals("/trackMetrics")) { printJsonTrack(request, response); } } catch (Exception e) { e.printStackTrace(); } } }; server = new Server(port); server.setHandler(handler); server.start(); }