當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourceHandler類代碼示例

本文整理匯總了Java中org.eclipse.jetty.server.handler.ResourceHandler的典型用法代碼示例。如果您正苦於以下問題:Java ResourceHandler類的具體用法?Java ResourceHandler怎麽用?Java ResourceHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ResourceHandler類屬於org.eclipse.jetty.server.handler包,在下文中一共展示了ResourceHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
    }
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:23,代碼來源:Main.java

示例2: main

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
    }
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_04,代碼行數:18,代碼來源:Main.java

示例3: initServer

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
}
 
開發者ID:VKCOM,項目名稱:vk-java-sdk,代碼行數:24,代碼來源:Application.java

示例4: start

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:18,代碼來源:Main.java

示例5: main

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
    }
 
開發者ID:biblelamp,項目名稱:JavaEE,代碼行數:27,代碼來源:Main.java

示例6: start

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:RUCD,項目名稱:apt-graph,代碼行數:25,代碼來源:FileServer.java

示例7: run

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:22,代碼來源:PerformanceServer.java

示例8: main

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
}
 
開發者ID:SvichkarevAnatoly,項目名稱:stepic-java-web-service,代碼行數:22,代碼來源:Main.java

示例9: run

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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;
}
 
開發者ID:sannies,項目名稱:ismv-server,代碼行數:23,代碼來源:Server.java

示例10: main

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
}
 
開發者ID:vitaly-chibrikov,項目名稱:homework_tester,代碼行數:19,代碼來源:Main.java

示例11: addResources

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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);
}
 
開發者ID:dohbot,項目名稱:knives,代碼行數:21,代碼來源:EmbeddedJetty.java

示例12: main

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
}
 
開發者ID:AlanHohn,項目名稱:jaxrs,代碼行數:26,代碼來源:EmbeddedServer.java

示例13: WebSocketServer

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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);
}
 
開發者ID:ryohashioka,項目名稱:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House,代碼行數:25,代碼來源:WebSocketServer.java

示例14: startServer

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
}
 
開發者ID:nhekfqn,項目名稱:jersey-guice-jetty-angular-seed,代碼行數:21,代碼來源:Main.java

示例15: setup

import org.eclipse.jetty.server.handler.ResourceHandler; //導入依賴的package包/類
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();
        }
    }
}
 
開發者ID:Esri,項目名稱:performance-test-harness-for-geoevent,代碼行數:27,代碼來源:WebsocketServerEventProducer.java


注:本文中的org.eclipse.jetty.server.handler.ResourceHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。