Search in sources :

Example 61 with StatelessBean

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

the class InterceptorBindingEjbTest method ejbJar.

/**
 * aims to test that method level cdi interceptors are well managed (and not all merged in class level interceptors).
 *
 * @return the needed module
 */
@Module
public EjbModule ejbJar() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean("ejb1", EJB1.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb2", EJB2.class));
    final Beans beans = new Beans();
    beans.addInterceptor(MarkedInterceptor.class);
    final EjbModule module = new EjbModule(ejbJar);
    module.setBeans(beans);
    return module;
}
Also used : Beans(org.apache.openejb.jee.Beans) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module)

Example 62 with StatelessBean

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

the class JndiTest method test.

public void test() throws Exception {
    EjbServer ejbServer = new EjbServer();
    Properties initProps = new Properties();
    initProps.put(DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY, Boolean.toString(false));
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    ServiceDaemon serviceDaemon = new ServiceDaemon(ejbServer, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    ConfigurationFactory config = new ConfigurationFactory();
    EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean("Orange", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Apple", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Peach", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Pear", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Plum", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Orange", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Apple", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Peach", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Pear", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Plum", Fruit.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    try {
        // good creds
        Properties props = new Properties();
        props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
        props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
        Context context = new InitialContext(props);
        assertNameClassPair(context.list(""));
        assertNameClassPair(context.list("ejb"));
        assertBindings(context.listBindings(""));
        assertBindings(context.listBindings("ejb"));
    } finally {
        serviceDaemon.stop();
        OpenEJB.destroy();
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ServerFederation(org.apache.openejb.core.ServerFederation) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) EjbServer(org.apache.openejb.server.ejbd.EjbServer) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EjbJar(org.apache.openejb.jee.EjbJar)

Example 63 with StatelessBean

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

the class DynamicConnectionStrategyTest method test.

public void test() throws Exception {
    ConnectionManager.registerStrategy("test", new TestConnectionStrategy());
    EjbServer ejbServer = new EjbServer();
    Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    ServicePool pool = new ServicePool(ejbServer, 10);
    ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    ConfigurationFactory config = new ConfigurationFactory();
    EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    EjbJar ejbJar = ejbModule.getEjbJar();
    OpenejbJar openejbJar = ejbModule.getOpenejbJar();
    StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
    deployment.getProperties().put("openejb.client.connection.strategy", "test");
    assembler.createApplication(config.configureApplication(ejbModule));
    Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
    Context context = new InitialContext(props);
    Widget remote = (Widget) context.lookup("WidgetBeanRemote");
    assertFalse(TestConnectionStrategy.called.get());
    remote.echo("foo");
    assertTrue(TestConnectionStrategy.called.get());
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 64 with StatelessBean

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

the class FailoverConnectionFactoryTest method test.

public void test() throws Exception {
    ConnectionManager.registerStrategy("test", new TestConnectionStrategy());
    EjbServer ejbServer = new EjbServer();
    Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    ServicePool pool = new ServicePool(ejbServer, 10);
    ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    ConfigurationFactory config = new ConfigurationFactory();
    EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    EjbJar ejbJar = ejbModule.getEjbJar();
    OpenejbJar openejbJar = ejbModule.getOpenejbJar();
    StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
    deployment.getProperties().put("openejb.client.connection.strategy", "test");
    assembler.createApplication(config.configureApplication(ejbModule));
    Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", "failover:sticky:ejbd://agwdt:9999,ejbd://127.0.0.1:" + port);
    Context context = new InitialContext(props);
    Widget remote = (Widget) context.lookup("WidgetBeanRemote");
    assertFalse(TestConnectionStrategy.called.get());
    remote.echo("foo");
    assertTrue(TestConnectionStrategy.called.get());
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 65 with StatelessBean

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

the class UberInterfaceTest method test.

public void test() throws Exception {
    final EjbServer ejbServer = new EjbServer();
    final Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    final ServicePool pool = new ServicePool(ejbServer, 10);
    final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    final int port = serviceDaemon.getPort();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    assertEquals(asList(Everything.class.getName()), beanInfo.businessLocal);
    assertEquals(asList(Everything.class.getName()), beanInfo.businessRemote);
    assembler.createApplication(ejbJarInfo);
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext deployment = containerSystem.getBeanContext(beanInfo.ejbDeploymentId);
    assertEquals(asList(Everything.class), deployment.getBusinessLocalInterfaces());
    assertEquals(asList(Everything.class), deployment.getBusinessRemoteInterfaces());
    {
        // remote invoke
        final Properties props = new Properties();
        props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
        props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
        final Context context = new InitialContext(props);
        final Everything remote = (Everything) context.lookup("SuperBeanRemote");
        final Reference reference = new Reference("test");
        assertEquals(reference, remote.echo(reference));
        // pass by value
        assertNotSame(reference, remote.echo(reference));
    }
    {
        // local invoke
        final Properties props = new Properties();
        props.put("java.naming.factory.initial", "org.apache.openejb.core.LocalInitialContextFactory");
        final Context context = new InitialContext(props);
        final Everything local = (Everything) context.lookup("SuperBeanLocal");
        final Reference reference = new Reference("test");
        assertEquals(reference, local.echo(reference));
        // pass by reference
        assertSame(reference, local.echo(reference));
    }
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitialContext(javax.naming.InitialContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

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