Java 类org.eclipse.jetty.server.handler.ResourceHandler 实例源码

项目:otus_java_2017_06    文件:Main.java   
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        //page reloaded by the timer
        context.addServlet(TimerServlet.class, "/timer");
        //part of a page reloaded by the timer
        context.addServlet(AjaxTimerServlet.class, "/server-time");
        //long-polling waits till a message
        context.addServlet(new ServletHolder(new MessengerServlet()), "/messenger");
        //web chat
        context.addServlet(WebSocketChatServlet.class, "/chat");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
项目:vk-java-sdk    文件:Application.java   
private static void initServer(Properties properties) throws Exception {
    Integer port = Integer.valueOf(properties.getProperty("server.port"));
    String host = properties.getProperty("server.host");

    Integer clientId = Integer.valueOf(properties.getProperty("client.id"));
    String clientSecret = properties.getProperty("client.secret");

    HandlerCollection handlers = new HandlerCollection();

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setWelcomeFiles(new String[]{"index.html"});
    resourceHandler.setResourceBase(Application.class.getResource("/static").getPath());

    VkApiClient vk = new VkApiClient(new HttpTransportClient());
    handlers.setHandlers(new Handler[]{resourceHandler, new RequestHandler(vk, clientId, clientSecret, host)});

    Server server = new Server(port);
    server.setHandler(handlers);

    server.start();
    server.join();
}
项目:JavaEE    文件:Main.java   
public static void main(String[] args) throws Exception {

        // Create a basic Jetty server object that will listen on port 8080
        Server server = new Server(8080);

        // Create the ResourceHandler. It is the object that will actually
        // handle the request for a given file. It is a Jetty Handler object
        // so it is suitable for chaining with other handlers as you will see
        // in other examples
        ResourceHandler resource_handler = new ResourceHandler();

        // Configure the ResourceHandler. Setting the resource base indicates
        // where the files should be served out of
        resource_handler.setDirectoriesListed(true);
        resource_handler.setWelcomeFiles(new String[]{ "index.html" });
        resource_handler.setResourceBase("src/main/webapp/");

        // Add the ResourceHandler to the server
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
        server.setHandler(handlers);

        // Start server
        server.start();
        server.join();
    }
项目:otus_java_2017_06    文件:Main.java   
private void start() throws Exception {
    resourcesExample();

    ResourceHandler resourceHandler = new ResourceHandler();
    Resource resource = Resource.newClassPathResource(PUBLIC_HTML);
    resourceHandler.setBaseResource(resource);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new TimerServlet()), "/timer");

    Server server = new Server(PORT);
    server.setHandler(new HandlerList(resourceHandler, context));

    server.start();
    server.join();
}
项目:otus_java_2017_06    文件:Main.java   
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
        context.addServlet(AdminServlet.class, "/admin");
        context.addServlet(TimerServlet.class, "/timer");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
项目:otus_java_2017_04    文件:Main.java   
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
        context.addServlet(AdminServlet.class, "/admin");
        context.addServlet(TimerServlet.class, "/timer");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
项目:vk-java-sdk    文件:Application.java   
private static void initServer(Properties properties) throws Exception {
    Integer port = Integer.valueOf(properties.getProperty("server.port"));
    String host = properties.getProperty("server.host");

    Integer clientId = Integer.valueOf(properties.getProperty("client.id"));
    String clientSecret = properties.getProperty("client.secret");

    HandlerCollection handlers = new HandlerCollection();

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setWelcomeFiles(new String[]{"index.html"});
    resourceHandler.setResourceBase(Application.class.getResource("/static").getPath());

    VkApiClient vk = new VkApiClient(new HttpTransportClient());
    handlers.setHandlers(new Handler[]{resourceHandler, new RequestHandler(vk, clientId, clientSecret, host)});

    Server server = new Server(port);
    server.setHandler(handlers);

    server.start();
    server.join();
}
项目:apt-graph    文件:FileServer.java   
/**
 * Start the file server (blocking).
 *
 * @throws Exception If server cannot start
 */
