Java Code Examples for org.mortbay.jetty.handler.ResourceHandler#setResourceBase()
The following examples show how to use
org.mortbay.jetty.handler.ResourceHandler#setResourceBase() .
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: Main.java From blog-codes with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Server server = new Server(PORT); // Static file handler Context fileContext = new Context(server, "/mxgraph", Context.SESSIONS); ResourceHandler fileHandler = new ResourceHandler(); fileHandler.setResourceBase("."); fileContext.setHandler(fileHandler); // Servlets Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(new ServletHolder(new Roundtrip()), "/Roundtrip"); context.addServlet(new ServletHolder(new ServerView()), "/ServerView"); context.addServlet(new ServletHolder(new ExportServlet()), "/Export"); context.addServlet(new ServletHolder(new EchoServlet()), "/Echo"); context.addServlet(new ServletHolder(new Deploy()), "/Deploy"); context.addServlet(new ServletHolder(new Link()), "/Link"); context.addServlet(new ServletHolder(new EmbedImage()), "/EmbedImage"); context.addServlet(new ServletHolder(new Backend()), "/Backend"); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { new RedirectHandler(), fileContext, context, new DefaultHandler() }); server.setHandler(handlers); System.out.println("Go to http://localhost:" + PORT + "/"); server.start(); server.join(); }
Example 2
Source File: LocalServerWebDriverContainerTest.java From testcontainers-java with MIT License | 5 votes |
@Before public void setupLocalServer() throws Exception { // Set up a local Jetty HTTP server Server server = new Server(); server.addConnector(new SocketConnector()); ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setResourceBase("src/test/resources/server"); server.addHandler(resourceHandler); server.start(); // The server will have a random port assigned, so capture that localPort = server.getConnectors()[0].getLocalPort(); }
Example 3
Source File: AbstractServerMojo.java From opoopress with Apache License 2.0 | 5 votes |
protected Server createJettyServer(Site site){ Server server = new Server(); //FIXME server.setStopAtShutdown(true); Connector defaultConnector = createConnector(null, port); server.setConnectors( new Connector[] { defaultConnector } ); String root = site.getRoot(); String resourceBase = site.getDestination().getPath(); getLog().info("Server resource base: " + resourceBase); if("".equals(root)){ ResourceHandler resourceHandler = new ResourceHandler(); //resourceHandler.setDirectoriesListed(true); resourceHandler.setWelcomeFiles(new String[]{"index.html"}); resourceHandler.setResourceBase(resourceBase/*site.getDestination().getPath()*/); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler()}); server.setHandler(handlers); //server.setHandlers(new Handler[]{handlers, logHandler}); //getLog().info( "Startisng preview server on http://localhost:" + port + "/" ); } else { getLog().info("Using " + ContextHandler.class.getName()); ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath(root); contextHandler.setHandler(new ResourceHandler()); contextHandler.setResourceBase(resourceBase/*site.getDestination().getPath()*/); //server.setHandler(contextHandler); server.setHandlers(new Handler[]{contextHandler, new DefaultHandler()}); //server.setHandlers(new Handler[]{contextHandler, logHandler}); //log.info( "Starting preview server on http://localhost:" + port + root ); } return server; }
Example 4
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 5
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(); }