Search in sources :

Example 81 with StatelessBean

use of org.apache.openejb.jee.StatelessBean in project tomee by apache.

the class JTAPuAndBmtTest method app.

@Module
public StatelessBean app() throws Exception {
    final StatelessBean bean = new StatelessBean(BmtManager.class);
    bean.setLocalBean(new Empty());
    return bean;
}
Also used : Empty(org.apache.openejb.jee.Empty) StatelessBean(org.apache.openejb.jee.StatelessBean) Module(org.apache.openejb.testing.Module)

Example 82 with StatelessBean

use of org.apache.openejb.jee.StatelessBean in project tomee by apache.

the class SecondStatelessInterceptedTest method module.

@Module
public EjbJar module() {
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(SecondStatelessInterceptedBean.class));
    final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();
    assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
    assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));
    assembly.addInterceptorBinding(new InterceptorBinding(bean)).setExcludeDefaultInterceptors(true);
    return ejbJar;
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar) Module(org.apache.openejb.testing.Module)

Example 83 with StatelessBean

use of org.apache.openejb.jee.StatelessBean in project tomee by apache.

the class OpenejbLookupTest method testLocalInitialContext.

public void testLocalInitialContext() throws Exception {
    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 StatelessBean(FooBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    final Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    Context context = new InitialContext(properties);
    // This is still the jvm InitialContext delegating to the openejbURLContextFactory
    assertTrue(context instanceof InitialContext);
    assertOpenejbUrlLookups(context);
    // Now we have effectively unwrapped the InitalContext, openejb: lookups should still work.
    context = (Context) context.lookup("");
    assertTrue(context instanceof IvmContext);
    assertOpenejbUrlLookups(context);
    // Test that an EJB can lookup items from openejb:
    final FooLocal fooLocal = (FooLocal) context.lookup("FooBeanLocal");
    fooLocal.test();
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 84 with StatelessBean

use of org.apache.openejb.jee.StatelessBean in project tomee by apache.

the class EjbContextTest method test.

public void test() throws Exception {
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean("Stateful", MySessionBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Stateless", MySessionBean.class));
    ejbJar.addEnterpriseBean(new SingletonBean("Singleton", MySessionBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    final Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    final InitialContext context = new InitialContext(properties);
    {
        final MySessionBean bean = (MySessionBean) context.lookup("StatefulLocalBean");
        bean.test();
    }
    {
        final MySessionBean bean = (MySessionBean) context.lookup("StatelessLocalBean");
        bean.test();
    }
    {
        final MySessionBean bean = (MySessionBean) context.lookup("SingletonLocalBean");
        bean.test();
    }
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) StatefulBean(org.apache.openejb.jee.StatefulBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.osgi.client.LocalInitialContextFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) InitialContext(javax.naming.InitialContext) EjbJar(org.apache.openejb.jee.EjbJar)

Example 85 with StatelessBean

use of org.apache.openejb.jee.StatelessBean in project tomee by apache.

the class AsynchTest method testMethodScopeAsynch.

@SuppressWarnings("UseOfSystemOutOrSystemErr")
@Test
public void testMethodScopeAsynch() throws Exception {
    System.out.println(long.class.getName());
    System.out.println(String[].class.getCanonicalName());
    // Build the application
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testasynch");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(TestBeanC.class));
    ejbJar.addEnterpriseBean(new SingletonBean(TestBeanD.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final InitialContext context = new InitialContext();
    final String[] beans = new String[] { "TestBeanCLocal", "TestBeanDLocal" };
    for (final String beanName : beans) {
        final TestBean testBean = (TestBean) context.lookup(beanName);
        testBean.testA(Thread.currentThread().getId());
        Thread.sleep(1000L);
        Assert.assertEquals("testA was never executed", "testA", testBean.getLastInvokeMethod());
        final Future<String> future = testBean.testB(Thread.currentThread().getId());
        Thread.sleep(1000L);
        Assert.assertTrue("The task should be done", future.isDone());
        Assert.assertEquals("testB was never executed", "testB", testBean.getLastInvokeMethod());
        testBean.testC(Thread.currentThread().getId());
        Assert.assertEquals("testC was never executed", "testC", testBean.getLastInvokeMethod());
        testBean.testD(Thread.currentThread().getId());
        Assert.assertEquals("testD was never executed", "testD", testBean.getLastInvokeMethod());
    }
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) InitialContext(javax.naming.InitialContext) AppInfo(org.apache.openejb.assembler.classic.AppInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Aggregations

StatelessBean (org.apache.openejb.jee.StatelessBean)132 EjbJar (org.apache.openejb.jee.EjbJar)120 Assembler (org.apache.openejb.assembler.classic.Assembler)58 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)46 EjbModule (org.apache.openejb.config.EjbModule)39 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)33 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)33 InitialContext (javax.naming.InitialContext)31 Properties (java.util.Properties)30 Module (org.apache.openejb.testing.Module)25 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)19 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)18 AppModule (org.apache.openejb.config.AppModule)18 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)17 ServerFederation (org.apache.openejb.core.ServerFederation)15 Context (javax.naming.Context)14 ContainerSystem (org.apache.openejb.spi.ContainerSystem)14 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)13 Empty (org.apache.openejb.jee.Empty)13 StatefulBean (org.apache.openejb.jee.StatefulBean)12