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


Java DefaultServlet類代碼示例

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


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

示例1: run

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

示例2: start

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

示例3: main

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    try(HttpRequest http = new HttpRequest()) {
        WeatherService service = new WeatherServiceCache(new WeatherWebApi(http));
        WeatherController weatherCtr = new WeatherController(service);

        ServletHolder holderHome = new ServletHolder("static-home", DefaultServlet.class);
        String resPath = getSystemResource("public").toString();
        holderHome.setInitParameter("resourceBase", resPath);
        holderHome.setInitParameter("dirAllowed", "true");
        holderHome.setInitParameter("pathInfoOnly", "true");

        int[] counter = {0};
        new HttpServer(3000)
                .addHandler("/search", weatherCtr::getSearch)
                .addHandler("/search/city", weatherCtr::searchCity)
                .addHandler("/weather/*", weatherCtr::last30daysWeather)
                .addServletHolder("/public/*", holderHome)
                .run();
    }
}
 
開發者ID:isel-leic-mpd,項目名稱:mpd-2017-i41d,代碼行數:21,代碼來源:WeatherWebApp.java

示例4: run

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的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.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);
		new Thread(new Console(getPinto(),port,build, () -> {
			try {
				server.stop();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}), "console_thread").start();
        server.start();
        server.join();
	}
 
開發者ID:punkbrwstr,項目名稱:pinto,代碼行數:27,代碼來源:Main.java

示例5: configureServlets

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
@Override
protected void configureServlets() {
  if (ENABLE_CORS_FOR.get() != null) {
    filter(API_PATH).through(new CorsFilter(ENABLE_CORS_FOR.get()));
  }
  serve(API_PATH).with(TServlet.class);

  filter(ApiBeta.PATH, ApiBeta.PATH + "/*").through(LeaderRedirectFilter.class);
  filter(ApiBeta.PATH, ApiBeta.PATH + "/*")
      .through(GuiceContainer.class, JettyServerModule.GUICE_CONTAINER_PARAMS);
  bind(ApiBeta.class);

  serve("/apiclient", "/apiclient/*")
      .with(new DefaultServlet(), ImmutableMap.<String, String>builder()
          .put("resourceBase", API_CLIENT_ROOT)
          .put("pathInfoOnly", "true")
          .put("dirAllowed", "false")
          .build());
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:20,代碼來源:ApiModule.java

示例6: getSwagger

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
private ServletModule getSwagger() {
	
	String resourceBasePath = ServletContextListner.class.getResource("/swagger-ui").toExternalForm();
	DefaultServlet ds = new DefaultServlet();
	
	ServletModule sm = new ServletModule() {
		@Override
		protected void configureServlets() {
			Map<String, String> params = new HashMap<>();
			params.put("resourceBase", resourceBasePath);
			params.put("redirectWelcome", "true");
			serve("/*").with(ds, params);
		}
	};
	
	return sm;
	
}
 
開發者ID:Netflix,項目名稱:conductor,代碼行數:19,代碼來源:ServletContextListner.java

示例7: ParticipantHoster

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
public ParticipantHoster(final List<ContextParticipantProxy> unregisteredParticipants, final short port) throws Exception {
	participants = unregisteredParticipants;

	participantsUrl = FluentIterable.from(participants).transform(new Function<ContextParticipantProxy, String>() {

		@Override
		public String apply(final ContextParticipantProxy input) {
			// return "/" + input.getApplicationName() +
			// "/ContextParticipant/*";
			return input.getApplicationName();
		}
	}).append("/*");

	server = new Server(port);
	final ServletContextHandler sch = new ServletContextHandler(server, "/");
	sch.addEventListener(new InnerListener());
	sch.addFilter(AppGuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
	sch.addServlet(DefaultServlet.class, "/");
	server.start();
}
 
開發者ID:jkiddo,項目名稱:ccow,代碼行數:21,代碼來源:ParticipantHoster.java

示例8: setupWebAppContext

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
private static WebAppContext setupWebAppContext(
    ZeppelinConfiguration conf) {

  WebAppContext webApp = new WebAppContext();
  webApp.setContextPath(conf.getServerContextPath());
  File warPath = new File(conf.getString(ConfVars.ZEPPELIN_WAR));
  if (warPath.isDirectory()) {
    // Development mode, read from FS
    // webApp.setDescriptor(warPath+"/WEB-INF/web.xml");
    webApp.setResourceBase(warPath.getPath());
    webApp.setParentLoaderPriority(true);
  } else {
    // use packaged WAR
    webApp.setWar(warPath.getAbsolutePath());
    File warTempDirectory = new File(conf.getRelativeDir(ConfVars.ZEPPELIN_WAR_TEMPDIR));
    warTempDirectory.mkdir();
    LOG.info("ZeppelinServer Webapp path: {}", warTempDirectory.getPath());
    webApp.setTempDirectory(warTempDirectory);
  }
  // Explicit bind to root
  webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
  return webApp;
}
 
開發者ID:lorthos,項目名稱:incubator-zeppelin-druid,代碼行數:24,代碼來源:ZeppelinServer.java

示例9: JettyRule

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
public JettyRule(final Filter filter, final Trace trace) {
    this.server = new Server(0);

    final ServletContextHandler handler = new ServletContextHandler();
    handler.setContextPath("/");
    handler.addServlet(new ServletHolder(new AsyncServlet(trace)), "/async");
    handler.addServlet(new ServletHolder(new TraceServlet(trace)), "/traced");
    handler.addServlet(new ServletHolder(new TraceServlet(trace)), "/untraced");
    handler.addServlet(ForwardServlet.class, "/forward");
    handler.addServlet(IncludeServlet.class, "/include");
    handler.addServlet(FailingServlet.class, "/failure");
    handler.addServlet(DefaultServlet.class, "/");

    handler.addFilter(new FilterHolder(filter), "/async", EnumSet.allOf(DispatcherType.class));
    // /untraced is intentionally NOT traced!
    handler.addFilter(new FilterHolder(filter), "/traced", EnumSet.allOf(DispatcherType.class));
    handler.addFilter(new FilterHolder(filter), "/forward", EnumSet.allOf(DispatcherType.class));
    handler.addFilter(new FilterHolder(filter), "/include", EnumSet.allOf(DispatcherType.class));
    handler.addFilter(new FilterHolder(filter), "/failure", EnumSet.allOf(DispatcherType.class));

    server.setHandler(handler);
}
 
開發者ID:zalando,項目名稱:tracer,代碼行數:23,代碼來源:JettyRule.java

示例10: provideServer

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
@Provides
@Singleton
Server provideServer(Environment env, ShutdownManager shutdownManager) {
    Server server = new Server();

    ServerConnector connector = new ServerConnector(server);
    connector.setPort(12025);
    server.addConnector(connector);

    ServletContextHandler handler = new ServletContextHandler();
    handler.setContextPath("/");

    DefaultServlet servlet = new DefaultServlet();

    ServletHolder holder = new ServletHolder(servlet);
    handler.addServlet(holder, "/*");
    handler.setResourceBase(env.getProperty("bq.internaljetty.base"));

    server.setHandler(handler);

    shutdownManager.addShutdownHook(() -> {
        server.stop();
    });

    return server;
}
 
開發者ID:bootique,項目名稱:bootique,代碼行數:27,代碼來源:BQInternalWebServerTestFactory.java

示例11: testHttpFileSystemReadTimeouts

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
@Test
public void testHttpFileSystemReadTimeouts() throws Exception {
  HttpServer server = new HttpServer("/", 0, null, new ServletHolder(DefaultServlet.class));
  try {
    server.addServlet("/download", new PartialFileFetchServlet());
    server.start();
    String serverUrl = server.getUrl().toString() + "download";
    FileSystemClientThread fileSystemClientThread = new FileSystemClientThread(new URI(serverUrl));
    fileSystemClientThread.start();
    fileSystemClientThread.join();
    Assert.assertEquals(fileSystemClientThread.getTotalBytesRead(), THRESHOLD_BYTES);
    Assert.assertNull(clientException);
    Assert.assertNull(serverException);
  } finally {
    server.stop();
  }
}
 
開發者ID:apache,項目名稱:samza,代碼行數:18,代碼來源:TestHttpFileSystem.java

示例12: run

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
public int run(String[] args) throws Exception {
  URI uri = new URI("http://" + conf.get(HTRACE_VIEWER_HTTP_ADDRESS_KEY,
                                         HTRACE_VIEWER_HTTP_ADDRESS_DEFAULT));
  InetSocketAddress addr = new InetSocketAddress(uri.getHost(), uri.getPort());
  server = new Server(addr);
  ServletContextHandler root =
    new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
  server.setHandler(root);

  String resourceBase = server.getClass()
                              .getClassLoader()
                              .getResource("webapps/htrace")
                              .toExternalForm();
  root.setResourceBase(resourceBase);
  root.setWelcomeFiles(new String[]{"index.html"});
  root.addServlet(new ServletHolder(new DefaultServlet()),
                  "/");
  root.addServlet(new ServletHolder(new HBaseSpanViewerTracesServlet(conf)),
                  "/gettraces");
  root.addServlet(new ServletHolder(new HBaseSpanViewerSpansServlet(conf)),
                  "/getspans/*");

  server.start();
  server.join();
  return 0;
}
 
開發者ID:apache,項目名稱:incubator-htrace,代碼行數:27,代碼來源:HBaseSpanViewerServer.java

示例13: setupWebAppContext

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
private static WebAppContext setupWebAppContext(VarOneConfiguration conf) {
	WebAppContext webApp = new WebAppContext();
    webApp.setContextPath(conf.getServerContextPath());
    File warPath = new File(conf.getString(ConfVars.VARONE_WAR));
    if (warPath.isDirectory()) {
      webApp.setResourceBase(warPath.getPath());
      webApp.setParentLoaderPriority(true);
    } else {
      // use packaged WAR
      webApp.setWar(warPath.getAbsolutePath());
      File warTempDirectory = new File(conf.getRelativeDir(ConfVars.VARONE_WAR_TEMPDIR));
      warTempDirectory.mkdir();
      LOG.info("VarOneServer Webapp path: {}" + warTempDirectory.getPath());
      webApp.setTempDirectory(warTempDirectory);
    }
    // Explicit bind to root
    webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
    return webApp;
}
 
開發者ID:SparkMonitor,項目名稱:varOne,代碼行數:20,代碼來源:VarOneServer.java

示例14: main

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
public static void main(String[] args) {
    Server server = new Server(8180);

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

    ServletHolder jerseyServlet = context
            .addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/rest/*");
    jerseyServlet.setInitOrder(1);
    jerseyServlet
            .setInitParameter("jersey.config.server.provider.packages", "ske.part.partsregister.interfaces.rest");
    String appName = PartsregisterApplication.class.getCanonicalName();
    jerseyServlet.setInitParameter("javax.ws.rs.Application", appName);

    ServletHolder staticServlet = context.addServlet(DefaultServlet.class, "/*");
    staticServlet.setInitParameter("resourceBase", "src/main/webapp");
    staticServlet.setInitParameter("pathInfoOnly", "true");

    try {
        server.start();
        server.join();
    } catch (Throwable t) {
        t.printStackTrace(System.err);
    }
}
 
開發者ID:lind,項目名稱:partsregister-eventsourcing,代碼行數:27,代碼來源:TestServer.java

示例15: JettyCrosServer

import org.eclipse.jetty.servlet.DefaultServlet; //導入依賴的package包/類
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()), "/*");
       
}
 
開發者ID:y12studio,項目名稱:bkbc-tools,代碼行數:27,代碼來源:JettyCrosServer.java


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