Search in sources :

Example 66 with AppInfo

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

the class EntityManagerPropogationTest method setUp.

public void setUp() throws OpenEJBException, IOException, NamingException {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    System.setProperty("openejb.embedded", "true");
    // Boot up the minimum required OpenEJB components
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // Start creating the test application
    // Create an ejb-jar.xml for this app
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean("PleaseCloseMyExtendedEm", PleaseCloseMyExtendedEmBean.class));
    ejbJar.addEnterpriseBean(new StatefulBean("PleaseCloseMyEm", PleaseCloseMyEmBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean("PleaseCloseMyLessEm", PleaseCloseMyEmBean.class));
    // Add six beans and link them all in a chain
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extended", "Extendedx2");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx2", "Extendedx3");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx3", "Extendedx4");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx4", "Extendedx5");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "ExtendedToTransaction", "StatelessTransactionToExtended");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx5", "Extendedx6");
    ejbJar.addEnterpriseBean(new StatefulBean("Extendedx6", EndNodeBean.class));
    // Add six beans and link them all in a chain
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transaction", "Transactionx2");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx2", "Transactionx3");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx3", "Transactionx4");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx4", "Transactionx5");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx5", "Transactionx6");
    addStatefulBean(ejbJar, TransactionContextBean.class, "TransactionToExtended", "Extendedx5");
    addStatelessBean(ejbJar, TransactionContextBean.class, "StatelessTransactionToExtended", "Extendedx5");
    ejbJar.addEnterpriseBean(new StatefulBean("Transactionx6", EndNodeBean.class));
    ejbJar.setAssemblyDescriptor(new AssemblyDescriptor());
    ejbJar.getAssemblyDescriptor().addApplicationException(IllegalArgumentException.class, false, true);
    ejbJar.getAssemblyDescriptor().addApplicationException(ArgumentException.class, false, true);
    // List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
    // declared.add(new ContainerTransaction(TransAttribute.REQUIRED, ExtendedContextBean.class.getName(), "Extendedx5", "*"));
    // declared.add(new ContainerTransaction(TransAttribute.REQUIRED, ExtendedContextBean.class.getName(), "TransactionToExtended", "*"));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    // Create an "ear"
    final AppModule appModule = new AppModule(ejbModule.getClassLoader(), "test-app");
    // Add the ejb-jar.xml to the ear
    appModule.getEjbModules().add(ejbModule);
    // Create a persistence-unit for this app
    final PersistenceUnit unit = new PersistenceUnit("testUnit");
    unit.addClass(Color.class);
    unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
    unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
    // Add the persistence.xml to the "ear"
    appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(unit)));
    // Configure and assemble the ear -- aka. deploy it
    final AppInfo info = config.configureApplication(appModule);
    assembler.createApplication(info);
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) PersistenceModule(org.apache.openejb.config.PersistenceModule) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Persistence(org.apache.openejb.jee.jpa.unit.Persistence) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 67 with AppInfo

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

the class ModulePropertiesTest method testOverrideAdd.

public void testOverrideAdd() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        SystemInstance.get().getProperties().put("fooModule.color", "orange");
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    assertContexts(containerSystem);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Assembler(org.apache.openejb.assembler.classic.Assembler) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 68 with AppInfo

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

the class XmlOverridesTest method test.

