Java Code Examples for org.eclipse.jetty.servlet.ServletContextHandler#setWelcomeFiles()
The following examples show how to use
org.eclipse.jetty.servlet.ServletContextHandler#setWelcomeFiles() .
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: HBaseSpanViewerServer.java From incubator-retired-htrace with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: JettyServer.java From conductor with Apache License 2.0 | 5 votes |
@Override public synchronized void start() throws Exception { if (server != null) { throw new IllegalStateException("Server is already running"); } this.server = new Server(port); ServletContextHandler context = new ServletContextHandler(); context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); context.setWelcomeFiles(new String[]{"index.html"}); server.setHandler(context); if (getBoolean("enableJMX")) { System.out.println("configure MBean container..."); configureMBeanContainer(server); } server.start(); System.out.println("Started server on http://localhost:" + port + "/"); try { if (getBoolean("loadSample")) { System.out.println("Creating kitchensink workflow"); createKitchenSink(port); } } catch (Exception e) { logger.error("Error loading sample!", e); } if (join) { server.join(); } }
Example 3
Source File: ClientProxy.java From OmniOcular with Apache License 2.0 | 5 votes |
@Override public void startHttpServer() { Thread t = new Thread(new Runnable() { @Override public void run() { Server server = new Server(23333); try { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); ServletHolder wsHolder = new ServletHolder("echo", new WebSocketServlet() { @Override public void configure(WebSocketServletFactory factory) { factory.register(WebSocketHandler.class); } }); context.addServlet(wsHolder, "/w"); URI uri = OmniOcular.class.getResource("/assets/omniocular/static/").toURI(); context.setBaseResource(Resource.newResource(uri)); context.setWelcomeFiles(new String[]{"index.html"}); ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class); holderPwd.setInitParameter("cacheControl", "max-age=0,public"); holderPwd.setInitParameter("useFileMappedBuffer", "false"); context.addServlet(holderPwd, "/"); server.setHandler(context); server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); } } }); t.start(); }
Example 4
Source File: HttpTransportConfiguration.java From chassis with Apache License 2.0 | 5 votes |
@Bean public ServletContextHandler servletContextHandler(){ ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY); context.setErrorHandler(null); context.setWelcomeFiles(new String[] { "/" }); return context; }
Example 5
Source File: ChassisEurekaTestConfiguration.java From chassis with Apache License 2.0 | 5 votes |
@Order(0) @Bean(initMethod="start", destroyMethod="stop") public Server httpServer( @Value("${http.hostname}") String hostname, @Value("${http.port}") int port, ConfigurableWebApplicationContext webApplicationContext) { // set up servlets ServletHandler servlets = new ServletHandler(); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY); context.setErrorHandler(null); context.setWelcomeFiles(new String[] { "/" }); // set up spring with the servlet context setServletContext(context.getServletContext()); // configure the spring mvc dispatcher DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext); // map application servlets context.addServlet(new ServletHolder(dispatcher), "/"); servlets.setHandler(context); // create the server InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port); Server server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setHost(address.getHostName()); connector.setPort(address.getPort()); server.setConnectors(new Connector[]{ connector }); server.setHandler(servlets); return server; }
Example 6
Source File: TestSpringWebApp.java From chassis with Apache License 2.0 | 5 votes |
@Bean(initMethod = "start", destroyMethod = "stop", name = "httpServer") @Order(0) public Server httpServer(ConfigurableWebApplicationContext webApplicationContext) { // set up servlets ServletHandler servlets = new ServletHandler(); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY); context.setErrorHandler(null); context.setWelcomeFiles(new String[]{"/"}); // set up spring with the servlet context setServletContext(context.getServletContext()); // configure the spring mvc dispatcher DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext); // map application servlets context.addServlet(new ServletHolder(dispatcher), "/"); servlets.setHandler(context); // create the server InetSocketAddress address = new InetSocketAddress(SocketUtils.findAvailableTcpPort()); Server server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setHost(address.getHostName()); connector.setPort(address.getPort()); server.setConnectors(new Connector[]{connector}); server.setHandler(servlets); server.setStopAtShutdown(true); return server; }
Example 7
Source File: AdminTransportConfiguration.java From chassis with Apache License 2.0 | 4 votes |
@Bean(initMethod="start", destroyMethod="stop") @Order(0) public Server adminServer( @Value("${admin.hostname}") String hostname, @Value("${admin.port}") int port) { // set up servlets ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY); context.setErrorHandler(null); context.setWelcomeFiles(new String[] { "/" }); // enable gzip context.addFilter(GzipFilter.class, "/*", null); // add common admin servlets context.addServlet(new ServletHolder(new HealthServlet(healthCheckRegistry)), "/healthcheck"); context.addServlet(new ServletHolder(new ClasspathResourceServlet("com/kixeye/chassis/transport/admin", "/admin/", "index.html")), "/admin/*"); context.addServlet(new ServletHolder(new PropertiesServlet()), "/admin/properties"); context.addServlet(new ServletHolder(new ClasspathDumpServlet()), "/admin/classpath"); // add websocket servlets if WebSockets have been initialized if (mappingRegistry != null && messageRegistry != null) { context.addServlet(new ServletHolder(new ProtobufMessagesDocumentationServlet(appName, mappingRegistry, messageRegistry)), "/schema/messages/protobuf"); context.addServlet(new ServletHolder(new ProtobufEnvelopeDocumentationServlet()), "/schema/envelope/protobuf"); } // add metric servlets if Metric has been initialized if (metricRegistry != null && healthCheckRegistry != null) { context.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry); context.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry); ServletHolder holder = new ServletHolder(new AdminServlet()); holder.setInitParameter("service-name", System.getProperty("app.name")); context.addServlet(holder, "/metrics/*"); } // create the server InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port); Server server = new Server(); JettyConnectorRegistry.registerHttpConnector(server, address); server.setHandler(context); return server; }