public final void start() throws Exception {
    LOGGER.info("Starting web interface at http://localhost:8000");

    Server server = new Server(8000);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[]{"index.html"});
    resource_handler.setResourceBase("../website");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(
            new Handler[]{
                resource_handler,
                new DefaultHandler()});
    server.setHandler(handlers);

    server.start();
}
项目:little_mitm    文件:PerformanceServer.java   
public void run(int port) throws Exception {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });

    resource_handler.setResourceBase("./performance/site/");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
    System.out.println("Started performance file server at port: " + port);
    server.join();
}
项目:stepic-java-web-service    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    final Handler[] handler = {resource_handler, context};
    handlers.setHandlers(handler);

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
项目:stepic-java-web-service    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    final Handler[] handler = {resource_handler, context};
    handlers.setHandlers(handler);

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
项目:ismv-server    文件:Server.java   
public int run() throws Exception {
    org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(port);
    HandlerList handlerList = new HandlerList();

    ServletContextHandler servletContextHandler = new ServletContextHandler();
    FilterHolder cof = new FilterHolder(new CrossOriginFilter());
    cof.setInitParameter(
            CrossOriginFilter.EXPOSED_HEADERS_PARAM,
            "Date");
    servletContextHandler.addFilter(cof, "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
    servletContextHandler.addServlet(new ServletHolder(new SmoothStreamingServlet(dataDir)), "/*");
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newClassPathResource("supportfiles"));
    handlerList.addHandler(resourceHandler);
    handlerList.addHandler(servletContextHandler);
    server.setHandler(handlerList);

    server.start();
    server.dumpStdErr();
    server.join();
    return 0;
}
项目:LittleProxy    文件:PerformanceServer.java   
public void run(int port) throws Exception {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });

    resource_handler.setResourceBase("./performance/site/");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
    System.out.println("Started performance file server at port: " + port);
    server.join();
}
项目:homework_tester    文件:Main.java   
public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new WebSocketChatServlet()), "/chat");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started!");
    server.join();
}
项目:knives    文件:EmbeddedJetty.java   
public void addResources(String contextPath, String resourcePath, String welcomesCsv) {
    int opt = ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS;
    ServletContextHandler context = new ServletContextHandler(opt);
    {
        context.setContextPath(contextPath);
        context.setCompactPath(true);
        context.setAllowNullPathInfo(true);

        if (Resources.exists(resourcePath)) {
            URL url = Resources.getURL(resourcePath);
            context.setResourceBase(url.toExternalForm());
        }
        ResourceHandler h = new ResourceHandler();
        h.setMinMemoryMappedContentLength(-1);
        h.setEtags(true);
        context.setHandler(h);
        context.setWelcomeFiles(Iterables.toArray(Splitters.notEmpties(",").split(welcomesCsv), String.class));
    }
    this.handlers.addHandler(context);
}
项目:jaxrs    文件:EmbeddedServer.java   
public static void main(String[] args) throws Exception {
    URI baseUri = UriBuilder.fromUri("http://localhost").port(SERVER_PORT)
            .build();
    ResourceConfig config = new ResourceConfig(Calculator.class);
    Server server = JettyHttpContainerFactory.createServer(baseUri, config,
            false);

    ContextHandler contextHandler = new ContextHandler("/rest");
    contextHandler.setHandler(server.getHandler());

    ProtectionDomain protectionDomain = EmbeddedServer.class
            .getProtectionDomain();
    URL location = protectionDomain.getCodeSource().getLocation();

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setWelcomeFiles(new String[] { "index.html" });
    resourceHandler.setResourceBase(location.toExternalForm());
    System.out.println(location.toExternalForm());
    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { resourceHandler,
            contextHandler, new DefaultHandler() });
    server.setHandler(handlerCollection);
    server.start();
    server.join();
}
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:WebSocketServer.java   
public WebSocketServer(int port, String rootDirPath, final MainWindow m, final Statement smt, final java.sql.Connection sqlcon) {
    idCounter = 0;

    connector = new SelectChannelConnector();
    connector.setPort(port);
    addConnector(connector);

    wsHandler = new WebSocketHandler() {
        @Override
        public WebSocket doWebSocketConnect(HttpServletRequest request,
                String protocol) {
            idCounter++;
            System.out.printf("Protocol:%s\n", protocol);
            return new MyWebSocket(idCounter, m, smt, sqlcon);
        }
    };

    resHandler = new ResourceHandler();
    resHandler.setDirectoriesListed(true);
    resHandler.setResourceBase(rootDirPath);

    wsHandler.setHandler(resHandler);
    setHandler(wsHandler);
}
项目:jersey-guice-jetty-angular-seed    文件:Main.java   
public void startServer() throws Exception {
    int serverPort = propertiesConfiguration.getInt("server.port.http");
    Server server = new Server(serverPort);

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newClassPathResource("/web"));

    ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/api");
    servletContextHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));

    initGuiceInjector();

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(resourceHandler);
    handlerList.addHandler(servletContextHandler);
    server.setHandler(handlerList);

    server.start();
    server.join();
}
项目:performance-test-harness-for-geoevent    文件:WebsocketServerEventProducer.java   
private void setup(int port) {
    if (server == null) {
        server = new Server(port);
        ServletHandler servletHandler = new ServletHandler();
        webSocketServlet = new WebsocketOutboundServlet();
        ServletHolder holder = new ServletHolder(webSocketServlet);
        servletHandler.addServletWithMapping(holder, uri + URI_SUFFIX);

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setBaseResource(Resource.newClassPathResource("com/example/docroot/"));

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{servletHandler, resourceHandler, new DefaultHandler()});
        server.setHandler(handlers);
        try {
            server.start();
            String url = "ws://localhost:" + port + uri;
            System.out.println(ImplMessages.getMessage("WS_SERVER_START_MSG", url));
            // add the shutdown hook
            Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown()));
        } catch (Exception error) {
            System.out.println(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()));
            error.printStackTrace();
        }
    }
}
项目:performance-test-harness-for-geoevent    文件:WebsocketServerEventConsumer.java   
private void setup(int port) {
    if (server == null) {
        server = new Server(port);
        ServletHandler servletHandler = new ServletHandler();
        webSocketServlet = new WebsocketOutboundServlet(message -> receive(message));
        ServletHolder holder = new ServletHolder(webSocketServlet);
        servletHandler.addServletWithMapping(holder, uri + URI_SUFFIX);

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setBaseResource(Resource.newClassPathResource("com/example/docroot/"));

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{servletHandler, resourceHandler, new DefaultHandler()});
        server.setHandler(handlers);
        try {
            server.start();
            String url = "ws://localhost:" + port + uri;
            System.out.println(ImplMessages.getMessage("WS_SERVER_START_MSG", url));
            // add the shutdown hook
            Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown()));
        } catch (Exception error) {
            System.out.println(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()));
            error.printStackTrace();
        }
    }
}
项目:armeria    文件:JettyServiceTest.java   
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.port(0, SessionProtocol.HTTP);
    sb.port(0, SessionProtocol.HTTPS);
    sb.sslContext(SessionProtocol.HTTPS,
                  certificate.certificateFile(),
                  certificate.privateKeyFile());

    sb.serviceUnder(
            "/jsp/",
            new JettyServiceBuilder()
                    .handler(newWebAppContext())
                    .configurator(s -> jettyBeans.addAll(s.getBeans()))
                    .build()
                    .decorate(LoggingService.newDecorator()));

    sb.serviceUnder(
            "/default/",
            new JettyServiceBuilder().handler(new DefaultHandler()).build());

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(webAppRoot().getPath());
    sb.serviceUnder(
            "/resources/",
            new JettyServiceBuilder().handler(resourceHandler).build());
}
项目:stepic_java_webserver    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    accountService.addNewUser(new UserProfile("admin"));
    accountService.addNewUser(new UserProfile("test"));

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new UsersServlet(accountService)), "/api/v1/users");
    context.addServlet(new ServletHolder(new SessionsServlet(accountService)), "/api/v1/sessions");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    server.join();
}
项目:stepic_java_webserver    文件:Main.java   
public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new WebSocketChatServlet()), "/chat");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});
    server.setHandler(handlers);

    server.start();
    server.join();
}
项目:frinika    文件:SwingJavaFXTest.java   
public static void main(String[] args)  throws Exception {
Server server = new Server(15000);
HandlerCollection hc = new HandlerCollection();

ResourceHandler rh = new ResourceHandler();
rh.setBaseResource(Resource.newClassPathResource("/com/frinika/web/content/"));
rh.setDirectoriesListed(true);
hc.addHandler(rh);
server.setHandler(hc);
server.start();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                initAndShowGUI();
            }
        });
    }
