use of org.apache.openejb.assembler.classic.EjbJarInfo in project aries by apache.
the class EJBExtender method startEJBs.
private void startEJBs(final Bundle bundle) {
try {
//If there is another thread adding or removing then stop here
Object o = processingMap.put(bundle, PROCESSING_OBJECT);
if (o == REMOVING_OBJECT || o == PROCESSING_OBJECT) {
return;
}
//If already running then avoid
if (runningApps.get(bundle) != null)
return;
//Broken validation for persistence :(
EjbModule ejbModule = new EjbModule(AriesFrameworkUtil.getClassLoaderForced(bundle), null, null, null);
try {
Field f = EjbModule.class.getDeclaredField("validation");
f.setAccessible(true);
f.set(ejbModule, new ValidationProofValidationContext(ejbModule));
} catch (Exception e) {
// Hmmm
}
addAltDDs(ejbModule, bundle);
//We build our own because we can't trust anyone to get the classpath right otherwise!
ejbModule.setFinder(new OSGiFinder(bundle));
ConfigurationFactory configurationFactory = new ConfigurationFactory();
EjbJarInfo ejbInfo = null;
//Avoid yet another ClassLoading problem
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(new ClassLoader(OpenEjbVersion.class.getClassLoader()) {
protected Class<?> findClass(String name) throws ClassNotFoundException {
for (Bundle b : bundle.getBundleContext().getBundles()) {
if (b.getSymbolicName().contains("jaxb-impl"))
return b.loadClass(name);
}
throw new ClassNotFoundException(name);
}
});
ejbInfo = configurationFactory.configureApplication(ejbModule);
//Another oddity here
ejbInfo.validationInfo = null;
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
processJPAMappings(ejbInfo);
Assembler assembler = (Assembler) SystemInstance.get().getComponent(Assembler.class);
RunningApplication app = null;
try {
SystemInstance.get().setProperty("openejb.geronimo", "true");
cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(OpenEjbVersion.class.getClassLoader());
app = new RunningApplication(assembler.createApplication(ejbInfo, new AppClassLoader(ejbModule.getClassLoader())), bundle, ejbInfo.enterpriseBeans);
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
} finally {
SystemInstance.get().getProperties().remove("openejb.geronimo");
}
runningApps.put(bundle, app);
app.init();
} catch (OpenEJBException oee) {
// TODO Auto-generated catch block
oee.printStackTrace();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (processingMap.remove(bundle) == REMOVING_OBJECT) {
stopEJBs(bundle);
}
}
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class ActivationConfigPropertyOverrideTest method testEjbNameOverrideSystem.
public void testEjbNameOverrideSystem() throws Exception {
SystemInstance.reset();
final Properties properties = SystemInstance.get().getProperties();
properties.setProperty("Orange.activation.maxSessions", "20");
properties.setProperty("Orange.activation.maxMessagesPerSessions", "100");
properties.setProperty("Orange.activation.destinationType", "javax.jms.Queue");
properties.setProperty("Orange.activation.destination", "OVERRIDDEN.QUEUE");
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
// just to make sure class name is not used
ejbJar.addEnterpriseBean(new MessageDrivenBean("Yellow", Orange.class));
// just to make sure class name is not used
ejbJar.addEnterpriseBean(new MessageDrivenBean("Orange", Yellow.class));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
assertEquals(2, ejbJarInfo.enterpriseBeans.size());
final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
assertEquals("7", orange.activationProperties.get("maxSessions"));
assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));
assertEquals("20", yellow.activationProperties.get("maxSessions"));
assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class ActivationConfigPropertyOverrideTest method testEjbNameOverrideOpenejbJar.
public void testEjbNameOverrideOpenejbJar() throws Exception {
SystemInstance.reset();
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
{
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
final OpenejbJar openejbJar = new OpenejbJar();
final Properties properties = openejbJar.getProperties();
properties.setProperty("mdb.activation.maxSessions", "20");
properties.setProperty("mdb.activation.maxMessagesPerSessions", "100");
properties.setProperty("mdb.activation.destinationType", "javax.jms.Queue");
properties.setProperty("mdb.activation.destination", "OVERRIDDEN.QUEUE");
final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
assertEquals(2, ejbJarInfo.enterpriseBeans.size());
final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
assertEquals("20", orange.activationProperties.get("maxSessions"));
assertEquals("100", orange.activationProperties.get("maxMessagesPerSessions"));
assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
assertEquals("OVERRIDDEN.QUEUE", orange.activationProperties.get("destination"));
assertEquals("20", yellow.activationProperties.get("maxSessions"));
assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
}
// Verify the openejb-jar level overrides do not affect other apps
{
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
assertEquals(2, ejbJarInfo.enterpriseBeans.size());
final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
assertEquals("7", orange.activationProperties.get("maxSessions"));
assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));
assertEquals("5", yellow.activationProperties.get("maxSessions"));
assertEquals("10", yellow.activationProperties.get("maxMessagesPerSessions"));
assertEquals("javax.jms.Topic", yellow.activationProperties.get("destinationType"));
assertEquals("YELLOW.TOPIC", yellow.activationProperties.get("destination"));
}
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class AltDDPrefixTest method testMultitplePrefixes.
public void testMultitplePrefixes() throws Exception {
System.out.println("*** testMultitplePrefixes ***");
final Assembler assmbler = new Assembler();
SystemInstance.get().setProperty("openejb.altdd.prefix", "footest, test");
DeploymentLoader.reloadAltDD();
final ConfigurationFactory factory = new ConfigurationFactory();
final URL resource = AltDDPrefixTest.class.getClassLoader().getResource("altddapp2");
final File file = URLs.toFile(resource);
final AppInfo appInfo = factory.configureApplication(file);
assertNotNull(appInfo);
assertEquals(1, appInfo.ejbJars.size());
final EjbJarInfo ejbJar = appInfo.ejbJars.get(0);
// was the footest.ejb-jar.xml picked up
assertEquals("EjbJar.enterpriseBeans", 1, ejbJar.enterpriseBeans.size());
assertEquals("EjbJar.interceptors.size()", 1, ejbJar.interceptors.size());
// was the test.env-entries.properties picked up
// 4 + ComponentName
assertEquals("EjbJar.enterpriseBeans.get(0).jndiEnc.envEntries.size()", 5, ejbJar.enterpriseBeans.get(0).jndiEnc.envEntries.size());
}
use of org.apache.openejb.assembler.classic.EjbJarInfo in project tomee by apache.
the class DeploymentContextPropertiesTest method testModuleContextProperties.
public void testModuleContextProperties() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
{
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
}
{
// Setup the descriptor information
final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
openejbJar.getProperties().setProperty("color", "orange");
ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
final EjbJarInfo moduleInfo = config.configureApplication(ejbModule);
assertProperty(moduleInfo.properties, "color", "orange");
assembler.createApplication(moduleInfo);
}
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
final Properties properties = beanContext.getModuleContext().getProperties();
assertProperty(properties, "color", "orange");
}
Aggregations