Search in sources :

Example 11 with ServicePool

use of org.apache.openejb.server.ServicePool in project tomee by apache.

the class AppClientTest 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();
    int port = serviceDaemon.getPort();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbModule ejbModule = new EjbModule(new EjbJar("testejbmodule"), new OpenejbJar());
    final EjbJar ejbJar = ejbModule.getEjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(Orange.class));
    final ClassLoader loader = this.getClass().getClassLoader();
    final ClientModule clientModule = new ClientModule(new ApplicationClient(), loader, "orange-client", OrangeAppClient.class.getName(), "orange-client");
    final AppModule appModule = new AppModule(loader, "testapp");
    appModule.getClientModules().add(clientModule);
    appModule.getEjbModules().add(ejbModule);
    assembler.createApplication(config.configureApplication(appModule));
    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);
    props.put("openejb.client.moduleId", "orange-client");
    Context context = new InitialContext(props);
    final Object home = context.lookup("comp/env/home");
    assertTrue(home instanceof OrangeHome);
    OrangeHome orangeHome = (OrangeHome) home;
    final OrangeRemote orangeRemote = orangeHome.create();
    assertEquals("bat", orangeRemote.echo("tab"));
    final Object business = context.lookup("comp/env/business");
    assertTrue(business instanceof OrangeBusinessRemote);
    OrangeBusinessRemote orangeBusinessRemote = (OrangeBusinessRemote) business;
    assertEquals("nap", orangeBusinessRemote.echo("pan"));
    final Object dataSourceObject = context.lookup("comp/env/datasource");
    assertTrue(dataSourceObject instanceof DataSource);
    //        DataSource dataSource = (DataSource) dataSourceObject;
    //        assertEquals("nap", orangeBusinessRemote.echo("pan"));
    props.put("openejb.client.moduleId", "openejb/global");
    context = new InitialContext(props);
    final Object global = context.lookup("global/testapp/testejbmodule/Orange!" + OrangeBusinessRemote.class.getName());
    assertTrue(global instanceof OrangeBusinessRemote);
    OrangeBusinessRemote globalOrangeBusinessRemote = (OrangeBusinessRemote) global;
    assertEquals("nap", globalOrangeBusinessRemote.echo("pan"));
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ApplicationClient(org.apache.openejb.jee.ApplicationClient) ServicePool(org.apache.openejb.server.ServicePool) ClientModule(org.apache.openejb.config.ClientModule) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) EJBObject(javax.ejb.EJBObject) Assembler(org.apache.openejb.assembler.classic.Assembler)

Aggregations

ServicePool (org.apache.openejb.server.ServicePool)11 ServiceDaemon (org.apache.openejb.server.ServiceDaemon)10 Properties (java.util.Properties)8 Assembler (org.apache.openejb.assembler.classic.Assembler)7 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)7 ServerFederation (org.apache.openejb.core.ServerFederation)7 EjbJar (org.apache.openejb.jee.EjbJar)7 StatelessBean (org.apache.openejb.jee.StatelessBean)7 Context (javax.naming.Context)6 InitialContext (javax.naming.InitialContext)6 EjbModule (org.apache.openejb.config.EjbModule)4 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)4 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)3 BeanContext (org.apache.openejb.BeanContext)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)2 ContainerSystem (org.apache.openejb.spi.ContainerSystem)2 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 EJBObject (javax.ejb.EJBObject)1