org.apache.catalina.WebResourceRoot Java Examples

The following examples show how to use org.apache.catalina.WebResourceRoot. 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: ApplicationContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public Set<String> getResourcePaths(String path) {

    // Validate the path argument
    if (path == null) {
        return null;
    }
    if (!path.startsWith("/")) {
        throw new IllegalArgumentException (sm.getString("applicationContext.resourcePaths.iae", path));
    }

    WebResourceRoot resources = context.getResources();
    if (resources != null) {
        return resources.listWebAppPaths(path);
    }

    return null;
}
 
Example #2
Source File: FileResource.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public FileResource(WebResourceRoot root, String webAppPath,
        File resource, boolean readOnly, Manifest manifest) {
    super(root,webAppPath);
    this.resource = resource;

    if (webAppPath.charAt(webAppPath.length() - 1) == '/') {
        String realName = resource.getName() + '/';
        if (webAppPath.endsWith(realName)) {
            name = resource.getName();
        } else {
            // This is the root directory of a mounted ResourceSet
            // Need to return the mounted name, not the real name
            int endOfName = webAppPath.length() - 1;
            name = webAppPath.substring(
                    webAppPath.lastIndexOf('/', endOfName - 1) + 1,
                    endOfName);
        }
    } else {
        // Must be a file
        name = resource.getName();
    }

    this.readOnly = readOnly;
    this.manifest = manifest;
    this.needConvert = PROPERTIES_NEED_CONVERT && name.endsWith(".properties");
}
 
Example #3
Source File: TomcatWebAppBuilder.java    From tomee with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void destroy(final StandardContext standardContext) {
    final Loader standardContextLoader = standardContext.getLoader();
    if (LazyStopLoader.class.isInstance(standardContextLoader)) {
        final Loader delegate = LazyStopLoader.class.cast(standardContextLoader).getDelegateLoader();
        if (TomEEWebappLoader.class.isInstance(delegate)) {
            final TomEEWebappLoader webappLoader = TomEEWebappLoader.class.cast(delegate);
            final ClassLoader loader = webappLoader.internalLoader();
            webappLoader.clearLoader();
            if (TomEEWebappClassLoader.class.isInstance(loader)) {
                TomEEWebappClassLoader.class.cast(loader).internalDestroy();
            }
        }
    }

    final WebResourceRoot root = standardContext.getResources();
    if (LazyStopStandardRoot.class.isInstance(root)) {
        try {
            LazyStopStandardRoot.class.cast(root).internalDestroy();
        } catch (final LifecycleException e) {
            throw new IllegalStateException(e);
        }
    }
}
 
Example #4
Source File: JsfTomcatApplicationListenerIT.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@Test
public void jarResourcesNull() {
	Context standardContext = mock(Context.class);
	WebResourceRoot webResourceRoot = mock(WebResourceRoot.class);
	Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
	Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);
	Mockito.when(webResourceRoot.getJarResources()).thenReturn(null);

	JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
	jsfTomcatContextCustomizer.customize(standardContext);

	JsfTomcatApplicationListener jsfTomcatApplicationListener = new JsfTomcatApplicationListener(jsfTomcatContextCustomizer.getContext());
	jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));

	assertThat(jsfTomcatApplicationListener)
		.isNotNull();
}
 
Example #5
Source File: JarResourceRoot.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public JarResourceRoot(WebResourceRoot root, File base, String baseUrl,
        String webAppPath) {
    super(root, webAppPath);
    // Validate the webAppPath before going any further
    if (!webAppPath.endsWith("/")) {
        throw new IllegalArgumentException(sm.getString(
                "jarResourceRoot.invalidWebAppPath", webAppPath));
    }
    this.base = base;
    this.baseUrl = "jar:" + baseUrl;
    // Extract the name from the webAppPath
    // Strip the trailing '/' character
    String resourceName = webAppPath.substring(0, webAppPath.length() - 1);
    int i = resourceName.lastIndexOf('/');
    if (i > -1) {
        resourceName = resourceName.substring(i + 1);
    }
    name = resourceName;
}
 
Example #6
Source File: TomcatConfig.java    From find with MIT License 6 votes vote down vote up
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    final TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();

    if(useReverseProxy) {
        tomcat.addAdditionalTomcatConnectors(createAjpConnector());
    }

    // Set the web resources cache size (this defaults to 10MB but that is too small for Find)
    tomcat.addContextCustomizers(context -> {
        final WebResourceRoot resources = new StandardRoot(context);
        resources.setCacheMaxSize(webResourcesCacheSize);
        context.setResources(resources);
    });

    tomcat.addConnectorCustomizers(connector -> {
        connector.setMaxPostSize(connectorMaxPostSize);
    });

    return tomcat;
}
 
