Java Code Examples for org.apache.catalina.WebResourceSet#getBaseUrl()

The following examples show how to use org.apache.catalina.WebResourceSet#getBaseUrl() . 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: 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 2
Source File: StandardRoot.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public List<URL> getBaseUrls() {
    List<URL> result = new ArrayList<>();
    for (List<WebResourceSet> list : allResources) {
        for (WebResourceSet webResourceSet : list) {
            if (!webResourceSet.getClassLoaderOnly()) {
                URL url = webResourceSet.getBaseUrl();
                if (url != null) {
                    result.add(url);
                }
            }
        }
    }
    return result;
}
 
Example 3
Source File: JsfTomcatApplicationListener.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
private URL mainFile(WebResourceRoot resources) {
	URL result = null;
	for (WebResourceSet resourceSet :resources.getJarResources()) {
		if (resourceSet instanceof JarWarResourceSet) {
			result = resourceSet.getBaseUrl();
			break;
		}
	}
	return result;
}
 
Example 4
Source File: TomcatWebAppBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
private static DeploymentLoader.ExternalConfiguration configuredClasspath(final StandardContext standardContext) {
    Loader loader = standardContext.getLoader();
    if (loader != null && LazyStopLoader.class.isInstance(loader)) {
        loader = LazyStopLoader.class.cast(loader).getDelegateLoader();
    }
    if (loader != null) {
        final ClassLoader cl = standardContext.getLoader().getClassLoader();
        if (cl == null) {
            return null;
        }

        final Collection<String> cp = new LinkedList<>();

        final WebResourceRoot webResources = standardContext.getResources();
        if (webResources != null) { // to enhance
            for (final WebResourceSet[] sets : asList(webResources.getPreResources(), webResources.getPostResources(), webResources.getJarResources())) {
                for (final WebResourceSet wr : sets) {
                    final URL base = wr.getBaseUrl();
                    if (base != null) {
                        final File baseFile = URLs.toFile(base);
                        if (baseFile.isDirectory()) {
                            final String[] libs = wr.list("/WEB-INF/lib/");
                            if (libs != null) {
                                for (final String resource : libs) {
                                    cp.add(new File(baseFile, resource).getAbsolutePath());
                                }
                            }

                            final WebResource classes = wr.getResource("/WEB-INF/classes/");
                            if (classes != null) {
                                final String path = classes.getCanonicalPath();
                                if (path != null) {
                                    cp.add(path);
                                }
                            }
                        } else if (baseFile.exists() && baseFile.getName().endsWith(".jar") && wr.getResource("/WEB-INF/classes/").exists()) {
                            try {
                                cp.add(baseFile.getCanonicalPath());
                            } catch (final IOException e) {
                                throw new IllegalStateException(e);
                            }
                        }
                    }
                }
            }
        }

        if (!cp.isEmpty()) {
            return new DeploymentLoader.ExternalConfiguration(cp.toArray(new String[cp.size()]), null /*for now doesnt make sense, todo: configure*/);
        }
    }
    return null;
}