项目:tp_java_2015_02    文件:Main.java   
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.out.append("Use port as the first argument");
        System.exit(1);
    }

    String portString = args[0];
    int port = Integer.valueOf(portString);
    System.out.append("Starting at port: ").append(portString).append('\n');

    Server server = new Server(port);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new AdminPageServlet()), AdminPageServlet.adminPageURL);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("static");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});
    server.setHandler(handlers);

    server.start();
    server.join();
}
项目:BeSeenium    文件:HttpServer.java   
/**
     * do setup for the static resource handler
     * @return ContextHandler for the static resource handler
     */
    private static ContextHandler setUpGuiHandler() throws MalformedURLException
    {
        ContextHandler context1 = new ContextHandler();
        context1.setContextPath("/");        
        ResourceHandler res = new ResourceHandler();
        res.setWelcomeFiles(new String[]{"index.html"});
        res.setBaseResource(Resource.newResource("./resources/"));
        context1.setHandler(res);
        logger.info("<---gui handler initialised--->");

//    WebAppContext webApp = new WebAppContext();
//    webApp.setContextPath("/");
//    webApp.setResourceBase("/home/orpheus/projects/BeSeen/BeSeenium/resources/");
//    webApp.setWar("/home/orpheus/projects/BeSeen/BeSeenium/resources/quercus-4.0.18.war");
//    webApp.setServer(server);
   // context1.setHandler(webApp);

        return context1;
    }
