Search in sources :

Example 1 with WebAppEnricher

use of org.apache.openejb.classloader.WebAppEnricher in project tomee by apache.

the class DeploymentLoader method getWebappUrlsAndRars.

public static Map<String, URL[]> getWebappUrlsAndRars(final File warFile) {
    final Set<URL> webClassPath = new HashSet<URL>();
    final Set<URL> webRars = new HashSet<URL>();
    final File webInfDir = new File(warFile, "WEB-INF");
    try {
        webClassPath.add(new File(webInfDir, "classes").toURI().toURL());
    } catch (final MalformedURLException e) {
        logger.warning("War path bad: " + new File(webInfDir, "classes"), e);
    }
    final File libDir = new File(webInfDir, "lib");
    if (libDir.exists()) {
        final File[] list = libDir.listFiles();
        if (list != null) {
            for (final File file : list) {
                final String name = file.getName();
                if (name.endsWith(".jar") || name.endsWith(".zip")) {
                    try {
                        webClassPath.add(file.toURI().toURL());
                    } catch (final MalformedURLException e) {
                        logger.warning("War path bad: " + file, e);
                    }
                } else if (name.endsWith(".rar")) {
                    try {
                        webRars.add(file.toURI().toURL());
                    } catch (final MalformedURLException e) {
                        logger.warning("War path bad: " + file, e);
                    }
                }
            }
        }
    }
    final WebAppEnricher enricher = SystemInstance.get().getComponent(WebAppEnricher.class);
    if (enricher != null) {
        webClassPath.addAll(Arrays.asList(enricher.enrichment(null)));
    }
    // create the class loader
    final Map<String, URL[]> urls = new HashMap<String, URL[]>();
    urls.put(URLS_KEY, webClassPath.toArray(new URL[webClassPath.size()]));
    urls.put(RAR_URLS_KEY, webRars.toArray(new URL[webRars.size()]));
    return urls;
}
Also used : MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WebAppEnricher(org.apache.openejb.classloader.WebAppEnricher) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with WebAppEnricher

use of org.apache.openejb.classloader.WebAppEnricher in project tomee by apache.

the class ReloadingLoaderTest method initContext.

@Before
public void initContext() throws LifecycleException {
    final OpenEjbConfiguration configuration = new OpenEjbConfiguration();
    configuration.facilities = new FacilitiesInfo();
    final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
    SystemInstance.get().setComponent(OpenEjbConfiguration.class, configuration);
    SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);
    SystemInstance.get().setComponent(WebAppEnricher.class, new WebAppEnricher() {

        @Override
        public URL[] enrichment(final ClassLoader webappClassLaoder) {
            return new URL[0];
        }
    });
    parentInstance = new AtomicReference<>(ParentClassLoaderFinder.Helper.get());
    loader = new TomEEWebappClassLoader(parentInstance.get()) {

        @Override
        public ClassLoader getInternalParent() {
            return parentInstance.get();
        }

        @Override
        protected void clearReferences() {
        // no-op: this test should be reworked to support it but in real life a loader is not stopped/started
        }
    };
    loader.init();
    final StandardRoot resources = new StandardRoot();
    loader.setResources(resources);
    resources.setContext(new StandardContext() {

        @Override
        public String getDocBase() {
            final File file = new File("target/foo");
            file.mkdirs();
            return file.getAbsolutePath();
        }

        @Override
        public String getMBeanKeyProperties() {
            return "foo";
        }

        {
        }
    });
    resources.start();
    loader.start();
    info = new AppInfo();
    info.appId = "test";
    context = new AppContext(info.appId, SystemInstance.get(), loader, new IvmContext(), new IvmContext(), true);
    containerSystem.addAppContext(context);
    final WebContext webDeployment = new WebContext(context);
    webDeployment.setId(context.getId());
    webDeployment.setClassLoader(loader);
    containerSystem.addWebContext(webDeployment);
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) StandardRoot(org.apache.catalina.webresources.StandardRoot) IvmJndiFactory(org.apache.openejb.core.ivm.naming.IvmJndiFactory) TomEEWebappClassLoader(org.apache.tomee.catalina.TomEEWebappClassLoader) CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) WebAppEnricher(org.apache.openejb.classloader.WebAppEnricher) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) AppInfo(org.apache.openejb.assembler.classic.AppInfo) FacilitiesInfo(org.apache.openejb.assembler.classic.FacilitiesInfo) StandardContext(org.apache.catalina.core.StandardContext) TomEEWebappClassLoader(org.apache.tomee.catalina.TomEEWebappClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) Before(org.junit.Before)

Aggregations

File (java.io.File)2 WebAppEnricher (org.apache.openejb.classloader.WebAppEnricher)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 JarFile (java.util.jar.JarFile)1 StandardContext (org.apache.catalina.core.StandardContext)1 StandardRoot (org.apache.catalina.webresources.StandardRoot)1 AppContext (org.apache.openejb.AppContext)1 AppInfo (org.apache.openejb.assembler.classic.AppInfo)1 FacilitiesInfo (org.apache.openejb.assembler.classic.FacilitiesInfo)1 OpenEjbConfiguration (org.apache.openejb.assembler.classic.OpenEjbConfiguration)1 CoreContainerSystem (org.apache.openejb.core.CoreContainerSystem)1 WebContext (org.apache.openejb.core.WebContext)1 IvmContext (org.apache.openejb.core.ivm.naming.IvmContext)1 IvmJndiFactory (org.apache.openejb.core.ivm.naming.IvmJndiFactory)1