public void test() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(AnnotatedBean.class));
    bean.getEjbLocalRef().add(new EjbLocalRef(name("annotatedLocal"), "BarBean"));
    bean.getEnvEntry().add(new EnvEntry(name("striing"), "java.lang.Integer", "2"));
    bean.getEnvEntry().add(new EnvEntry(name("doouble"), "java.lang.String", "two"));
    bean.getEnvEntry().add(new EnvEntry(name("loong"), "java.lang.String", "three"));
    bean.getEnvEntry().add(new EnvEntry(name("flooat"), "java.lang.String", "four"));
    bean.getEnvEntry().add(new EnvEntry(name("inteeger"), "java.lang.String", "five"));
    bean.getEnvEntry().add(new EnvEntry(name("shoort"), "java.lang.String", "six"));
    bean.getEnvEntry().add(new EnvEntry(name("booolean"), "java.lang.String", "seven"));
    bean.getEnvEntry().add(new EnvEntry(name("byyte"), "java.lang.String", "eight"));
    bean.getEnvEntry().add(new EnvEntry(name("chaaracter"), "java.lang.String", "nine"));
    final EnvEntry lookupEntry = new EnvEntry(name("lookup"), "java.lang.String", null);
    lookupEntry.setLookupName("java:app/AppName");
    bean.getEnvEntry().add(lookupEntry);
    bean.getResourceRef().add(new ResourceRef(name("daataSource"), DataSource.class.getName(), ResAuth.CONTAINER, ResSharingScope.SHAREABLE));
    bean.getPersistenceUnitRef().add(new PersistenceUnitRef(name("emf"), "yellow"));
    bean.getPersistenceContextRef().add(new PersistenceContextRef(name("em"), "yellow", PersistenceContextType.TRANSACTION, new ArrayList(Arrays.asList(new Property("zzzz", "AAAA")))));
    final org.apache.openejb.jee.jpa.unit.PersistenceUnit persistenceUnit = new org.apache.openejb.jee.jpa.unit.PersistenceUnit("yellow");
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "app");
    app.getEjbModules().add(new EjbModule(ejbJar));
    app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
    final AppInfo appInfo = config.configureApplication(app);
    final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    final JndiEncInfo enc = beanInfo.jndiEnc;
    assertEquals("Enc.ejbLocalReferences.size()", 1, enc.ejbLocalReferences.size());
    assertEquals("Enc.ejbLocalReferences.get(0).link", "BarBean", enc.ejbLocalReferences.get(0).link);
    assertEquals("Enc.ejbReferences.size()", 0, enc.ejbReferences.size());
    // 10 + ComponentName
    assertEquals("Enc.envEntries.size()", 11, enc.envEntries.size());
    final Map<String, EnvEntryInfo> entries = map(enc.envEntries);
    assertEnvEntry(entries, name("striing"), "java.lang.Integer", "2");
    assertEnvEntry(entries, name("doouble"), "java.lang.String", "two");
    assertEnvEntry(entries, name("loong"), "java.lang.String", "three");
    assertEnvEntry(entries, name("flooat"), "java.lang.String", "four");
    assertEnvEntry(entries, name("inteeger"), "java.lang.String", "five");
    assertEnvEntry(entries, name("shoort"), "java.lang.String", "six");
    assertEnvEntry(entries, name("booolean"), "java.lang.String", "seven");
    assertEnvEntry(entries, name("byyte"), "java.lang.String", "eight");
    assertEnvEntry(entries, name("chaaracter"), "java.lang.String", "nine");
    assertEnvEntryLookup(entries, name("lookup"), "java.lang.String", "java:app/AppName");
    assertEquals("Enc.persistenceContextRefs.size()", 1, enc.persistenceContextRefs.size());
    final PersistenceContextReferenceInfo context = enc.persistenceContextRefs.get(0);
    assertEquals("Context.extended", false, context.extended);
    assertEquals("Context.persistenceUnitName", "yellow", context.persistenceUnitName);
    assertEquals("Context.properties.size()", 1, context.properties.size());
    assertEquals("Context.properties.getProperty(\"zzzz\")", "AAAA", context.properties.getProperty("zzzz"));
    assertEquals("Enc.persistenceUnitRefs.size()", 1, enc.persistenceUnitRefs.size());
    final PersistenceUnitReferenceInfo unit = enc.persistenceUnitRefs.get(0);
    assertEquals("Unit.persistenceUnitName", "yellow", unit.persistenceUnitName);
    assertEquals("Enc.resourceRefs.size()", 1, enc.resourceRefs.size());
    final ResourceReferenceInfo resource = enc.resourceRefs.get(0);
    assertEquals("Resource.referenceAuth", "CONTAINER", resource.referenceAuth);
}
Also used : PersistenceContextRef(org.apache.openejb.jee.PersistenceContextRef) ArrayList(java.util.ArrayList) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) PersistenceUnit(javax.persistence.PersistenceUnit) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) Property(org.apache.openejb.jee.Property) PersistenceUnitRef(org.apache.openejb.jee.PersistenceUnitRef) EjbJar(org.apache.openejb.jee.EjbJar) EnvEntry(org.apache.openejb.jee.EnvEntry) EjbLocalRef(org.apache.openejb.jee.EjbLocalRef) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) JndiEncInfo(org.apache.openejb.assembler.classic.JndiEncInfo) StatefulBean(org.apache.openejb.jee.StatefulBean) EnvEntryInfo(org.apache.openejb.assembler.classic.EnvEntryInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Persistence(org.apache.openejb.jee.jpa.unit.Persistence) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ResourceRef(org.apache.openejb.jee.ResourceRef) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 69 with AppInfo

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

the class ConfigurationFactory method configureApplication.

/**
 * embedded usage
 *
 * @param classLoader classloader
 * @param id          id supplied from embedded properties or null
 * @param jarFiles    list of ejb modules
 * @return configured AppInfo
 * @throws OpenEJBException on error
 */
public AppInfo configureApplication(final ClassLoader classLoader, final String id, final List<File> jarFiles) throws OpenEJBException {
    final AppModule collection = loadApplication(classLoader, id, jarFiles);
    final AppInfo appInfo;
    try {
        appInfo = configureApplication(collection);
    } catch (final ValidationFailedException e) {
        // DO not include the stacktrace in the message
        logger.warning("configureApplication.loadFailed", collection.getModuleId(), 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, collection.getModuleId(), e.getMessage());
        throw e;
    }
    return appInfo;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) AppInfo(org.apache.openejb.assembler.classic.AppInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo)

Example 70 with AppInfo

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

the class AutoDeployer method fileRemoved.

private static boolean fileRemoved(final File file) {
    if (null == file) {
        return true;
    }
    final String path = file.getAbsolutePath();
    final Assembler assembler = getAssembler();
    if (null != assembler) {
        final Collection<AppInfo> apps = assembler.getDeployedApplications();
        for (final AppInfo app : apps) {
            if (app.paths.contains(path)) {
                logger.info("Starting Auto-Undeployment of: " + app.appId + " - " + file.getAbsolutePath());
                try {
                    assembler.destroyApplication(app);
                    for (final String location : app.paths) {
                        if (new File(location).equals(file)) {
                            continue;
                        }
                        final File delete = new File(location.replace("%20", " ").replace("%23", "#"));
                        for (int i = 0; i < 3; i++) {
                            try {
                                Files.remove(delete);
                                break;
                            } catch (final Exception e) {
                                if (i < 2) {
                                    // Try again as file IO is not a science
                                    Thread.sleep(100);
                                } else {
                                    logger.warning("Failed to delete: " + delete);
                                }
                            }
                        }
                        logger.debug("Auto-Undeploy: Delete " + location);
                    }
                    logger.info("Completed Auto-Undeployment of: " + app.appId);
                } catch (final Throwable e) {
                    logger.error("Auto-Undeploy Failed: " + file.getAbsolutePath(), e);
                }
                break;
            }
        }
    }
    return true;
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)109 File (java.io.File)49 Assembler (org.apache.openejb.assembler.classic.Assembler)49 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJar (org.apache.openejb.jee.EjbJar)17 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 ContainerSystem (org.apache.openejb.spi.ContainerSystem)15 OpenEJBException (org.apache.openejb.OpenEJBException)14 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)12 EjbModule (org.apache.openejb.config.EjbModule)11 Properties (java.util.Properties)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 InitialContext (javax.naming.InitialContext)9 StatelessBean (org.apache.openejb.jee.StatelessBean)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8