项目:MoodCat.me-Core    文件:App.java   
private ContextHandlerCollection attachHandlers(final File staticsFolder, final Module... overrides) {
    final MoodcatHandler moodcatHandler = new MoodcatHandler(this, staticsFolder, overrides);

    final ResourceHandler resources = new ResourceHandler();
    resources.setBaseResource(Resource.newResource(staticsFolder));
    resources.setDirectoriesListed(false);
    resources.setCacheControl("max-age=3600");

    final HashSessionManager hashSessionManager = new HashSessionManager();
    hashSessionManager.setMaxInactiveInterval(SESSION_KEEP_ALIVE);

    final ContextHandlerCollection handlers = new ContextHandlerCollection();
    // CHECKSTYLE:OFF
    handlers.addContext("/", "/").setHandler(resources);
    handlers.addContext("/", "/").setHandler(moodcatHandler);
    // CHECKSTYLE:ON

    return handlers;
}
项目:mesos-hbase    文件:ConfigServer.java   
@Inject
public ConfigServer(HBaseFrameworkConfig hbaseFrameworkConfig,
    IPersistentStateStore persistenceStore) {
  this.hbaseFrameworkConfig = hbaseFrameworkConfig;
  this.persistenceStore = persistenceStore;
  engine = new Engine();
  server = new Server(hbaseFrameworkConfig.getConfigServerPort());
  ResourceHandler resourceHandler = new ResourceHandler();
  resourceHandler.setResourceBase(hbaseFrameworkConfig.getExecutorPath());
  HandlerList handlers = new HandlerList();
  handlers.setHandlers(new Handler[]{
      resourceHandler, new ServeHbaseConfigHandler()});
  server.setHandler(handlers);

  try {
    server.start();

  } catch (Exception e) {
    final String msg = "Unable to start jetty server";
    log.error(msg, e);
    throw new ConfigServerException(msg, e);
  }
}
项目:stepic-java-web-service    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    final Handler[] handler = {resource_handler, context};
    handlers.setHandlers(handler);

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
项目:stepic-java-web-service    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    final Handler[] handler = {resource_handler, context};
    handlers.setHandlers(handler);

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
项目:restolino    文件:MainHandler.java   
private void setupFilesHandler(Reflections reflections) throws IOException {

        // Set up the handler if there's anything to be served:
        URL url = getFilesUrl(reflections);
        if (url != null) {

            // Set up the resource handler:
            ResourceHandler filesHandler = new ResourceHandler();
            Resource resource = Resource.newResource(url);
            filesHandler.setBaseResource(resource);

            this.filesHandler = filesHandler;

            log.info("Set up static file handler for URL: " + url);
        } else {
            log.info("No static file handler configured.");
        }
    }
项目:RushServer    文件:WebServerMgr.java   
public static boolean init(WebServerConfig webServerConfig)
{
    server = new Server(webServerConfig.port);
    try
    {
        context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.setResourceBase("");
        resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(webServerConfig.resourcePath);
        handlerList.addHandler(context);
        handlerList.addHandler(resourceHandler);
        server.setHandler(handlerList);
        loadWebServlet(webServerConfig.packages);
        server.start();
    }
    catch (Exception e)
    {
        Log.error("WebServerMgr init error", e);
        return false;
    }

    return true;
}
项目:crawljax    文件:PassBasicHttpAuthTest.java   
private ConstraintSecurityHandler newSecurityHandler(ResourceHandler handler) {
    HashLoginService login = new HashLoginService();
    login.putUser(USERNAME, Credential.getCredential(PASSWORD), new String[] { "user" });

    Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    constraint.setRoles(new String[] { "user" });
    constraint.setAuthenticate(true);

    ConstraintMapping cm = new ConstraintMapping();
    cm.setConstraint(constraint);
    cm.setPathSpec("/*");

    ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
    csh.setAuthenticator(new BasicAuthenticator());
    csh.addConstraintMapping(cm);
    csh.setLoginService(login);
    csh.setHandler(handler);
    return csh;
}
项目:bkbc-tools    文件:JettyCrosServer.java   
public JettyCrosServer() throws Exception {
    server = new Server(80);
    HandlerList handlers = new HandlerList();
       ResourceHandler resource_handler = new ResourceHandler();
       resource_handler.setDirectoriesListed(true);
       resource_handler.setWelcomeFiles(new String[] { "index.html" });
       resource_handler.setBaseResource(Resource.newClassPathResource("web"));

       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       context.setInitParameter("maxInterval", "1000");
       context.setInitParameter("logLevel", "2");

       handlers.setHandlers(new Handler[] { resource_handler, context});

       server.setHandler(handlers);


       FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
       filterHolder.getInitParameters().put(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin,Authorization");
       context.addFilter(filterHolder, "/*", EnumSet.allOf(DispatcherType.class));

       context.addServlet(new ServletHolder(new JsonServlet()), "/t.json");
       context.addServlet(new ServletHolder(new DefaultServlet()), "/*");

}
项目:buck-cutom    文件:WebServerTest.java   
@Test
public void testCreateHandlersCoversExpectedContextPaths() {
  ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
  WebServer webServer = new WebServer(/* port */ 9999, projectFilesystem, "/static/");
  List<ContextHandler> handlers = webServer.createHandlers();
  final Map<String, ContextHandler> contextPathToHandler = Maps.newHashMap();
  for (ContextHandler handler : handlers) {
    contextPathToHandler.put(handler.getContextPath(), handler);
  }

  Function<String, TemplateHandlerDelegate> getDelegate =
      new Function<String, TemplateHandlerDelegate>() {
        @Override
        public TemplateHandlerDelegate apply(String contextPath) {
          return ((TemplateHandler) contextPathToHandler.get(contextPath).getHandler())
              .getDelegate();
        }
      };
  assertTrue(getDelegate.apply("/") instanceof IndexHandlerDelegate);
  assertTrue(contextPathToHandler.get("/static").getHandler() instanceof ResourceHandler);
  assertTrue(getDelegate.apply("/trace") instanceof TraceHandlerDelegate);
  assertTrue(getDelegate.apply("/traces") instanceof TracesHandlerDelegate);
  assertTrue(contextPathToHandler.get("/tracedata").getHandler() instanceof TraceDataHandler);
}
项目:trux    文件:TruxServer.java   
@Override
public void run() {
    try {
        Server server = new Server(8080);

        ResourceHandler resource_handler = new ResourceHandler();
        resource_handler.setDirectoriesListed(true);
        resource_handler.setWelcomeFiles(new String[] { "index.html" });

        resource_handler.setResourceBase("./www");

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { resource_handler,
                new StateHandler(this.geo) });
        server.setHandler(handlers);

        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:candybean    文件:ConfigurationServerDriver.java   
public static void main (String args[]) throws Exception{
    logger.info("Starting JETTY server");
    Server server = new Server(8080);

       ResourceHandler resourceHandler = new ResourceHandler();
       resourceHandler.setDirectoriesListed(true);
       resourceHandler.setWelcomeFiles(new String[]{ "resources/html/configure.html" });
       resourceHandler.setResourceBase(".");

       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       resourceHandler.setWelcomeFiles(new String[]{ "resources/html/configure.html" });
       resourceHandler.setResourceBase(".");
       context.addServlet(new ServletHolder(new ConfigurationServlet()),"/cfg");
       context.addServlet(new ServletHolder(new SaveConfigurationServlet()),"/cfg/save");
       context.addServlet(new ServletHolder(new LoadConfigurationServlet()),"/cfg/load");

       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { resourceHandler, context });
       server.setHandler(handlers);

       server.start();
    logger.info("Configuration server started at: http://localhost:8080/cfg");
       server.join();
}
项目:iif-resultsrepository    文件:ServerStarter.java   
public static void startWebServer(int port) throws Exception {
    webServer = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    webServer.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    //resource_handler.setWelcomeFiles(new String[] { "index.html" });

    String serverRoot = ServerStarter.class.getResource("/").getFile();

    resource_handler.setResourceBase(serverRoot);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    webServer.setHandler(handlers);

    webServer.start();

}
项目:superpipes    文件:T_CheckURITest.java   
public T_CheckURITest()
{
    // Dispatcher
    final Dispatcher dispatcher = new Dispatcher();
    this.node = dispatcher.addNode( "dummy" ,
                                    N_Dummy.class ,
                                    ConfigProperties.EMPTY_COMMONS );
    this.transform = node.addTransformIN( T_CheckURI.class ,
                                          ConfigProperties.EMPTY_COMMONS );

    // Server
    this.server = new Server( PORT );

    final ResourceHandler rHandler = new ResourceHandler();
    rHandler.setDirectoriesListed( true );
    rHandler.setResourceBase( "src/test/webapp" );

    this.server.setHandler( rHandler );
}
项目:superpipes    文件:T_FindBiggestTest.java   
public T_FindBiggestTest()
{
    // Dispatcher
    final Dispatcher dispatcher = new Dispatcher();
    this.node = dispatcher.addNode( "dummy" ,
                                    N_Dummy.class ,
                                    ConfigProperties.EMPTY_COMMONS );
    this.transform = node.addTransformIN( T_FindBiggest.class ,
                                          ConfigProperties.EMPTY_COMMONS );

    // Server
    this.server = new Server( PORT );

    final ResourceHandler rHandler = new ResourceHandler();
    rHandler.setDirectoriesListed( true );
    rHandler.setResourceBase( "src/test/webapp" );

    this.server.setHandler( rHandler );
}