Example #7
Source File: JsfTomcatApplicationListener.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
/**
 * Inform tomcat runtime setup. UNPACKAGED_WAR not covered yet.
 * @param resources of the tomcat
 * @return tomcat runtime
 */
TomcatRuntime getTomcatRuntime(WebResourceRoot resources) {
	TomcatRuntime result = null;

	if (isUberJar(resources)) {
		result = TomcatRuntime.UBER_JAR;
	}
	else if (isUberWar(resources)) {
		result = TomcatRuntime.UBER_WAR;
	}
	else if (isTesting(resources)) {
		result = TomcatRuntime.TEST;
	}
	else if (isUnpackagedJar(resources)) {
		result = TomcatRuntime.UNPACKAGED_JAR;
	}

	return result;
}
 
Example #8
Source File: ApplicationContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public URL getResource(String path) throws MalformedURLException {

    String validatedPath = validateResourcePath(path, false);

    if (validatedPath == null) {
        throw new MalformedURLException(
                sm.getString("applicationContext.requestDispatcher.iae", path));
    }

    WebResourceRoot resources = context.getResources();
    if (resources != null) {
        return resources.getResource(validatedPath).getURL();
    }

    return null;
}
 
Example #9
Source File: ApplicationContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public InputStream getResourceAsStream(String path) {

    String validatedPath = validateResourcePath(path, false);

    if (validatedPath == null) {
        return null;
    }

    WebResourceRoot resources = context.getResources();
    if (resources != null) {
        return resources.getResource(validatedPath).getInputStream();
    }

    return null;
}
 
Example #10
Source File: DirResourceSet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public WebResource getResource(String path) {
    checkPath(path);
    String webAppMount = getWebAppMount();
    WebResourceRoot root = getRoot();
    if (path.startsWith(webAppMount)) {
        File f = file(path.substring(webAppMount.length()), false);
        if (f == null) {
            return new EmptyResource(root, path);
        }
        if (!f.exists()) {
            return new EmptyResource(root, path, f);
        }
        if (f.isDirectory() && path.charAt(path.length() - 1) != '/') {
            path = path + '/';
        }
        return new FileResource(root, path, f, isReadOnly(), getManifest());
    } else {
        return new EmptyResource(root, path);
    }
}
 
Example #11
Source File: TestDirResourceSetVirtual.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public WebResourceRoot getWebResourceRoot() {
    TesterWebResourceRoot root = new TesterWebResourceRoot();
    WebResourceSet webResourceSet =
            new DirResourceSet(new TesterWebResourceRoot(), "/",
                    getBaseDir().getAbsolutePath(), "/");
    root.setMainResources(webResourceSet);

    WebResourceSet f1 = new FileResourceSet(root, "/f1.txt",
            dir1.getAbsolutePath() + "/f1.txt", "/");
    root.addPreResources(f1);

    WebResourceSet f2 = new FileResourceSet(root, "/f2.txt",
            dir1.getAbsolutePath() + "/f2.txt", "/");
    root.addPreResources(f2);

    WebResourceSet d1 = new DirResourceSet(root, "/d1",
            dir1.getAbsolutePath() + "/d1", "/");
    root.addPreResources(d1);

    WebResourceSet d2 = new DirResourceSet(root, "/d2",
            dir1.getAbsolutePath() + "/d2", "/");
    root.addPreResources(d2);

    return root;
}
 
Example #12
Source File: ResolverImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public boolean resolveResource(int type, String name) {
    WebResourceRoot resources = request.getContext().getResources();
    WebResource resource = resources.getResource(name);
    if (!resource.exists()) {
        return false;
    } else {
        switch (type) {
        case 0:
            return resource.isDirectory();
        case 1:
            return resource.isFile();
        case 2:
            return resource.isFile() && resource.getContentLength() > 0;
        default:
            return false;
        }
    }
}
 
Example #13
Source File: TomEEWebappClassLoader.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void setResources(final WebResourceRoot resources) {
    this.resources = resources;
    if (StandardRoot.class.isInstance(resources)) {
        final List<WebResourceSet> jars = (List<WebResourceSet>) Reflections.get(resources, "jarResources");
        if (jars != null && !jars.isEmpty()) {
            final Iterator<WebResourceSet> jarIt = jars.iterator();
            while (jarIt.hasNext()) {
                final WebResourceSet set = jarIt.next();
                if (set.getBaseUrl() == null) {
                    continue;
                }
                final File file = URLs.toFile(set.getBaseUrl());
                try {
                    if (file.exists() && (!TomEEClassLoaderEnricher.validateJarFile(file) || !jarIsAccepted(file))) {
                        // need to remove this resource
                        LOGGER.warning("Removing " + file.getAbsolutePath() + " since it is offending");
                        jarIt.remove();
                    }
                } catch (final IOException e) {
                    // ignore
                }
            }
        }
    }
}
 
