use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class CheckRestMethodArePublic method validate.
@Override
public void validate(final AppModule appModule) {
// valid standalone classes
final Collection<String> standAloneClasses = new ArrayList<String>();
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
for (final EjbModule ejb : appModule.getEjbModules()) {
Thread.currentThread().setContextClassLoader(ejb.getClassLoader());
for (final EnterpriseBean bean : ejb.getEjbJar().getEnterpriseBeans()) {
if (bean instanceof SessionBean && ((SessionBean) bean).isRestService()) {
standAloneClasses.add(bean.getEjbClass());
valid(ejb.getValidation(), ejb.getClassLoader(), bean.getEjbClass());
}
}
}
for (final WebModule web : appModule.getWebModules()) {
Thread.currentThread().setContextClassLoader(web.getClassLoader());
// build the list of classes to validate
final Collection<String> classes = new ArrayList<String>();
classes.addAll(web.getRestClasses());
classes.addAll(web.getEjbRestServices());
for (final String app : web.getRestApplications()) {
final Class<?> clazz;
try {
clazz = web.getClassLoader().loadClass(app);
} catch (final ClassNotFoundException e) {
// managed elsewhere, here we just check methods
continue;
}
final Application appInstance;
try {
appInstance = (Application) clazz.newInstance();
} catch (final Exception e) {
// managed elsewhere
continue;
}
try {
for (final Class<?> rsClass : appInstance.getClasses()) {
classes.add(rsClass.getName());
}
/* don't do it or ensure you have cdi activated! + CXF will catch it later
for (final Object rsSingleton : appInstance.getSingletons()) {
classes.add(rsSingleton.getClass().getName());
}
*/
} catch (final RuntimeException npe) {
if (appInstance == null) {
throw npe;
}
// if app relies on cdi it is null here
}
}
// try to avoid to valid twice the same classes
final Iterator<String> it = classes.iterator();
while (it.hasNext()) {
final String current = it.next();
if (standAloneClasses.contains(current)) {
it.remove();
}
}
// valid
for (final String classname : classes) {
valid(web.getValidation(), web.getClassLoader(), classname);
}
classes.clear();
}
} finally {
Thread.currentThread().setContextClassLoader(loader);
}
standAloneClasses.clear();
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class QuartzMdbContainerTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
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
CronBean.lifecycle.clear();
final AppModule app = new AppModule(this.getClass().getClassLoader(), "testapp");
final Connector connector = new Connector("email-ra");
final ResourceAdapter adapter = new ResourceAdapter(QuartzResourceAdapter.class);
connector.setResourceAdapter(adapter);
final InboundResourceadapter inbound = adapter.setInboundResourceAdapter(new InboundResourceadapter());
final MessageAdapter messageAdapter = inbound.setMessageAdapter(new MessageAdapter());
final MessageListener listener = messageAdapter.addMessageListener(new MessageListener(Job.class, JobSpec.class));
listener.getActivationSpec().addRequiredConfigProperty("cronExpression");
app.getConnectorModules().add(new ConnectorModule(connector));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new MessageDrivenBean(CronBean.class));
app.getEjbModules().add(new EjbModule(ejbJar));
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
assertTrue(CronBean.latch.await(5, TimeUnit.SECONDS));
final Stack<Lifecycle> lifecycle = CronBean.lifecycle;
final List expected = Arrays.asList(Lifecycle.values());
Assert.assertEquals(expected.get(0), lifecycle.get(0));
Assert.assertEquals(expected.get(1), lifecycle.get(1));
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class EjbObjectInputStreamTest method testShouldAllowPrimitiveArraysToBeSerialized.
@Test
public void testShouldAllowPrimitiveArraysToBeSerialized() throws Exception {
final EjbJar ejbJar = new EjbJar();
final StatelessBean statelessBean = new StatelessBean(TestBean.class);
ejbJar.addEnterpriseBean(statelessBean);
final AppModule app = new AppModule(this.getClass().getClassLoader(), "Test");
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.setModuleId("EjbModule");
app.getEjbModules().add(ejbModule);
assembler.createApplication(config.configureApplication(app));
final TestRemote testBean = (TestRemote) context.lookup("TestBeanRemote");
assertEquals('J', testBean.getChar());
assertEquals("Hello", new String(testBean.getCharArray()));
assertEquals("test", new String(testBean.getCharArrayArray()[0]));
assertEquals("run", new String(testBean.getCharArrayArray()[1]));
assertEquals(1, testBean.getIntArray()[0]);
assertEquals(2, testBean.getIntArray()[1]);
assertEquals(true, testBean.getBooleanArray()[0]);
assertEquals(false, testBean.getBooleanArray()[1]);
assertEquals(0xD, testBean.getByteArray()[0]);
assertEquals(0xE, testBean.getByteArray()[1]);
assertEquals(0xA, testBean.getByteArray()[2]);
assertEquals(0xD, testBean.getByteArray()[3]);
assertEquals(0xB, testBean.getByteArray()[4]);
assertEquals(0xE, testBean.getByteArray()[5]);
assertEquals(0xE, testBean.getByteArray()[6]);
assertEquals(0xF, testBean.getByteArray()[7]);
assertEquals(1, testBean.getShortArray()[0]);
assertEquals(2, testBean.getShortArray()[1]);
assertEquals(1.1f, testBean.getFloatArray()[0], 0.001);
assertEquals(2.2f, testBean.getFloatArray()[1], 0.001);
assertEquals(5L, testBean.getLongArray()[0]);
assertEquals(6L, testBean.getLongArray()[1]);
assertEquals(1.1, testBean.getDoubleArray()[0], 0.001);
assertEquals(2.2, testBean.getDoubleArray()[1], 0.001);
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class AsynchInRoleTest method testSessionContext.
@Test
public void testSessionContext() throws Exception {
//Build the application
final AppModule app = new AppModule(this.getClass().getClassLoader(), "testcanceltask");
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(TestBeanB.class));
app.getEjbModules().add(new EjbModule(ejbJar));
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
final Properties env = new Properties();
env.put(javax.naming.Context.SECURITY_PRINCIPAL, "jonathan");
env.put(javax.naming.Context.SECURITY_CREDENTIALS, "secret");
final InitialContext context = new InitialContext(env);
final TestBean test = (TestBean) context.lookup("TestBeanBLocal");
test.testA(Thread.currentThread().getId());
Assert.assertEquals("testA was never executed", "testA", test.getLastInvokeMethod());
final Future<String> future = test.testB(Thread.currentThread().getId());
Thread.sleep(1000L);
Assert.assertFalse(future.cancel(true));
Assert.assertFalse(future.isCancelled());
Assert.assertFalse(future.isDone());
Thread.sleep(3000L);
Assert.assertTrue(future.isDone());
Assert.assertEquals("testB was never executed", "testB", test.getLastInvokeMethod());
test.testC(Thread.currentThread().getId());
Assert.assertEquals("testC was never executed", "testC", test.getLastInvokeMethod());
test.testD(Thread.currentThread().getId());
Thread.sleep(3000L);
Assert.assertEquals("testD was never executed", "testD", test.getLastInvokeMethod());
context.close();
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class AppModuleBuilder method anAppModule.
public AppModuleBuilder anAppModule() {
ejbModule = new EjbModule(getClass().getClassLoader(), "FakeEjbJar", "fake.jar", ejbJar, null);
ejbModule.setOpenejbJar(openEJBJar);
return this;
}
Aggregations