Java Code Examples for org.eclipse.jetty.webapp.WebAppContext#setWelcomeFiles()
The following examples show how to use
org.eclipse.jetty.webapp.WebAppContext#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: HttpBindManager.java From Openfire with Apache License 2.0 | 6 votes |
/** * Creates a Jetty context handler that can be used to expose static files. * * Note that an invocation of this method will not register the handler (and thus make the related functionality * available to the end user). Instead, the created handler is returned by this method, and will need to be * registered with the embedded Jetty webserver by the caller. * * @return A Jetty context handler, or null when the static content could not be accessed. */ protected Handler createStaticContentHandler() { final File spankDirectory = new File( JiveGlobals.getHomeDirectory() + File.separator + "resources" + File.separator + "spank" ); if ( spankDirectory.exists() ) { if ( spankDirectory.canRead() ) { final WebAppContext context = new WebAppContext( null, spankDirectory.getPath(), "/" ); context.setWelcomeFiles( new String[] { "index.html" } ); return context; } else { Log.warn( "Openfire cannot read the directory: " + spankDirectory ); } } return null; }
Example 2
Source File: HttpServer2.java From hadoop-ozone 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 3
Source File: HttpServer2.java From lucene-solr 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 4
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 5
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 6
Source File: WebServerTools.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
public static Server start(WebServer webServer) throws Exception { /** * 更新x_desktop的center指向 */ updateCenterConfigJson(); /** * 更新 favicon.ico */ updateFavicon(); /** * 创建index.html */ createIndexPage(); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(WEBSERVER_THREAD_POOL_SIZE_MIN); threadPool.setMaxThreads(WEBSERVER_THREAD_POOL_SIZE_MAX); Server server = new Server(threadPool); if (webServer.getSslEnable()) { addHttpsConnector(server, webServer.getPort()); } else { addHttpConnector(server, webServer.getPort()); } WebAppContext context = new WebAppContext(); context.setContextPath("/"); context.setBaseResource(Resource.newResource(new File(Config.base(), "servers/webServer"))); // context.setResourceBase("."); context.setParentLoaderPriority(true); context.setExtractWAR(false); // context.setDefaultsDescriptor(new File(Config.base(), // "commons/webdefault_w.xml").getAbsolutePath()); context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "" + webServer.getDirAllowed()); context.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); if (webServer.getCacheControlMaxAge() > 0) { context.setInitParameter("org.eclipse.jetty.servlet.Default.cacheControl", "max-age=" + webServer.getCacheControlMaxAge()); } context.setInitParameter("org.eclipse.jetty.servlet.Default.maxCacheSize", "256000000"); context.setInitParameter("org.eclipse.jetty.servlet.Default.maxCachedFileSize", "200000000"); context.setWelcomeFiles(new String[] { "default.html", "index.html" }); context.setGzipHandler(new GzipHandler()); context.setParentLoaderPriority(true); context.getMimeTypes().addMimeMapping("wcss", "application/json"); /* stat */ if (webServer.getStatEnable()) { FilterHolder statFilterHolder = new FilterHolder(new WebStatFilter()); statFilterHolder.setInitParameter("exclusions", webServer.getStatExclusions()); context.addFilter(statFilterHolder, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletHolder statServletHolder = new ServletHolder(StatViewServlet.class); statServletHolder.setInitParameter("sessionStatEnable", "false"); context.addServlet(statServletHolder, "/druid/*"); } /* stat end */ server.setHandler(context); server.setDumpAfterStart(false); server.setDumpBeforeStop(false); server.setStopAtShutdown(true); server.start(); context.setMimeTypes(Config.mimeTypes()); System.out.println("****************************************"); System.out.println("* web server start completed."); System.out.println("* port: " + webServer.getPort() + "."); System.out.println("****************************************"); return server; }
Example 7
Source File: ServerLauncher.java From bromium with MIT License | 4 votes |
public static void main(final String[] args) { InetSocketAddress _inetSocketAddress = new InetSocketAddress("localhost", 8080); final Server server = new Server(_inetSocketAddress); WebAppContext _webAppContext = new WebAppContext(); final Procedure1<WebAppContext> _function = (WebAppContext it) -> { it.setResourceBase("WebRoot"); it.setWelcomeFiles(new String[] { "index.html" }); it.setContextPath("/"); AnnotationConfiguration _annotationConfiguration = new AnnotationConfiguration(); WebXmlConfiguration _webXmlConfiguration = new WebXmlConfiguration(); WebInfConfiguration _webInfConfiguration = new WebInfConfiguration(); MetaInfConfiguration _metaInfConfiguration = new MetaInfConfiguration(); it.setConfigurations(new Configuration[] { _annotationConfiguration, _webXmlConfiguration, _webInfConfiguration, _metaInfConfiguration }); it.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, ".*/com\\.hribol\\.bromium\\.dsl\\.web/.*,.*\\.jar"); it.setInitParameter("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false"); }; WebAppContext _doubleArrow = ObjectExtensions.<WebAppContext>operator_doubleArrow(_webAppContext, _function); server.setHandler(_doubleArrow); String _name = ServerLauncher.class.getName(); final Slf4jLog log = new Slf4jLog(_name); try { server.start(); URI _uRI = server.getURI(); String _plus = ("Server started " + _uRI); String _plus_1 = (_plus + "..."); log.info(_plus_1); final Runnable _function_1 = () -> { try { log.info("Press enter to stop the server..."); final int key = System.in.read(); if ((key != (-1))) { server.stop(); } else { log.warn("Console input is not available. In order to stop the server, you need to cancel process manually."); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; new Thread(_function_1).start(); server.join(); } catch (final Throwable _t) { if (_t instanceof Exception) { final Exception exception = (Exception)_t; log.warn(exception.getMessage()); System.exit(1); } else { throw Exceptions.sneakyThrow(_t); } } }