Example #14
Source File: FatJarContextConfig.java    From oxygen with Apache License 2.0 6 votes vote down vote up
private void processJar(URL url) throws IOException {
  try (Jar jar = JarFactory.newInstance(url)) {
    jar.nextEntry();
    String entryName = jar.getEntryName();
    while (entryName != null) {
      if (entryName.startsWith(TomcatConf.META_INF_RESOURCES)) {
        context.getResources()
            .createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR, Strings.SLASH,
                url, TomcatConf.META_INF_RESOURCES_PATH);
        break;
      }
      jar.nextEntry();
      entryName = jar.getEntryName();
    }
  }
}
 
Example #15
Source File: TomcatBaseTest.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Make the Tomcat instance preconfigured with test/webapp available to
 * sub-classes.
 * @param addJstl Should JSTL support be added to the test webapp
 * @param start   Should the Tomcat instance be started
 *
 * @return A Tomcat instance pre-configured with the web application located
 *         at test/webapp
 *
 * @throws LifecycleException If a problem occurs while starting the
 *                            instance
 */
public Tomcat getTomcatInstanceTestWebapp(boolean addJstl, boolean start)
        throws LifecycleException {
    File appDir = new File("test/webapp");
    Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    StandardJarScanner scanner = (StandardJarScanner) ctx.getJarScanner();
    StandardJarScanFilter filter = (StandardJarScanFilter) scanner.getJarScanFilter();
    filter.setTldSkip(filter.getTldSkip() + ",testclasses");
    filter.setPluggabilitySkip(filter.getPluggabilitySkip() + ",testclasses");

    if (addJstl) {
        File lib = new File("webapps/examples/WEB-INF/lib");
        ctx.setResources(new StandardRoot(ctx));
        ctx.getResources().createWebResourceSet(
                WebResourceRoot.ResourceSetType.POST, "/WEB-INF/lib",
                lib.getAbsolutePath(), null, "/");
    }

    if (start) {
        tomcat.start();
    }
    return tomcat;
}
 
Example #16
Source File: TomcatServer.java    From doodle with Apache License 2.0 6 votes vote down vote up
public TomcatServer(Configuration configuration) {
    try {
        this.tomcat = new Tomcat();
        tomcat.setBaseDir(configuration.getDocBase());
        tomcat.setPort(configuration.getServerPort());

        File root = getRootFolder(configuration);
        File webContentFolder = new File(root.getAbsolutePath(), configuration.getResourcePath());
        if (!webContentFolder.exists()) {
            webContentFolder = Files.createTempDirectory("default-doc-base").toFile();
        }

        log.info("Tomcat:configuring app with basedir: [{}]", webContentFolder.getAbsolutePath());
        StandardContext ctx = (StandardContext) tomcat.addWebapp(configuration.getContextPath(), webContentFolder.getAbsolutePath());
        ctx.setParentClassLoader(this.getClass().getClassLoader());

        WebResourceRoot resources = new StandardRoot(ctx);
        ctx.setResources(resources);

        tomcat.addServlet(configuration.getContextPath(), "dispatcherServlet", new DispatcherServlet()).setLoadOnStartup(0);
        ctx.addServletMappingDecoded("/*", "dispatcherServlet");
    } catch (Exception e) {
        log.error("初始化Tomcat失败", e);
        throw new RuntimeException(e);
    }
}
 
