/** * Set the war of the webapp as a {@link Resource}. * @see #setWar(String) * @param war The war to set as a Resource. */ public void setWarResource(Resource war) { setWar(war==null?null:war.toString()); }
/** * @param contextPath The context path * @param webApp The URL or filename of the webapp directory or war file. */ public WebAppContext(String webApp,String contextPath) { this(null,contextPath,null,null,null,new ErrorPageErrorHandler(),SESSIONS|SECURITY); setWar(webApp); }
/** * @param parent The parent HandlerContainer. * @param contextPath The context path * @param webApp The URL or filename of the webapp directory or war file. */ public WebAppContext(HandlerContainer parent, String webApp, String contextPath) { this(parent,contextPath,null,null,null,new ErrorPageErrorHandler(),SESSIONS|SECURITY); setWar(webApp); }
private static void startServer() throws Exception { File warFile = findWar(); server = new Server(8080); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setWar(warFile.getAbsolutePath()); server.setHandler(webapp); server.start(); eurekaServiceUrl = "http://localhost:8080/v2"; }
/** * Create the web context for the application of specified name */ WebAppContext createWebAppContext(Builder b) { WebAppContext ctx = new WebAppContext(); setContextAttributes(ctx.getServletContext(), b.contextAttrs); ctx.setDisplayName(b.name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + b.name); return ctx; }
bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp");
webapp.setWar(warFilePath); webapp.setParentLoaderPriority(false); webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
private WebAppContext createWebAppContext() { webAppContext = new WebAppContext(); webAppContext.setDefaultsDescriptor(GoWebXmlConfiguration.configuration(getWarFile())); webAppContext.setConfigurationClasses(new String[]{ WebInfConfiguration.class.getCanonicalName(), WebXmlConfiguration.class.getCanonicalName(), JettyWebXmlConfiguration.class.getCanonicalName() }); webAppContext.setContextPath(systemEnvironment.getWebappContextPath()); // delegate all logging to parent classloader to avoid initialization of loggers in multiple classloaders webAppContext.addSystemClass("org.apache.log4j."); webAppContext.addSystemClass("org.slf4j."); webAppContext.addSystemClass("org.apache.commons.logging."); webAppContext.setWar(getWarFile()); webAppContext.setParentLoaderPriority(systemEnvironment.getParentLoaderPriority()); return webAppContext; }
Server server = new Server(); // Note: if you don't want control over type of connector, etc. you can simply // call new Server(<port>); ServerConnector connector = new ServerConnector(server); connector.setHost("0.0.0.0"); connector.setPort(8085); // Setting the name allows you to serve different app contexts from different connectors. connector.setName("main"); server.addConnector(connector); WebAppContext context = new WebAppContext(); context.setContextPath("/"); // For development within an IDE like Eclipse, you can directly point to the web.xml context.setWar("src/main/webapp"); context.addFilter(MyFilter.class, "/", 1); HandlerCollection collection = new HandlerCollection(); RequestLogHandler rlh = new RequestLogHandler(); // Slf4j - who uses anything else? Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setExtended(false); rlh.setRequestLog(requestLog); collection.setHandlers(new Handler[] { context, rlh }); server.setHandler(collection); try { server.start(); server.join(); } catch (Exception e) { // Google guava way throw Throwables.propagate(e); }
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; }
private static WebAppContext createWebAppContext(String name, Configuration conf, AccessControlList adminsAcl, final String appDir) { WebAppContext ctx = new WebAppContext(); ctx.setDisplayName(name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + name); ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf); // for org.apache.hadoop.metrics.MetricsServlet ctx.getServletContext().setAttribute( org.apache.hadoop.http.HttpServer2.CONF_CONTEXT_ATTRIBUTE, conf); ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); addNoCacheFilter(ctx); return ctx; }
private WebAppContext createDeployedApplicationInstance(File workDirectory, String deployedApplicationPath) { WebAppContext deployedApplication = new WebAppContext(); deployedApplication.setContextPath(this.getContextPath()); deployedApplication.setWar(deployedApplicationPath); deployedApplication.setAttribute("javax.servlet.context.tempdir", workDirectory.getAbsolutePath()); deployedApplication .setAttribute( "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$"); deployedApplication.setAttribute( "org.eclipse.jetty.containerInitializers", jspInitializers()); deployedApplication.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager()); deployedApplication.addBean(new ServletContainerInitializersStarter( deployedApplication), true); // webapp.setClassLoader(new URLClassLoader(new // URL[0],App.class.getClassLoader())); deployedApplication.addServlet(jspServletHolder(), "*.jsp"); return deployedApplication; }
webapp.setWar("/"); // Appropriate file system path.
ctx.setWar(webapp); ctx.setServer(server);
WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setWar(warURL); server.setHandler(webapp);
Server server = new Server( port ); WebAppContext root = new WebAppContext(); root.setWar("/path/to/somewhere"); root.setContextPath("/"); server.addHandler( root ); server.start();
WebAppContext root = new WebAppContext(); root.setAllowDuplicateFragmentNames(true); root.setWar(tempWarFile.getAbsolutePath()); root.setParentLoaderPriority(true); root.setContextPath("/");
private HandlerCollection createHandlers() { final WebAppContext webApp = new WebAppContext(); webApp.setContextPath(contextPath); webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); webApp.getSessionHandler().setMaxInactiveInterval(sessionTimeout * 60); // GZIP handler final GzipHandler gzipHandler = new GzipHandler(); gzipHandler.addIncludedMimeTypes("text/html", "text/xml", "text/css", "text/plain", "text/javascript", "application/javascript", "application/json", "application/xml"); gzipHandler.setIncludedMethods("GET", "POST"); gzipHandler.setCompressionLevel(9); gzipHandler.setHandler(webApp); if (Strings.isNullOrEmpty(webAppLocation)) { webApp.setWar(getShadedWarUrl()); } else { webApp.setWar(webAppLocation); } // Request log handler final RequestLogHandler log = new RequestLogHandler(); log.setRequestLog(createRequestLog()); // Redirect root context handler MovedContextHandler rootRedirect = new MovedContextHandler(); rootRedirect.setContextPath("/"); rootRedirect.setNewContextURL(contextPath); rootRedirect.setPermanent(true); // Put rootRedirect at the end! return new HandlerCollection(log, gzipHandler, rootRedirect); }
private WebAppContext deployWar(String url, String warFile, Path warDirectory) throws IOException { WebAppContext webapp = new WebAppContext(); if (url.startsWith("/")) { webapp.setContextPath(url); } else { webapp.setContextPath("/" + url); } webapp.setWar(warDirectory.resolve(warFile).toString()); handlers.addHandler(webapp); return webapp; }
/** * Create the web context for the application of specified name */ WebAppContext createWebAppContext(Builder b) { WebAppContext ctx = new WebAppContext(); setContextAttributes(ctx.getServletContext(), b.contextAttrs); ctx.setDisplayName(b.name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + b.name); return ctx; }