Search in sources :

Example 11 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class ConfigurationFactory method configureApplication.

public AppInfo configureApplication(final AppModule appModule) throws OpenEJBException {
    try {
        final Collection<Class<?>> extensions = new HashSet<Class<?>>();
        final Collection<String> notLoaded = new HashSet<String>();
        final List<URL> libs = appModule.getAdditionalLibraries();
        if (libs != null && libs.size() > 0) {
            final Extensions.Finder finder = new Extensions.Finder("META-INF", false, libs.toArray(new URL[libs.size()]));
            extensions.addAll(Extensions.findExtensions(finder));
            notLoaded.addAll(finder.getResourcesNotLoaded());
        }
        for (final EjbModule ejb : appModule.getEjbModules()) {
            try {
                final URI uri = ejb.getModuleUri();
                if (uri.isAbsolute()) {
                    final URL url = uri.toURL();
                    if (libs != null && !libs.contains(url)) {
                        final Extensions.Finder finder = new Extensions.Finder("META-INF", false, url);
                        extensions.addAll(Extensions.findExtensions(finder));
                        notLoaded.addAll(finder.getResourcesNotLoaded());
                    }
                }
            } catch (final IllegalArgumentException | MalformedURLException iae) {
                logger.debug("can't look for server event listener for module " + ejb.getModuleUri(), iae);
            } catch (final Exception e) {
                logger.error("can't look for server event listener for module " + ejb.getJarLocation());
            }
        }
        for (final WebModule web : appModule.getWebModules()) {
            final List<URL> webLibs = web.getScannableUrls();
            if (webLibs != null && webLibs.size() > 0) {
                final Extensions.Finder finder = new Extensions.Finder("META-INF", false, webLibs.toArray(new URL[webLibs.size()]));
                extensions.addAll(Extensions.findExtensions(finder));
                notLoaded.addAll(finder.getResourcesNotLoaded());
            }
        }
        // add it as early as possible, the ones needing the app classloader will be added later
        Extensions.addExtensions(extensions);
        final String location = appModule.getJarLocation();
        logger.info("config.configApp", null != location ? location : appModule.getModuleId());
        deployer.deploy(appModule);
        final AppInfoBuilder appInfoBuilder = new AppInfoBuilder(this);
        final AppInfo info = appInfoBuilder.build(appModule);
        info.eventClassesNeedingAppClassloader.addAll(notLoaded);
        return info;
    } finally {
        destroy(appModule.getEarLibFinder());
        for (final EjbModule ejb : appModule.getEjbModules()) {
            destroy(ejb.getFinder());
        }
        for (final WebModule web : appModule.getWebModules()) {
            destroy(web.getFinder());
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ParentClassLoaderFinder(org.apache.openejb.core.ParentClassLoaderFinder) IAnnotationFinder(org.apache.xbean.finder.IAnnotationFinder) Extensions(org.apache.openejb.Extensions) URI(java.net.URI) URL(java.net.URL) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) AppInfo(org.apache.openejb.assembler.classic.AppInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) MetaAnnotatedClass(org.apache.xbean.finder.MetaAnnotatedClass) HashSet(java.util.HashSet)

Example 12 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class AutoDeployer method fileAdded.

private boolean fileAdded(final File file) {
    final String appPath = file.getAbsolutePath();
    logger.info("Starting Auto-Deployment of: " + appPath);
    try {
        final AppInfo appInfo = factory.configureApplication(file);
        appInfo.paths.add(appPath);
        appInfo.paths.add(appInfo.path);
        if (logger.isDebugEnabled()) {
            for (final String path : appInfo.paths) {
                logger.debug("Auto-Deployment path: " + path);
            }
        }
        final Assembler assembler = getAssembler();
        if (null == assembler) {
            throw new Exception("Assembler is not available for Auto-Deployment of: " + appPath);
        }
        assembler.createApplication(appInfo);
        // war can be unpacked so it changes the last modified time
        files.get(appPath).setModified(getLastModifiedInDir(new File(appPath)));
    } catch (final Exception e) {
        logger.error("Failed Auto-Deployment of: " + appPath, e);
    }
    return true;
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 13 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class ConfigurationFactory method configureApplication.

public AppInfo configureApplication(final File jarFile) throws OpenEJBException {
    logger.debug("Beginning load: " + jarFile.getAbsolutePath());
    try {
        final AppModule appModule = deploymentLoader.load(jarFile, null);
        final AppInfo appInfo = configureApplication(appModule);
        // this is clean up in Assembler for safety and TomcatWebAppBuilder when used
        if (!appModule.getWebModules().isEmpty()) {
            for (final WebAppInfo info : appInfo.webApps) {
                for (final EjbModule ejbModule : appModule.getEjbModules()) {
                    if (ejbModule.getModuleId().equals(info.moduleId) && ejbModule.getFinder() != null) {
                        appInfo.properties.put(info, ejbModule);
                    }
                }
            }
        }
        // TODO This is temporary -- we need to do this in AppInfoBuilder
        appInfo.paths.add(appInfo.path);
        appInfo.paths.add(jarFile.getAbsolutePath());
        return appInfo;
    } catch (final ValidationFailedException e) {
        // DO not include the stacktrace in the message
        logger.warning("configureApplication.loadFailed", jarFile.getAbsolutePath(), e.getMessage());
        throw e;
    } catch (final OpenEJBException e) {
        // DO NOT REMOVE THE EXCEPTION FROM THIS LOG MESSAGE
        // removing this message causes NO messages to be printed when embedded
        logger.warning("configureApplication.loadFailed", e, jarFile.getAbsolutePath(), e.getMessage());
        throw e;
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo)

Example 14 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class HibernateTest method checkEmIsHibernateOne.

// using an internal lookup because in tomee embedded new InitialContext() is not guaranteed
@Test
public void checkEmIsHibernateOne() throws Exception {
    AppInfo info = null;
    for (final AppInfo app : SystemInstance.get().getComponent(Assembler.class).getDeployedApplications()) {
        if (app.appId.endsWith("hibernate-app")) {
            info = app;
            break;
        }
    }
    assertNotNull(info);
    final EntityManagerFactory emf = (EntityManagerFactory) SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup(Assembler.PERSISTENCE_UNIT_NAMING_CONTEXT + info.persistenceUnits.iterator().next().id);
    assertTrue(((ReloadableEntityManagerFactory) emf).getDelegate().getClass().getName().startsWith("org.hibernate."));
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) ReloadableEntityManagerFactory(org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory) EntityManagerFactory(javax.persistence.EntityManagerFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) ReloadableEntityManagerFactory(org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

Example 15 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class JMXDeployer method getDeployedApplications.

@ManagedAttribute
@Description("List available applications")
public String[] getDeployedApplications() {
    try {
        final Collection<AppInfo> apps = deployer().getDeployedApps();
        final String[] appsNames = new String[apps.size()];
        int i = 0;
        for (final AppInfo info : apps) {
            appsNames[i++] = info.path;
        }
        return appsNames;
    } catch (final Exception e) {
        return new String[] { "ERR:" + e.getMessage() };
    }
}
Also used : NamingException(javax.naming.NamingException) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Description(org.apache.openejb.api.jmx.Description) ManagedAttribute(org.apache.openejb.api.jmx.ManagedAttribute)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)106 File (java.io.File)50 Assembler (org.apache.openejb.assembler.classic.Assembler)46 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 OpenEJBException (org.apache.openejb.OpenEJBException)15 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)13 EjbJar (org.apache.openejb.jee.EjbJar)13 ContainerSystem (org.apache.openejb.spi.ContainerSystem)13 Properties (java.util.Properties)10 EjbModule (org.apache.openejb.config.EjbModule)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8 URL (java.net.URL)8 InitialContext (javax.naming.InitialContext)8