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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations