org.eclipse.jetty.servlet.DefaultServlet Java Examples
The following examples show how to use
org.eclipse.jetty.servlet.DefaultServlet.
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: JettyServerProvider.java From browserup-proxy with Apache License 2.0 | 8 votes |
@Inject public JettyServerProvider(@Named("port") int port, @Named("address") String address, MitmProxyManager proxyManager) throws UnknownHostException { OpenApiResource openApiResource = new OpenApiResource(); openApiResource.setConfigLocation(SWAGGER_CONFIG_NAME); ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.packages(SWAGGER_PACKAGE); resourceConfig.register(openApiResource); resourceConfig.register(proxyManagerToHkBinder(proxyManager)); resourceConfig.register(JacksonFeature.class); resourceConfig.register(ConstraintViolationExceptionMapper.class); resourceConfig.registerClasses(LoggingFilter.class); resourceConfig.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true); resourceConfig.property(ServerProperties.WADL_FEATURE_DISABLE, true); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));; context.addServlet(DefaultServlet.class, "/"); context.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*"); server = new Server(new InetSocketAddress(InetAddress.getByName(address), port)); server.setHandler(context); }
Example #2
Source File: TestHttpFileSystem.java From samza with Apache License 2.0 | 6 votes |
@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(); } }
Example #3
Source File: ServerStarter.java From jetty-web-sockets-jsr356 with Apache License 2.0 | 6 votes |
public static void main( String[] args ) throws Exception { Server server = new Server(8080); // Create the 'root' Spring application context final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addEventListener(new ContextLoaderListener()); context.setInitParameter("contextClass",AnnotationConfigWebApplicationContext.class.getName()); context.setInitParameter("contextConfigLocation",AppConfig.class.getName()); // Create default servlet (servlet api required) // The name of DefaultServlet should be set to 'defualt'. final ServletHolder defaultHolder = new ServletHolder( "default", DefaultServlet.class ); defaultHolder.setInitParameter( "resourceBase", System.getProperty("user.dir") ); context.addServlet( defaultHolder, "/" ); server.setHandler(context); WebSocketServerContainerInitializer.configureContext(context); server.start(); server.join(); }
Example #4
Source File: ParallelDownloadTest.java From chipster with MIT License | 6 votes |
public static Server getJetty() throws Exception { Server server = new Server(); //http //ServerConnector connector = new ServerConnector(server); //https SslContextFactory factory = new SslContextFactory(); factory.setKeyStorePath("filebroker.ks"); factory.setKeyStorePassword("password"); ServerConnector connector = new ServerConnector(server, factory); connector.setPort(8080); server.setConnectors(new Connector[]{ connector }); ServletContextHandler handler = new ServletContextHandler(server, "/", false, false); handler.setResourceBase(new File("").getAbsolutePath()); handler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); return server; }
Example #5
Source File: EmissaryServer.java From emissary with Apache License 2.0 | 6 votes |
private ContextHandler buildStaticHandler() { // Add pathspec for static assets ServletHolder homeHolder = new ServletHolder("static-holder", DefaultServlet.class); // If no filesytem path was passed in, load assets from the classpath if (null == cmd.getStaticDir()) { LOG.debug("Loading static resources from the classpath"); homeHolder.setInitParameter("resourceBase", this.getClass().getClassLoader().getResource("public").toExternalForm()); } else { // use --staticDir ${project_loc}/src/main/resources/public as command args LOG.debug("Loading static resources from staticPath: {}", cmd.getStaticDir()); homeHolder.setInitParameter("resourceBase", cmd.getStaticDir().toAbsolutePath().toString()); } homeHolder.setInitParameter("dirAllowed", "true"); homeHolder.setInitParameter("pathInfoOnly", "true"); // homeHolder.setInitOrder(0); ServletContextHandler homeContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); homeContextHandler.addServlet(homeHolder, "/*"); return homeContextHandler; }
Example #6
Source File: ApiModule.java From attic-aurora with Apache License 2.0 | 6 votes |
@Override protected void configureServlets() { if (options.enableCorsFor != null) { filter(API_PATH).through(new CorsFilter(options.enableCorsFor)); } serve(API_PATH).with(TContentAwareServlet.class); filter(ApiBeta.PATH, ApiBeta.PATH + "/*").through(LeaderRedirectFilter.class); 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()); }
Example #7
Source File: TwootrServer.java From Real-World-Software-Development with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { var websocketAddress = new InetSocketAddress("localhost", WEBSOCKET_PORT); var twootrServer = new TwootrServer(websocketAddress); twootrServer.start(); System.setProperty("org.eclipse.jetty.LEVEL", "INFO"); var context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setResourceBase(System.getProperty("user.dir") + "/src/main/webapp"); context.setContextPath("/"); ServletHolder staticContentServlet = new ServletHolder( "staticContentServlet", DefaultServlet.class); staticContentServlet.setInitParameter("dirAllowed", "true"); context.addServlet(staticContentServlet, "/"); var jettyServer = new Server(STATIC_PORT); jettyServer.setHandler(context); jettyServer.start(); jettyServer.dumpStdErr(); jettyServer.join(); }
Example #8
Source File: ExplorerServer.java From Explorer with Apache License 2.0 | 6 votes |
/** * Handles the WebApplication for Swagger-ui * * @return WebAppContext with swagger ui context */ private static WebAppContext setupWebAppSwagger(ExplorerConfiguration conf) { WebAppContext webApp = new WebAppContext(); File webapp = new File(conf.getString(ExplorerConfiguration.ConfVars.EXPLORER_API_WAR)); if (webapp.isDirectory()) { webApp.setResourceBase(webapp.getPath()); } else { webApp.setWar(webapp.getAbsolutePath()); } webApp.setContextPath("/docs"); webApp.setParentLoaderPriority(true); // Bind swagger-ui to the path HOST/docs webApp.addServlet(new ServletHolder(new DefaultServlet()), "/docs/*"); return webApp; }
Example #9
Source File: ExplorerServer.java From Explorer with Apache License 2.0 | 6 votes |
private static WebAppContext setupWebAppContext(ExplorerConfiguration conf) { WebAppContext webApp = new WebAppContext(); File webapp = new File(conf.getString(ExplorerConfiguration.ConfVars.EXPLORER_WAR)); if (webapp.isDirectory()) { // Development mode, read from FS webApp.setDescriptor(webapp+"/WEB-INF/web.xml"); webApp.setResourceBase(webapp.getPath()); webApp.setContextPath("/"); webApp.setParentLoaderPriority(true); } else { //use packaged WAR webApp.setWar(webapp.getAbsolutePath()); } ServletHolder servletHolder = new ServletHolder(new DefaultServlet()); servletHolder.setInitParameter("cacheControl","private, max-age=0, must-revalidate"); webApp.addServlet(servletHolder, "/*"); return webApp; }
Example #10
Source File: EngineWebServer.java From phoebus with Eclipse Public License 1.0 | 6 votes |
public EngineWebServer(final int port) { // Configure Jetty to use java.util.logging, and don't announce that it's doing that System.setProperty("org.eclipse.jetty.util.log.announce", "false"); System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.JavaUtilLog"); server = new Server(port); final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS); // Our servlets context.addServlet(MainServlet.class, "/main/*"); context.addServlet(DisconnectedServlet.class, "/disconnected/*"); context.addServlet(GroupsServlet.class, "/groups/*"); context.addServlet(GroupServlet.class, "/group/*"); context.addServlet(ChannelServlet.class, "/channel/*"); context.addServlet(RestartServlet.class, "/restart/*"); context.addServlet(StopServlet.class, "/stop/*"); // Serve static files from webroot to "/" context.setContextPath("/"); context.setResourceBase(EngineWebServer.class.getResource("/webroot").toExternalForm()); context.addServlet(DefaultServlet.class, "/"); server.setHandler(context); }
Example #11
Source File: ScanWebServer.java From phoebus with Eclipse Public License 1.0 | 6 votes |
public ScanWebServer(final int port) { // Configure Jetty to use java.util.logging, and don't announce that it's doing that System.setProperty("org.eclipse.jetty.util.log.announce", "false"); System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.JavaUtilLog"); server = new Server(port); final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS); // Our servlets context.addServlet(ServerServlet.class, "/server/*"); context.addServlet(ScansServlet.class, "/scans/*"); context.addServlet(ScanServlet.class, "/scan/*"); context.addServlet(SimulateServlet.class, "/simulate/*"); // Serve static files from webroot to "/" context.setContextPath("/"); context.setResourceBase(ScanServerInstance.class.getResource("/webroot").toExternalForm()); context.addServlet(DefaultServlet.class, "/"); server.setHandler(context); }
Example #12
Source File: WebServletsDemo.java From phoebus with Eclipse Public License 1.0 | 6 votes |
public static void main(String[] args) throws Exception { final Server server = new Server(8080); final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS); // Our servlets context.addServlet(HelloServlet.class, "/hello"); context.addServlet(StopServlet.class, "/stop"); // Serve static files from webroot to "/" context.setContextPath("/"); context.setResourceBase(WebServletsDemo.class.getResource("/webroot").toExternalForm()); context.addServlet(DefaultServlet.class, "/"); server.setHandler(context); server.start(); System.out.println("Running web server, check http://localhost:8080, http://localhost:8080/hello"); do System.out.println("Main thread could do other things while web server is running..."); while (! done.await(5, TimeUnit.SECONDS)); server.stop(); server.join(); System.out.println("Done."); }
Example #13
Source File: RunApp.java From titan-web-example with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { System.out.println("Working directory: " + new File("./").getAbsolutePath().toString()); Server server = new Server(9091); WebAppContext context = new WebAppContext(); context.setDescriptor("/WEB-INF/web.xml"); context.setResourceBase("src/main/webapp"); context.setContextPath("/"); context.setParentLoaderPriority(true); context.addServlet(DefaultServlet.class, "/*"); server.setHandler(context); server.start(); server.join(); }
Example #14
Source File: ExplorerAppTest.java From Nicobar with Apache License 2.0 | 6 votes |
@BeforeClass public void init() throws Exception { System.setProperty("archaius.deployment.applicationId","scriptmanager-app"); System.setProperty("archaius.deployment.environment","dev"); server = new Server(TEST_LOCAL_PORT); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addEventListener(new KaryonGuiceContextListener()); context.addFilter(GuiceFilter.class, "/*", 1); context.addServlet(DefaultServlet.class, "/"); server.setHandler(context); server.start(); }
Example #15
Source File: VarOneServer.java From varOne with MIT License | 6 votes |
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; }
Example #16
Source File: BQInternalWebServerTestFactory.java From bootique with Apache License 2.0 | 6 votes |
@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; }
Example #17
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 #18
Source File: KuduSpanViewerServer.java From incubator-retired-htrace with Apache License 2.0 | 6 votes |
public int run(HTraceConfiguration conf) throws Exception { URI uri = new URI("http://" + 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); root.addServlet(new ServletHolder(new DefaultServlet()), "/"); root.addServlet(new ServletHolder(new KuduSpanViewerTracesServlet(conf)), "/gettraces"); root.addServlet(new ServletHolder(new KuduSpanViewerSpansServlet(conf)), "/getspans/*"); server.start(); server.join(); return 0; }
Example #19
Source File: Main.java From Jax-RS-Performance-Comparison with Apache License 2.0 | 6 votes |
public void run() throws Exception { final Server server = new Server(port); // Setup the basic Application "context" at "/". // This is also known as the handler tree (in Jetty speak). final ServletContextHandler context = new ServletContextHandler(server, CONTEXT_ROOT); // Setup RESTEasy's HttpServletDispatcher at "/api/*". final ServletHolder restEasyServlet = new ServletHolder(new HttpServletDispatcher()); restEasyServlet.setInitParameter("resteasy.servlet.mapping.prefix", "/"); restEasyServlet.setInitParameter("javax.ws.rs.Application", "com.colobu.rest.jaxrs.MyApplication"); context.addServlet(restEasyServlet, "/rest/*"); // Setup the DefaultServlet at "/". final ServletHolder defaultServlet = new ServletHolder(new DefaultServlet()); context.addServlet(defaultServlet, CONTEXT_ROOT); server.setHandler(context); server.start(); server.join(); }
Example #20
Source File: StatsServer.java From cxf with Apache License 2.0 | 6 votes |
public static void main(final String[] args) throws Exception { final Server server = new Server(8686); final ServletHolder staticHolder = new ServletHolder(new DefaultServlet()); final ServletContextHandler staticContext = new ServletContextHandler(); staticContext.setContextPath("/static"); staticContext.addServlet(staticHolder, "/*"); staticContext.setResourceBase(StatsServer.class.getResource("/web-ui").toURI().toString()); // Register and map the dispatcher servlet final CXFCdiServlet cxfServlet = new CXFCdiServlet(); final ServletHolder cxfServletHolder = new ServletHolder(cxfServlet); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addEventListener(new Listener()); context.addEventListener(new BeanManagerResourceBindingListener()); context.addServlet(cxfServletHolder, "/rest/*"); HandlerList handlers = new HandlerList(); handlers.addHandler(staticContext); handlers.addHandler(context); server.setHandler(handlers); server.start(); server.join(); }
Example #21
Source File: StatsServer.java From cxf with Apache License 2.0 | 6 votes |
public static void main(final String[] args) throws Exception { final Server server = new Server(8686); final ServletHolder staticHolder = new ServletHolder(new DefaultServlet()); final ServletContextHandler staticContext = new ServletContextHandler(); staticContext.setContextPath("/static"); staticContext.addServlet(staticHolder, "/*"); staticContext.setResourceBase(StatsServer.class.getResource("/web-ui").toURI().toString()); // Register and map the dispatcher servlet final ServletHolder cxfServletHolder = new ServletHolder(new CXFServlet()); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addEventListener(new ContextLoaderListener()); context.addServlet(cxfServletHolder, "/rest/*"); context.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); context.setInitParameter("contextConfigLocation", StatsConfig.class.getName()); HandlerList handlers = new HandlerList(); handlers.addHandler(staticContext); handlers.addHandler(context); server.setHandler(handlers); server.start(); server.join(); }
Example #22
Source File: EmbeddedJerseyModule.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Inject public EmbeddedServer(SimulatedCloudGateway gateway) { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); jettyServer = new Server(8099); jettyServer.setHandler(context); // Static content DefaultServlet staticContentServlet = new DefaultServlet(); ServletHolder holder = new ServletHolder(staticContentServlet); holder.setInitOrder(1); context.addServlet(holder, "/static/*"); context.setResourceBase(resolveStaticContentLocation()); // Jersey DefaultResourceConfig config = new DefaultResourceConfig(); config.getClasses().add(JsonMessageReaderWriter.class); config.getClasses().add(TitusExceptionMapper.class); config.getSingletons().add(new SimulatedAgentsServiceResource(gateway)); ServletHolder jerseyServlet = new ServletHolder(new ServletContainer(config)); jerseyServlet.setInitOrder(0); context.addServlet(jerseyServlet, "/cloud/*"); }
Example #23
Source File: TestContainerProcessManager.java From samza with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { server = new MockHttpServer("/", 7777, null, new ServletHolder(DefaultServlet.class)); CoordinatorStreamStoreTestUtil coordinatorStreamStoreTestUtil = new CoordinatorStreamStoreTestUtil(config); CoordinatorStreamStore coordinatorStreamStore = coordinatorStreamStoreTestUtil.getCoordinatorStreamStore(); coordinatorStreamStore.init(); containerPlacementMetadataStore = new ContainerPlacementMetadataStore(coordinatorStreamStore); containerPlacementMetadataStore.start(); }
Example #24
Source File: BaseJettyTest.java From zsync4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Before public void startJetty() throws Exception { this.server = new Server(0); ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.setContextPath("/"); servletContextHandler.setBaseResource(Resource.newClassPathResource(WEB_ROOT)); ServletHolder defaultServletHolder = new ServletHolder("default", DefaultServlet.class); defaultServletHolder.setInitParameter("acceptRanges", "true"); servletContextHandler.addServlet(defaultServletHolder, "/"); this.server.setHandler(servletContextHandler); this.server.start(); this.port = ((ServerConnector) this.server.getConnectors()[0]).getLocalPort(); }
Example #25
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 #26
Source File: WebServerModule.java From datacollector with Apache License 2.0 | 5 votes |
@Provides(type = Type.SET) ContextConfigurator provideMesosDir(final RuntimeInfo runtimeInfo) { return new ContextConfigurator() { @Override public void init(ServletContextHandler context) { ServletHolder servlet = new ServletHolder(new DefaultServlet()); // can't allow listing of dir as mesos dir will be hosting the jar file servlet.setInitParameter("dirAllowed", "false"); servlet.setInitParameter("resourceBase", runtimeInfo.getDataDir()); context.addServlet(servlet, "/mesos/*"); } }; }
Example #27
Source File: HttpServer.java From hbase with Apache License 2.0 | 5 votes |
/** * Add default apps. * @param appDir The application directory */ protected void addDefaultApps(ContextHandlerCollection parent, final String appDir, Configuration conf) { // set up the context for "/logs/" if "hadoop.log.dir" property is defined. String logDir = this.logDir; if (logDir == null) { logDir = System.getProperty("hadoop.log.dir"); } if (logDir != null) { ServletContextHandler logContext = new ServletContextHandler(parent, "/logs"); logContext.addServlet(AdminAuthorizedServlet.class, "/*"); logContext.setResourceBase(logDir); if (conf.getBoolean( ServerConfigurationKeys.HBASE_JETTY_LOGS_SERVE_ALIASES, ServerConfigurationKeys.DEFAULT_HBASE_JETTY_LOGS_SERVE_ALIASES)) { Map<String, String> params = logContext.getInitParams(); params.put( "org.mortbay.jetty.servlet.Default.aliases", "true"); } logContext.setDisplayName("logs"); setContextAttributes(logContext, conf); defaultContexts.put(logContext, true); } // set up the context for "/static/*" ServletContextHandler staticContext = new ServletContextHandler(parent, "/static"); staticContext.setResourceBase(appDir + "/static"); staticContext.addServlet(DefaultServlet.class, "/*"); staticContext.setDisplayName("static"); setContextAttributes(staticContext, conf); defaultContexts.put(staticContext, true); }
Example #28
Source File: HttpServer2.java From knox with Apache License 2.0 | 5 votes |
private static WebAppContext createWebAppContext(Builder b, AccessControlList adminsAcl, final String appDir) { WebAppContext ctx = new WebAppContext(); ctx.setDefaultsDescriptor(null); ServletHolder holder = new ServletHolder(new DefaultServlet()); Map<String, String> params = ImmutableMap. <String, String> builder() .put("acceptRanges", "true") .put("dirAllowed", "false") .put("gzip", "true") .put("useFileMappedBuffer", "true") .build(); holder.setInitParameters(params); ctx.setWelcomeFiles(new String[] {"index.html"}); ctx.addServlet(holder, "/"); ctx.setDisplayName(b.name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + b.name); String tempDirectory = b.conf.get(HTTP_TEMP_DIR_KEY); if (tempDirectory != null && !tempDirectory.isEmpty()) { ctx.setTempDirectory(new File(tempDirectory)); ctx.setAttribute("javax.servlet.context.tempdir", tempDirectory); } ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, b.conf); ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); addNoCacheFilter(ctx); return ctx; }
Example #29
Source File: ServerRpcProvider.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
public void addWebSocketServlets() { // Servlet where the websocket connection is served from. ServletHolder wsholder = addServlet("/socket", WaveWebSocketServlet.class); // TODO(zamfi): fix to let messages span frames. wsholder.setInitParameter("bufferSize", "" + BUFFER_SIZE); // Serve the static content and GWT web client with the default servlet // (acts like a standard file-based web server). addServlet("/static/*", DefaultServlet.class); addServlet("/webclient/*", DefaultServlet.class); }
Example #30
Source File: PaasLauncher.java From staash with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { LOG.info("Starting PAAS"); // Create the server. Server server = new Server(DEFAULT_PORT); // Create a servlet context and add the jersey servlet. ServletContextHandler sch = new ServletContextHandler(server, "/"); // Add our Guice listener that includes our bindings sch.addEventListener(new PaasGuiceServletConfig()); // Then add GuiceFilter and configure the server to // reroute all requests through this filter. sch.addFilter(GuiceFilter.class, "/*", null); // Must add DefaultServlet for embedded Jetty. // Failing to do this will cause 404 errors. // This is not needed if web.xml is used instead. sch.addServlet(DefaultServlet.class, "/"); // Start the server server.start(); server.join(); LOG.info("Stopping PAAS"); }