use of org.apache.openejb.config.ConfigurationFactory 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.config.ConfigurationFactory in project tomee by apache.
the class CdiDecoratorTest method setUp.
@Before
public void setUp() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean("HelloOne", RedBean.class));
ejbJar.addEnterpriseBean(new StatelessBean("HelloTwo", RedBean.class));
ejbJar.addEnterpriseBean(new StatelessBean(OrangeBean.class));
final Beans beans = new Beans();
beans.addInterceptor(OrangeCdiInterceptor.class);
beans.addDecorator(OrangeOneDecorator.class);
beans.addDecorator(OrangeTwoDecorator.class);
beans.addManagedClass(YellowBean.class);
final EjbModule module = new EjbModule(ejbJar);
module.setBeans(beans);
assembler.createApplication(config.configureApplication(module));
final Properties properties = new Properties(System.getProperties());
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
ctx = new InitialContext(properties);
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class RedeployTest method test.
public void test() throws Exception {
// create reference to openejb itests
final File file = JarLocation.jarLocation(BasicStatelessBean.class);
if (!file.exists()) {
throw new Exception("File not found: " + file);
}
// These two objects pretty much encompas all the EJB Container
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
createAndDestroy(assembler, config, file);
createAndDestroy(assembler, config, file);
createAndDestroy(assembler, config, file);
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class EjbRefTest method setUp.
protected void setUp() throws Exception {
config = new ConfigurationFactory();
assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
context = new InitialContext();
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class EjbSecurityRoleRefTest method setUp.
protected void setUp() throws Exception {
config = new ConfigurationFactory();
assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
final Properties props = new Properties();
props.setProperty(Context.SECURITY_PRINCIPAL, "jonathan");
props.setProperty(Context.SECURITY_CREDENTIALS, "secret");
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
context = new InitialContext(props);
}
Aggregations