Search in sources :

Example 66 with StatelessBean

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

the class KeepAilveTest method test.

public void test() throws Exception {
    final EjbServer ejbServer = new EjbServer();
    final KeepAliveServer keepAliveServer = new KeepAliveServer(ejbServer, false);
    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(keepAliveServer, 10, 5000, true);
    final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    try {
        final int port = serviceDaemon.getPort();
        final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
        final ConfigurationFactory config = new ConfigurationFactory();
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(EchoBean.class));
        assembler.createApplication(config.configureApplication(ejbJar));
        // good creds
        final int threads = 1;
        final CountDownLatch latch = new CountDownLatch(threads);
        final Collection<Thread> th = new ArrayList<>(threads);
        for (int i = 0; i < threads; i++) {
            final Client client = new Client(latch, i, port);
            th.add(thread(client, false));
        }
        final boolean await = latch.await(60, TimeUnit.SECONDS);
        assertTrue(await);
        for (final Thread t : th) {
            t.join(1000);
        }
    } finally {
        serviceDaemon.stop();
        OpenEJB.destroy();
    }
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) ArrayList(java.util.ArrayList) Properties(java.util.Properties) CountDownLatch(java.util.concurrent.CountDownLatch) 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) EjbJar(org.apache.openejb.jee.EjbJar)

Example 67 with StatelessBean

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

the class StaticFailoverTest method testStatelessBeanTimeout.

public void testStatelessBeanTimeout() throws Exception {
    Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    System.setProperty(org.apache.openejb.client.SocketConnectionFactory.PROPERTY_POOL_SIZE, "" + 20);
    EjbServer ejbServer = new EjbServer();
    ejbServer.init(new Properties());
    daemons.add(createServiceDaemon(20, ejbServer, red));
    daemons.add(createServiceDaemon(20, ejbServer, blue));
    ConfigurationFactory config = new ConfigurationFactory();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    // containers
    StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "100");
    statelessContainerInfo.properties.setProperty("PoolSize", "" + 10);
    statelessContainerInfo.properties.setProperty("MinSize", "2");
    statelessContainerInfo.properties.setProperty("StrictPooling", "true");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    StatelessBean bean = new StatelessBean(CounterBean.class);
    bean.addBusinessLocal(Counter.class.getName());
    bean.addBusinessRemote(RemoteCounter.class.getName());
    bean.addPostConstruct("init");
    bean.addPreDestroy("destroy");
    EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);
    CounterBean.instances.set(0);
    assembler.createApplication(config.configureApplication(ejbJar));
    String failoverURI = "failover:roundrobin:";
    failoverURI += "ejbd://127.0.0.1:" + daemons.get(0).getPort() + "?red,";
    failoverURI += "ejbd://127.0.0.1:" + daemons.get(1).getPort() + "?blue";
    Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", failoverURI);
    Context context = new InitialContext(props);
    counter = (Counter) context.lookup("CounterBeanRemote");
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 68 with StatelessBean

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

the class MultithreadTest method setUp.

@Before
public void setUp() throws Exception {
    final int poolSize = 10;
    System.setProperty("openejb.client.connectionpool.size", "" + (poolSize * 2));
    final EjbServer ejbServer = new EjbServer();
    final KeepAliveServer keepAliveServer = new KeepAliveServer(ejbServer, false);
    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(keepAliveServer, (poolSize * 2));
    this.serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    final int port = serviceDaemon.getPort();
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "100");
    statelessContainerInfo.properties.setProperty("PoolSize", "" + poolSize);
    statelessContainerInfo.properties.setProperty("MinSize", "2");
    statelessContainerInfo.properties.setProperty("StrictPooling", "true");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final StatelessBean bean = new StatelessBean(CounterBean.class);
    bean.addBusinessLocal(Counter.class.getName());
    bean.addBusinessRemote(RemoteCounter.class.getName());
    bean.addPostConstruct("init");
    bean.addPreDestroy("destroy");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);
    CounterBean.instances.set(0);
    assembler.createApplication(config.configureApplication(ejbJar));
    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);
    counter = (Counter) context.lookup("CounterBeanRemote");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) 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) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Example 69 with StatelessBean

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

the class EjbSecurityRoleRefTest method testShouldCheckUserRole.

public void testShouldCheckUserRole() throws Exception {
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean statelessBean = new StatelessBean(UserBean.class);
    final SecurityRoleRef securityRoleRef = new SecurityRoleRef();
    securityRoleRef.setRoleName("TEST");
    securityRoleRef.setRoleLink("committer");
    statelessBean.getSecurityRoleRef().add(securityRoleRef);
    ejbJar.addEnterpriseBean(statelessBean);
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "classpath-" + ejbJar.hashCode());
    app.getEjbModules().add(new EjbModule(ejbJar));
    assembler.createApplication(config.configureApplication(app));
    final User user = (User) context.lookup("UserBeanLocal");
    assertTrue(user.isUserInRole());
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) SecurityRoleRef(org.apache.openejb.jee.SecurityRoleRef) EjbJar(org.apache.openejb.jee.EjbJar)

Example 70 with StatelessBean

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

the class DeploymentContextOptionsTest method testSystemInstanceOptions.

public void testSystemInstanceOptions() throws Exception {
    SystemInstance.get().setProperty("color", "orange");
    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
        final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final AppModule appModule = new AppModule(ejbModule);
        assembler.createApplication(config.configureApplication(appModule));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    assertOption(beanContext.getOptions(), "color", "orange");
    assertOption(beanContext.getModuleContext().getOptions(), "color", "orange");
    assertOption(beanContext.getModuleContext().getAppContext().getOptions(), "color", "orange");
    assertOption(SystemInstance.get().getOptions(), "color", "orange");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) Assembler(org.apache.openejb.assembler.classic.Assembler) 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