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


Java ServletContextHandler類代碼示例

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


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

示例1: main

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
public static void main(String[] args) throws Exception {

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");

        Server jettyServer = new Server(8067);
        jettyServer.setHandler(context);

        ServletHolder jerseyServlet = context.addServlet(
                org.glassfish.jersey.servlet.ServletContainer.class, "/*");
        jerseyServlet.setInitOrder(0);

        // Tells the Jersey Servlet which REST service/class to load.
        jerseyServlet.setInitParameter(
                "jersey.config.server.provider.classnames",
                EntryPointTestHandler.class.getCanonicalName());

        try {
            jettyServer.start();
            jettyServer.join();
        } finally {
            jettyServer.destroy();
        }
    }
 
開發者ID:warlock-china,項目名稱:wisp,代碼行數:25,代碼來源:ServerMain.java

示例2: JettyAdminServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
public JettyAdminServer(String address, int port, int timeout, String commandUrl) {
    this.port = port;
    this.idleTimeout = timeout;
    this.commandUrl = commandUrl;
    this.address = address;

    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address);
    connector.setPort(port);
    connector.setIdleTimeout(idleTimeout);
    server.addConnector(connector);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/*");
    server.setHandler(context);

    context.addServlet(new ServletHolder(new CommandServlet()), commandUrl + "/*");
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:20,代碼來源:JettyAdminServer.java

示例3: testStarted

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
public void testStarted() {
	// update the configuration
	this.reconfigure();
	this.server = new Server(this.getSaveConfig().getPort());

	ServletContextHandler context = new ServletContextHandler();
	context.setContextPath("/");
	server.setHandler(context);
	context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");

	try {
		server.start();
	} catch (Exception e) {
		log.error("Couldn't start http server", e);
	}

}
 
開發者ID:johrstrom,項目名稱:jmeter-prometheus-plugin,代碼行數:18,代碼來源:PrometheusListener.java

示例4: main

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
public static void main(String[] args) {
    int port = Configuration.INSTANCE.getInt("port", 8080);
    Server server = new Server(port);
    ServletContextHandler contextHandler
            = new ServletContextHandler(ServletContextHandler.SESSIONS);
    contextHandler.setContextPath("/");
    ServletHolder sh = new ServletHolder(new VaadinServlet());
    contextHandler.addServlet(sh, "/*");
    contextHandler.setInitParameter("ui", AnalysisUI.class.getCanonicalName());
    contextHandler.setInitParameter("productionMode", String.valueOf(PRODUCTION_MODE));
    server.setHandler(contextHandler);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        LOG.error("Failed to start application", e);
    }
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:19,代碼來源:Application.java

示例5: main

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的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

示例6: run

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
public void run() throws Exception {
	org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
	Server server = new Server(port);
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       context.setWelcomeFiles(new String[]{ "demo.html" });
       context.setResourceBase(httpPath);
       HashSessionIdManager idmanager = new HashSessionIdManager();
       server.setSessionIdManager(idmanager);
       HashSessionManager manager = new HashSessionManager();
       SessionHandler sessions = new SessionHandler(manager);
       sessions.setHandler(context);
       context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
       ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
       context.addServlet(holderPwd,"/*");
       server.setHandler(sessions);
       server.start();
       server.join();
}
 
開發者ID:punkbrwstr,項目名稱:pinto,代碼行數:20,代碼來源:Demo.java

示例7: initClientProxy

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
private void initClientProxy() {
    int port = Context.getConfig().getInteger("osmand.port");
    if (port != 0) {
        ServletContextHandler servletHandler = new ServletContextHandler() {
            @Override
            public void doScope(
                    String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
                    throws IOException, ServletException {
                if (target.equals("/") && request.getMethod().equals(HttpMethod.POST.asString())) {
                    super.doScope(target, baseRequest, request, response);
                }
            }
        };
        ServletHolder servletHolder = new ServletHolder(new AsyncProxyServlet.Transparent());
        servletHolder.setInitParameter("proxyTo", "http://localhost:" + port);
        servletHandler.addServlet(servletHolder, "/");
        handlers.addHandler(servletHandler);
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:20,代碼來源:WebServer.java

示例8: startWebSocket

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
/**
 * start server
 * 
 * @param port
 * @param path
 * @param handlerClass
 */
