use of org.apache.openejb.config.EjbModule 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.EjbModule in project tomee by apache.
the class TestClassDiscoverer method discover.
@Override
public AppModule discover(final AppModule module) {
final Set<Class<?>> testClasses = new HashSet<>();
final Map<Class<?>, WebModule> webTestClasses = new HashMap<>();
final Set<ClassLoader> saw = new HashSet<>();
if (module.getClassLoader() != null) {
addTests(findMarkers(module.getClassLoader()), findClassMarkers(module.getClassLoader()), module.getEarLibFinder(), testClasses);
saw.add(module.getClassLoader());
}
for (final WebModule web : module.getWebModules()) {
if (web.getClassLoader() != null && !saw.contains(web.getClassLoader())) {
final Set<Class<?>> classes = new HashSet<>();
addTests(findMarkers(web.getClassLoader()), findClassMarkers(web.getClassLoader()), web.getFinder(), classes);
saw.add(web.getClassLoader());
for (final Class<?> c : classes) {
webTestClasses.put(c, web);
}
// in case of an ear if we find the same test class in a webapp we don't want it in lib part
// this case can happen in tomee-embedded mainly
final Iterator<Class<?>> c = testClasses.iterator();
while (c.hasNext()) {
final String cl = c.next().getName();
for (final Class<?> wc : classes) {
if (cl.equals(wc.getName())) {
c.remove();
break;
}
}
}
testClasses.addAll(classes);
}
}
for (final EjbModule ejb : module.getEjbModules()) {
if (ejb.getClassLoader() != null && !saw.contains(ejb.getClassLoader())) {
addTests(findMarkers(ejb.getClassLoader()), findClassMarkers(ejb.getClassLoader()), ejb.getFinder(), testClasses);
saw.add(ejb.getClassLoader());
}
}
for (final ConnectorModule connector : module.getConnectorModules()) {
if (connector.getClassLoader() != null && !saw.contains(connector.getClassLoader())) {
addTests(findMarkers(connector.getClassLoader()), findClassMarkers(connector.getClassLoader()), connector.getFinder(), testClasses);
saw.add(connector.getClassLoader());
}
}
// keep it since CukeSpace doesn't rely on JUnit or TestNG @Test so it stays mandatory
final File file = module.getFile();
final String line = findTestName(file, module.getClassLoader());
if (line != null) {
String name;
final int endIndex = line.indexOf('#');
if (endIndex > 0) {
name = line.substring(0, endIndex);
if (file != null && !file.getName().equals(line.substring(endIndex + 1, line.length()))) {
name = null;
}
} else {
name = line;
}
if (name != null) {
boolean found = false;
for (final WebModule web : module.getWebModules()) {
try {
testClasses.add(web.getClassLoader().loadClass(name));
found = true;
break;
} catch (final Throwable e) {
// no-op
}
}
if (!found) {
try {
testClasses.add(module.getClassLoader().loadClass(name));
} catch (final Throwable e) {
// no-op
}
}
}
}
final Iterator<Class<?>> it = testClasses.iterator();
while (it.hasNext()) {
try {
// call some reflection methods to make it fail if some dep are missing...
Class<?> current = it.next();
if (!AnnotationDeployer.isInstantiable(current)) {
it.remove();
continue;
}
while (current != null) {
current.getDeclaredFields();
current.getDeclaredMethods();
current.getCanonicalName();
current = current.getSuperclass();
// TODO: more validations
}
} catch (final NoClassDefFoundError ncdfe) {
it.remove();
}
}
for (final Class<?> test : testClasses) {
final EjbJar ejbJar = new EjbJar();
final OpenejbJar openejbJar = new OpenejbJar();
final String name = test.getName();
final String ejbName = module.getModuleId() + "_" + name;
final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(ejbName, name, true));
bean.localBean();
bean.setTransactionType(TransactionType.BEAN);
final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
ejbDeployment.setDeploymentId(ejbName);
final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
ejbModule.setClassLoader(test.getClassLoader());
final WebModule webModule = webTestClasses.get(test);
if (webModule != null) {
ejbModule.setWebapp(true);
ejbModule.getProperties().put("openejb.ejbmodule.webappId", webModule.getModuleId());
}
ejbModule.getProperties().put("openejb.ejbmodule.MergeWebappJndiContext", "true");
module.getEjbModules().add(ejbModule);
}
return module;
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class CdiDecoratorMultipleDelegateCallsTest method classes.
@Module
@Classes({ ServiceImpl.class })
public EjbModule classes() {
final Beans beans = new Beans();
beans.addDecorator(ServiceDecorator.class);
final EjbModule jar = new EjbModule(new EjbJar());
jar.setBeans(beans);
return jar;
}
use of org.apache.openejb.config.EjbModule 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.EjbModule in project tomee by apache.
the class EjbRefTest method ear.
private void ear(final EjbJar... ejbJars) throws OpenEJBException, NamingException, IOException {
final AppModule app = new AppModule(this.getClass().getClassLoader(), "classpath-" + ejbJars.hashCode());
for (final EjbJar ejbJar : ejbJars) {
app.getEjbModules().add(new EjbModule(ejbJar));
}
assembler.createApplication(config.configureApplication(app));
}
Aggregations