Search in sources :

Example 21 with EjbModule

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();
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) ArrayList(java.util.ArrayList) EjbModule(org.apache.openejb.config.EjbModule) WebModule(org.apache.openejb.config.WebModule) SessionBean(org.apache.openejb.jee.SessionBean) Application(javax.ws.rs.core.Application)

Example 22 with EjbModule

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));
}
Also used : Connector(org.apache.openejb.jee.Connector) MessageAdapter(org.apache.openejb.jee.MessageAdapter) AppModule(org.apache.openejb.config.AppModule) MessageListener(org.apache.openejb.jee.MessageListener) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) ConnectorModule(org.apache.openejb.config.ConnectorModule) AppInfo(org.apache.openejb.assembler.classic.AppInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) QuartzResourceAdapter(org.apache.openejb.resource.quartz.QuartzResourceAdapter) ResourceAdapter(org.apache.openejb.jee.ResourceAdapter) List(java.util.List) Assembler(org.apache.openejb.assembler.classic.Assembler) JobSpec(org.apache.openejb.resource.quartz.JobSpec) InboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter) Job(org.apache.openejb.quartz.Job) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 23 with EjbModule

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);
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 24 with EjbModule

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();
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

Example 25 with EjbModule

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;
}
Also used : EjbModule(org.apache.openejb.config.EjbModule)

Aggregations

EjbModule (org.apache.openejb.config.EjbModule)88 EjbJar (org.apache.openejb.jee.EjbJar)78 AppModule (org.apache.openejb.config.AppModule)40 StatelessBean (org.apache.openejb.jee.StatelessBean)37 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)29 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)29 Assembler (org.apache.openejb.assembler.classic.Assembler)26 Properties (java.util.Properties)23 SingletonBean (org.apache.openejb.jee.SingletonBean)21 InitialContext (javax.naming.InitialContext)19 Module (org.apache.openejb.testing.Module)16 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)15 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)12 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)12 Beans (org.apache.openejb.jee.Beans)12 AppInfo (org.apache.openejb.assembler.classic.AppInfo)10 ContainerSystem (org.apache.openejb.spi.ContainerSystem)10 ArrayList (java.util.ArrayList)9 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)9 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)9