public static void startWebSocket(int port, String path, String handlerClass) {
	try {
		Server server = new Server(port);
		HandlerList handlerList = new HandlerList();
		ServletContextHandler context = new ServletContextHandler(
				ServletContextHandler.SESSIONS);
		context.setContextPath("/");
		context.addServlet(new ServletHolder(new Jwservlet(handlerClass)),
				path);
		handlerList.addHandler(context);
		handlerList.addHandler(new DefaultHandler());
		server.setHandler(handlerList);
		server.start();
		server.join();
	} catch (Exception e) {
		e.printStackTrace();
		LogUtil.LOG("start websocket server error:" + e.getMessage(),
				LogLev.ERROR, WebSocketServer.class);
		System.exit(1);
	}
}
 
開發者ID:Sunature,項目名稱:websocket,代碼行數:29,代碼來源:WebSocketServer.java

示例9: main

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
public static void main(String[] args) {
    int port = Configuration.INSTANCE.getInt("port", 8080);
    Server server = new Server(port);
    ServletContextHandler contextHandler
            = new ServletContextHandler(ServletContextHandler.SESSIONS);
    contextHandler.setContextPath("/");
    ServletHolder sh = new ServletHolder(new VaadinServlet());
    contextHandler.addServlet(sh, "/*");
    contextHandler.setInitParameter("ui", CrawlerAdminUI.class.getCanonicalName());
    contextHandler.setInitParameter("productionMode", String.valueOf(PRODUCTION_MODE));
    server.setHandler(contextHandler);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        LOG.error("Failed to start application", e);
    }
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:19,代碼來源:Application.java

示例10: reverseProxy

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
private static void reverseProxy() throws Exception{
  Server server = new Server();

  SocketConnector connector = new SocketConnector();
  connector.setHost("127.0.0.1");
  connector.setPort(8888);

  server.setConnectors(new Connector[]{connector});

  // Setup proxy handler to handle CONNECT methods
  ConnectHandler proxy = new ConnectHandler();
  server.setHandler(proxy);

  // Setup proxy servlet
  ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
  ServletHolder proxyServlet = new ServletHolder(ProxyServlet.Transparent.class);
  proxyServlet.setInitParameter("ProxyTo", "https://localhost:54321/");
  proxyServlet.setInitParameter("Prefix", "/");
  context.addServlet(proxyServlet, "/*");

  server.start();
}
 
開發者ID:tomkraljevic,項目名稱:jetty-embed-reverse-proxy-example,代碼行數:23,代碼來源:ProxyServer.java

示例11: addApplication

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
private void addApplication(final ServletContextHandler context, final MinijaxApplication application)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    // (0) Sort the resource methods by literal length
    application.sortResourceMethods();

    // (1) Add Minijax filter (must come before websocket!)
    context.addFilter(new FilterHolder(new MinijaxFilter(application)), "/*", EnumSet.of(DispatcherType.REQUEST));

    // (2) WebSocket endpoints
    if (OptionalClasses.WEB_SOCKET_UTILS != null) {
        OptionalClasses.WEB_SOCKET_UTILS
                .getMethod("init", ServletContextHandler.class, MinijaxApplication.class)
                .invoke(null, context, application);
    }

    // (3) Dynamic JAX-RS content
    final MinijaxServlet servlet = new MinijaxServlet(application);
    final ServletHolder servletHolder = new ServletHolder(servlet);
    servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
    context.addServlet(servletHolder, "/*");
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:23,代碼來源:Minijax.java

示例12: main

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的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

示例13: start

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
public void start() throws Exception {
    server = new Server(port);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.addFilter(AuthenticationFilter.class, "/*", null);
    context.setServer(server);

    // Add static files handler
    context.setBaseResource(Resource.newResource(JettyServer.class.getResource("/webapp")));
    context.addServlet(DefaultServlet.class,"/");
    context.setWelcomeFiles(new String[]{"index.html"});

    ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
    wsContainer.addEndpoint(createEndpointConfig(EchoEndpoint.class));

    server.setHandler(context);
    server.start();
}
 
開發者ID:asafalima,項目名稱:guice-websocket,代碼行數:19,代碼來源:JettyServer.java

示例14: jettyServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的package包/類
@Bean
public Server jettyServer(ApplicationContext context) throws Exception {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    Servlet servlet = new JettyHttpHandlerAdapter(handler);

    Server server = new Server();
    ServletContextHandler contextHandler = new ServletContextHandler(server, "");
    contextHandler.addServlet(new ServletHolder(servlet), "/");
    contextHandler.start();

    ServerConnector connector = new ServerConnector(server);
    connector.setHost("localhost");
    connector.setPort(port);
    server.addConnector(connector);

    return server;
}
 
開發者ID:hantsy,項目名稱:spring-reactive-sample,代碼行數:18,代碼來源:Application.java

示例15: start

import org.eclipse.jetty.servlet.ServletContextHandler; //導入依賴的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


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