Example #17
Source File: Main.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static void main(String[] args) throws ServletException, LifecycleException {
	OpenTracingUtil.configureOpenTracing("RobotShop-Order-Service");
	String webappDirLocation = "src/main/webapp/";
	Tomcat tomcat = new Tomcat();

	String webPort = System.getenv("PORT");
	if (webPort == null || webPort.isEmpty()) {
		webPort = DEFAULT_PORT;
	}

	tomcat.setPort(Integer.valueOf(webPort));

	StandardContext ctx = (StandardContext) tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
	System.out.println("Basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
	File additionWebInfClasses = new File("target/classes");
	WebResourceRoot resources = new StandardRoot(ctx);
	resources.addPreResources(
			new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
	ctx.setResources(resources);

	// Add servlet that will register Jersey REST resources
	Tomcat.addServlet(ctx, "jersey-container-servlet", resourceConfig());
	ctx.addServletMapping("/*", "jersey-container-servlet");

	tomcat.start();
	tomcat.getServer().await();
}
 
Example #18
Source File: JarSubsetResourceSet.java    From armeria with Apache License 2.0 5 votes vote down vote up
JarSubsetResourceSet(WebResourceRoot root, String webAppMount, String base, String internalPath,
                     String jarRoot) {
    super(root, webAppMount, base, internalPath);

    // Should be normalized by TomcatServiceBuilder.
    assert !"/".equals(jarRoot) : "JarResourceSet should be used instead.";
    assert jarRoot.startsWith("/") : "jarRoot must be absolute.";
    assert !jarRoot.endsWith("/") : "jarRoot must not end with '/'.";

    prefix = jarRoot.substring(1) + '/';
}
 
Example #19
Source File: JsfTomcatApplicationListener.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
private JarWarResourceSet getFirstJarWarResourceSetAtJarResources(WebResourceRoot resources) {
	JarWarResourceSet result = null;
	for (WebResourceSet resourceSet :resources.getJarResources()) {
		if (resourceSet instanceof JarWarResourceSet) {
			result = (JarWarResourceSet) resourceSet;
			break;
		}
	}
	return result;
}
 
Example #20
Source File: TestDirResourceSetInternal.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public WebResourceRoot getWebResourceRoot() {
    TesterWebResourceRoot root = new TesterWebResourceRoot();
    WebResourceSet webResourceSet =
            new DirResourceSet(root, "/", tempDir.toAbsolutePath().toString(), "/dir1");
    root.setMainResources(webResourceSet);
    return root;
}
 
Example #21
Source File: TestJarResourceSetMount.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public WebResourceRoot getWebResourceRoot() {
    File f = new File("test/webresources/dir1.jar");
    TesterWebResourceRoot root = new TesterWebResourceRoot();
    WebResourceSet webResourceSet =
            new JarResourceSet(root, getMount(), f.getAbsolutePath(), "/");
    root.setMainResources(webResourceSet);
    return root;
}
 
Example #22
Source File: Main.java    From heroku-identity-java with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        String webappDirLocation = "src/main/webapp/";
        Tomcat tomcat = new Tomcat();

        //The port that we should run on can be set into an environment variable
        //Look for that variable and default to 8080 if it isn't there.
        String webPort = System.getenv("PORT");
        if(webPort == null || webPort.isEmpty()) {
            webPort = "8080";
        }

        tomcat.setPort(Integer.valueOf(webPort));

        StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
        System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());

        // Declare an alternative location for your "WEB-INF/classes" dir
        // Servlet 3.0 annotation will work
        File additionWebInfClasses = new File("target/classes");
        WebResourceRoot resources = new StandardRoot(ctx);
        resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
                additionWebInfClasses.getAbsolutePath(), "/"));
        ctx.setResources(resources);

        tomcat.start();
        tomcat.getServer().await();
    }
 
Example #23
Source File: TestDirResourceSet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public WebResourceRoot getWebResourceRoot() {
    TesterWebResourceRoot root = new TesterWebResourceRoot();
    WebResourceSet webResourceSet =
            new DirResourceSet(root, "/", getBaseDir().getAbsolutePath(), "/");
    webResourceSet.setReadOnly(false);
    root.setMainResources(webResourceSet);
    return root;
}
 
