ctx.setResources(new ArmeriaWebResourceRoot(ctx, config));
protected void postProcessContext(Context context) { final int cacheSize = 100 * 1024 * 1024; StandardRoot standardRoot = new StandardRoot(context); standardRoot.setCacheMaxSize(cacheSize); standardRoot.setCacheObjectMaxSize(Integer.MAX_VALUE / 1024); context.setResources(standardRoot); } };
@Override public void lifecycleEvent(LifecycleEvent event) { if (event.getType().equals(Lifecycle.BEFORE_START_EVENT)) { Context context = (Context) event.getLifecycle(); WebResourceRoot resources = context.getResources(); if (resources == null) { resources = new StandardRoot(context); context.setResources(resources); } // 使用embedded tomcat时 WEB-INF放在了classpath下 URL resource = context.getParentClassLoader().getResource(Constants.WEB_INF); if (resource != null) { String webXmlUrlString = resource.toString(); try { URL root = new URL( webXmlUrlString.substring(0, webXmlUrlString.length() - Constants.WEB_INF.length())); resources.createWebResourceSet(ResourceSetType.RESOURCE_JAR, Constants.WEB_INF_PATH, root, Constants.WEB_INF_PATH); } catch (MalformedURLException e) { // ignore } } } } }
@Override public void lifecycleEvent(LifecycleEvent event) { if (event.getType().equals(Lifecycle.BEFORE_START_EVENT)) { Context context = (Context) event.getLifecycle(); WebResourceRoot resources = context.getResources(); if (resources == null) { resources = new StandardRoot(context); context.setResources(resources); } /** * <pre> * when run as embeded tomcat, context.getParentClassLoader() is AppClassLoader, * so it can load "WEB-INF/web.xml" from app classpath. * </pre> */ URL resource = context.getParentClassLoader().getResource("WEB-INF/web.xml"); if (resource != null) { String webXmlUrlString = resource.toString(); URL root; try { root = new URL(webXmlUrlString.substring(0, webXmlUrlString.length() - "WEB-INF/web.xml".length())); resources.createWebResourceSet(ResourceSetType.RESOURCE_JAR, "/WEB-INF", root, "/WEB-INF"); } catch (MalformedURLException e) { // ignore } } } }
@Override public void run() { try { try (final Meecrowave meecrowave = new Meecrowave(create(args)) { @Override protected Connector createConnector() { return new Connector(CustomPefixHttp11NioProtocol.class.getName()); } }) { this.instance = meecrowave; meecrowave.start(); meecrowave.deployClasspath(new Meecrowave.DeploymentMeta("", null, stdCtx -> { stdCtx.setResources(new StandardRoot() { @Override protected void registerURLStreamHandlerFactory() { // no-op: not supported into OSGi since there is already one and it must set a // single time } }); })); doWait(meecrowave, null); } } catch (final Exception e) { throw new IllegalStateException(e); } }
try (final Meecrowave meecrowave = new Meecrowave(Cli.create(buildArgs()))) { meecrowave.start().deployClasspath(new Meecrowave.DeploymentMeta("", null, stdCtx -> { stdCtx.setResources(new StandardRoot() {
); context.setResources(root);
context.setResources( new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath() ) );
context.setResources( new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath(), //
/** * @see #addWebapp(String, String) */ public Context addWebapp(Host host, String contextPath, String docBase, ContextConfig config) { Context ctx = createContext(host, contextPath); ctx.setPath(contextPath); ctx.setDocBase(docBase); ctx.addLifecycleListener(new DefaultWebXmlListener()); ctx.setConfigFile(getWebappConfigFile(docBase, contextPath)); ctx.addLifecycleListener(config); // prevent it from looking ( if it finds one - it'll have dup error ) config.setDefaultWebXml(noDefaultWebXmlPath()); // get the host first, creates a new std host if not already set getHost(); // reset ParentClassLoader if (!host.getParentClassLoader().equals(Thread.currentThread().getContextClassLoader())) { host.setParentClassLoader(Thread.currentThread().getContextClassLoader()); } StandardRoot standardRoot = new StandardRoot(ctx); standardRoot.setCacheMaxSize(cacheMaxSize); ctx.setResources(standardRoot); // add the context host.addChild(ctx); return ctx; }
context.setResources( new MyDirContext( new File( project.getBuild().getOutputDirectory() ).getAbsolutePath(), //
MultipleDirContext dirContext = new MultipleDirContext(); dirContext.setVirtualDocBase(resources); context.setResources(dirContext);
/** * @param context the context to configure * @throws IOException an IO Exception * @throws ServletException a Servlet Exception */ protected void configWebApp(final Context context) throws IOException, ServletException { final String libDir = getLibDir(); final String classesDir = getClassesDir(); configJarScanner(context); WebResourceRoot resources = new StandardRoot(context); context.setResources(resources); // Declare an alternative location for the "WEB-INF/lib" dir if (libDir != null && !libDir.isEmpty()) { resources.addPreResources(new DirResourceSet(resources, Constants.WEB_INF_LIB, libDir, "/")); } // Declare an alternative location for the "WEB-INF/classes" dir if (classesDir != null && !classesDir.isEmpty()) { resources.addPreResources(new DirResourceSet(resources, Constants.WEB_INF_CLASSES, classesDir, "/")); } // Stop persistent sessions StandardManager mgr = new StandardManager(); mgr.setPathname(null); context.setManager(mgr); // Delay for requets to stop processing in milliseconds ((StandardContext) context).setUnloadDelay(10000); }
context.setResources((javax.naming.directory.DirContext)TomcatService.getInstance(contextMetaData.getResources(), "org.apache.naming.resources.FileDirContext"));
webRoot.setCacheMaxSize(100000); webRoot.setCachingAllowed(true); context.setResources(webRoot);
"/WEB-INF/classes", "./target/classes", "/"); resourceRoot.addPreResources(dirResource); ctx.setResources(resourceRoot);