/** * Set a value in the webapp context. These values are available to the jsp * pages as "application.getAttribute(name)". * @param name The name of the attribute * @param value The value of the attribute */ public void setAttribute(String name, Object value) { webAppContext.setAttribute(name, value); }
/** * Set a value in the webapp context. These values are available to the jsp * pages as "application.getAttribute(name)". * @param name The name of the attribute * @param value The value of the attribute */ public void setAttribute(String name, Object value) { webAppContext.setAttribute(name, value); }
@Override public void postConfigure(WebAppContext context) throws Exception { context.setAttribute(FRAGMENT_RESOURCES, null); }
@Override public void postConfigure(WebAppContext context) throws Exception { context.setAttribute(METAINF_RESOURCES, null); context.setAttribute(METAINF_FRAGMENTS, null); context.setAttribute(METAINF_TLDS, null); }
/** Set temporary directory for context. * The javax.servlet.context.tempdir attribute is also set. * @param dir Writable temporary directory. */ public void setTempDirectory(File dir) { if (isStarted()) throw new IllegalStateException("Started"); if (dir!=null) { try{dir=new File(dir.getCanonicalPath());} catch (IOException e){LOG.warn(Log.EXCEPTION,e);} } _tmpDir=dir; setAttribute(TEMPDIR,_tmpDir); }
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; }
private void createWebAppContext() { contexts = new ContextHandlerCollection(); WebAppContext context; // Add web-app. Check to see if we're in development mode. If so, we don't // add the normal web-app location, but the web-app in the project directory. boolean developmentMode = Boolean.getBoolean("developmentMode"); if( developmentMode ) { System.out.println(LocaleUtils.getLocalizedString("admin.console.devmode")); context = new WebAppContext(contexts, pluginDir.getParentFile().getParentFile().getParentFile().getParent() + File.separator + "src" + File.separator + "web", "/"); } else { context = new WebAppContext(contexts, pluginDir.getAbsoluteFile() + File.separator + "webapp", "/"); } // Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs). final List<ContainerInitializer> initializers = new ArrayList<>(); initializers.add(new ContainerInitializer(new JasperInitializer(), null)); context.setAttribute("org.eclipse.jetty.containerInitializers", initializers); context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager()); // The index.html includes a redirect to the index.jsp and doesn't bypass // the context security when in development mode context.setWelcomeFiles(new String[]{"index.html"}); // Make sure the context initialization is done when in development mode if( developmentMode ) { context.addBean( new ServletContainerInitializersStarter( context ), true ); } }
.forEach(p -> webapp.setAttribute(p.getKey(), p.getValue()));
webappContext.setAttribute(CONTAINER_INCLUDE_PATTERN_KEY, CONTAINER_INCLUDE_PATTERN_VALUE);
ClassList clist = ClassList.setServerDefault(server); clist.addBefore(JettyWebXmlConfiguration.class.getName(), AnnotationConfiguration.class.getName()); servletContextHandler.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*(/target/classes/|.*.jar)"); servletContextHandler.setParentLoaderPriority(true); servletContextHandler.setInitParameter("useFileMappedBuffer", "false"); servletContextHandler.setAttribute("globalProps", globalProps);
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; }
@Override public void preConfigure(final WebAppContext context) throws Exception { boolean useContainerCache = DEFAULT_USE_CONTAINER_METAINF_CACHE; if (context.getServer() != null) { Boolean attr = (Boolean)context.getServer().getAttribute(USE_CONTAINER_METAINF_CACHE); if (attr != null) useContainerCache = attr.booleanValue(); } if (LOG.isDebugEnabled()) LOG.debug("{} = {}", USE_CONTAINER_METAINF_CACHE, useContainerCache); //pre-emptively create empty lists for tlds, fragments and resources as context attributes //this signals that this class has been called. This differentiates the case where this class //has been called but finds no META-INF data from the case where this class was never called if (context.getAttribute(METAINF_TLDS) == null) context.setAttribute(METAINF_TLDS, new HashSet<URL>()); if (context.getAttribute(METAINF_RESOURCES) == null) context.setAttribute(METAINF_RESOURCES, new HashSet<Resource>()); if (context.getAttribute(METAINF_FRAGMENTS) == null) context.setAttribute(METAINF_FRAGMENTS, new HashMap<Resource, Resource>()); //always scan everything from the container's classpath scanJars(context, context.getMetaData().getContainerResources(), useContainerCache, __allScanTypes); //only look for fragments if web.xml is not metadata complete, or it version 3.0 or greater List<String> scanTypes = new ArrayList<>(__allScanTypes); if (context.getMetaData().isMetaDataComplete() || (context.getServletContext().getEffectiveMajorVersion() < 3) && !context.isConfigurationDiscovered()) scanTypes.remove(METAINF_FRAGMENTS); scanJars(context, context.getMetaData().getWebInfJars(), false, scanTypes); }
context.setAttribute(TEMPDIR_CONFIGURED, Boolean.TRUE); //the tmp dir was set explicitly return; configureTempDirectory(tmpDir, context); context.setAttribute(WebAppContext.TEMPDIR,tmpDir);
context.setAttribute(METAINF_TLDS, metaInfTlds);
static WebAppContext newWebAppContext() throws MalformedURLException { final WebAppContext handler = new WebAppContext(); handler.setContextPath("/"); handler.setBaseResource(Resource.newResource(webAppRoot())); handler.setClassLoader(new URLClassLoader( new URL[] { Resource.newResource(new File(webAppRoot(), "WEB-INF" + File.separatorChar + "lib" + File.separatorChar + "hello.jar")).getURI().toURL() }, JettyService.class.getClassLoader())); handler.addBean(new ServletContainerInitializersStarter(handler), true); handler.setAttribute( "org.eclipse.jetty.containerInitializers", Collections.singletonList(new ContainerInitializer(new JettyJasperInitializer(), null))); return handler; }
context.setAttribute(METAINF_FRAGMENTS, fragments);
orderedLibs.add(fullname.substring(j+1,i+4)); context.setAttribute(ServletContext.ORDERED_LIBS, orderedLibs);
context.setAttribute(METAINF_RESOURCES, dirs);
webAppContext.setConfigurations(new Configuration[] { new WebXmlConfiguration(), new AnnotationConfiguration() { @Override public void preConfigure(WebAppContext context) throws Exception { MultiMap<String> map = new MultiMap<String>(); map.add(WebApplicationInitializer.class.getName(), MyWebApplicationInitializerImpl.class.getName()); context.setAttribute(CLASS_INHERITANCE_MAP, map); _classInheritanceHandler = new ClassInheritanceHandler(map); } } });
public void startStandAlone() { try { WebAppContext context = new WebAppContext(); String baseUrl = getBaseUrl(); LOGGER.info("Metric server baseUrl: " + baseUrl); context.setDescriptor(baseUrl + "/WEB-INF/web.xml"); context.setResourceBase(baseUrl); context.setContextPath("/"); context.setParentLoaderPriority(true); context.setAttribute("JetStreamRoot", applicationContext); Server s_server = new Server(s_port); s_server.setHandler(context); LOGGER.info( "Metric server started, listening on port " + s_port); s_server.start(); running.set(true); } catch (Throwable t) { throw CommonUtils.runtimeException(t); } }