Example #24
Source File: Main.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static void main(String[] args) throws ServletException, LifecycleException {
	OpenTracingUtil.configureOpenTracing("RobotShop-Customer-Service");
	
	String webappDirLocation = "src/main/webapp/";
	Tomcat tomcat = new Tomcat();

	String webPort = System.getenv("PORT");
	if (webPort == null || webPort.isEmpty()) {
		webPort = DEFAULT_PORT;
	}

	tomcat.setPort(Integer.valueOf(webPort));

	StandardContext ctx = (StandardContext) tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
	System.out.println("Basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
	File additionWebInfClasses = new File("target/classes");
	WebResourceRoot resources = new StandardRoot(ctx);
	resources.addPreResources(
			new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
	ctx.setResources(resources);

	// Add servlet that will register Jersey REST resources
	Tomcat.addServlet(ctx, "jersey-container-servlet", resourceConfig());
	ctx.addServletMapping("/*", "jersey-container-servlet");

	tomcat.start();
	tomcat.getServer().await();
}
 
Example #25
Source File: Main.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static void main(String[] args) throws ServletException, LifecycleException {
	OpenTracingUtil.configureOpenTracing("RobotShop-Factory-Service");

	String webappDirLocation = "src/main/webapp/";
	Tomcat tomcat = new Tomcat();

	String webPort = System.getenv("PORT");
	if (webPort == null || webPort.isEmpty()) {
		webPort = DEFAULT_PORT;
	}

	tomcat.setPort(Integer.valueOf(webPort));

	StandardContext ctx = (StandardContext) tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
	System.out.println("Basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
	File additionWebInfClasses = new File("target/classes");
	WebResourceRoot resources = new StandardRoot(ctx);
	resources.addPreResources(
			new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
	ctx.setResources(resources);

	// Add servlet that will register Jersey REST resources
	Tomcat.addServlet(ctx, "jersey-container-servlet", resourceConfig());
	ctx.addServletMapping("/*", "jersey-container-servlet");

	tomcat.start();
	tomcat.getServer().await();
}
 
Example #26
Source File: MapperListener.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Register context.
 */
private void registerContext(Context context) {

    String contextPath = context.getPath();
    if ("/".equals(contextPath)) {
        contextPath = "";
    }
    Host host = (Host)context.getParent();

    WebResourceRoot resources = context.getResources();
    String[] welcomeFiles = context.findWelcomeFiles();
    List<WrapperMappingInfo> wrappers = new ArrayList<>();

    for (Container container : context.findChildren()) {
        prepareWrapperMappingInfo(context, (Wrapper) container, wrappers);

        if(log.isDebugEnabled()) {
            log.debug(sm.getString("mapperListener.registerWrapper",
                    container.getName(), contextPath, service));
        }
    }

    mapper.addContextVersion(host.getName(), host, contextPath,
            context.getWebappVersion(), context, welcomeFiles, resources,
            wrappers);

    if(log.isDebugEnabled()) {
        log.debug(sm.getString("mapperListener.registerContext",
                contextPath, service));
    }
}
 
Example #27
Source File: FatJarWebXmlListener.java    From oxygen with Apache License 2.0 5 votes vote down vote up
private void createWebResource(Context context, WebResourceRoot resources, String path) {
  log.info(String.format("create web resources for [%s]", path));
  URL resource = context.getParentClassLoader().getResource(path);
  if (resource != null) {
    String webXmlUrlString = resource.toString();
    try {
      URL root = new URL(webXmlUrlString.substring(0, webXmlUrlString.length() - path.length()));
      String webPath = Strings.SLASH + path;
      resources.createWebResourceSet(ResourceSetType.RESOURCE_JAR, webPath, root, webPath);
    } catch (MalformedURLException e) {
      // ignore
    }
  }
}
 
Example #28
Source File: Mapper.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public ContextVersion(String version, String path, int slashCount,
        Context context, WebResourceRoot resources,
        String[] welcomeResources) {
    super(version, context);
    this.path = path;
    this.slashCount = slashCount;
    this.resources = resources;
    this.welcomeResources = welcomeResources;
}
 
Example #29
Source File: TestVirtualWebappLoader.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testStartInternal() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp");
    StandardContext ctx = (StandardContext) tomcat.addContext("",
            appDir.getAbsolutePath());


    WebappLoader loader = new WebappLoader();

    loader.setContext(ctx);
    ctx.setLoader(loader);

    ctx.setResources(new StandardRoot(ctx));
    ctx.resourcesStart();

    File f1 = new File("test/webapp-fragments/WEB-INF/lib");
    ctx.getResources().createWebResourceSet(
            WebResourceRoot.ResourceSetType.POST, "/WEB-INF/lib",
            f1.getAbsolutePath(), null, "/");

    loader.start();
    String[] repos = loader.getLoaderRepositories();
    Assert.assertEquals(4,repos.length);
    loader.stop();

    repos = loader.getLoaderRepositories();
    Assert.assertEquals(0, repos.length);

    // no leak
    loader.start();
    repos = loader.getLoaderRepositories();
    Assert.assertEquals(4,repos.length);

    // clear loader
    ctx.setLoader(null);
    // see tearDown()!
    tomcat.start();
}
 
Example #30
Source File: TestDirResourceSetReadOnly.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public WebResourceRoot getWebResourceRoot() {
    TesterWebResourceRoot root = new TesterWebResourceRoot();
    WebResourceSet webResourceSet =
            new DirResourceSet(root, "/", getBaseDir().getAbsolutePath(), "/");
    webResourceSet.setReadOnly(true);
    root.setMainResources(webResourceSet);
    return root;
}