Search in sources :

Example 16 with StatelessSessionContainerInfo

use of org.apache.openejb.assembler.classic.StatelessSessionContainerInfo in project tomee by apache.

the class JndiNameTest 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.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    ejbModule.getEjbJar().addEnterpriseBean(new StatelessBean(FooBean.class));
    final EjbDeployment ejbDeployment = new EjbDeployment(null, "FooBean", "FooBean");
    ejbDeployment.getJndi().add(new Jndi("thename", "Local"));
    ejbDeployment.getJndi().add(new Jndi("anothername", "Remote"));
    ejbDeployment.getJndi().add(new Jndi("loldstyle", "LocalHome"));
    ejbDeployment.getJndi().add(new Jndi("roldstyle", "RemoteHome"));
    ejbModule.getOpenejbJar().addEjbDeployment(ejbDeployment);
    assembler.createApplication(config.configureApplication(ejbModule));
    final InitialContext initialContext = new InitialContext();
    assertName(initialContext, Orange.class, "thename");
    assertName(initialContext, Red.class, "anothername");
    assertName(initialContext, LHYellow.class, "loldstyle");
    assertName(initialContext, RHGreen.class, "roldstyle");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Jndi(org.apache.openejb.jee.oejb3.Jndi) InitialContext(javax.naming.InitialContext) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 17 with StatelessSessionContainerInfo

use of org.apache.openejb.assembler.classic.StatelessSessionContainerInfo in project tomee by apache.

the class StatelessInstanceManagerPoolingTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "100");
    statelessContainerInfo.properties.setProperty("MaxSize", "10");
    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);
    instances.set(0);
    assembler.createApplication(config.configureApplication(ejbJar));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) 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) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 18 with StatelessSessionContainerInfo

use of org.apache.openejb.assembler.classic.StatelessSessionContainerInfo in project tomee by apache.

the class DynamicDataSourceTest method route.

@Test
public void route() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // resources
    for (int i = 1; i <= 3; i++) {
        final String dbName = "database" + i;
        final Resource resourceDs = new Resource(dbName, "DataSource");
        final Properties p = resourceDs.getProperties();
        p.put("JdbcDriver", "org.hsqldb.jdbcDriver");
        p.put("JdbcUrl", "jdbc:hsqldb:mem:db" + i);
        p.put("UserName", "sa");
        p.put("Password", "");
        p.put("JtaManaged", "true");
        assembler.createResource(config.configureService(resourceDs, ResourceInfo.class));
    }
    final Resource resourceRouter = new Resource("My Router", "org.apache.openejb.router.test.DynamicDataSourceTest$DeterminedRouter", "org.router:DeterminedRouter");
    resourceRouter.getProperties().setProperty("DatasourceNames", "database1 database2 database3");
    resourceRouter.getProperties().setProperty("DefaultDataSourceName", "database1");
    assembler.createResource(config.configureService(resourceRouter, ResourceInfo.class));
    final Resource resourceRoutedDs = new Resource("Routed Datasource", "org.apache.openejb.resource.jdbc.Router", "RoutedDataSource");
    resourceRoutedDs.getProperties().setProperty("Router", "My Router");
    assembler.createResource(config.configureService(resourceRoutedDs, ResourceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    assembler.createContainer(statelessContainerInfo);
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(RoutedEJBBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean(UtilityBean.class));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    // Create an "ear"
    final AppModule appModule = new AppModule(ejbModule.getClassLoader(), "test-dynamic-data-source");
    appModule.getEjbModules().add(ejbModule);
    // Create a persistence-units
    final PersistenceUnit unit = new PersistenceUnit("router");
    unit.addClass(Person.class);
    unit.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema");
    unit.setTransactionType(TransactionType.JTA);
    unit.setJtaDataSource("Routed Datasource");
    appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(unit)));
    for (int i = 1; i <= 3; i++) {
        final PersistenceUnit u = new PersistenceUnit("db" + i);
        u.addClass(Person.class);
        u.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema");
        u.setTransactionType(TransactionType.JTA);
        u.setJtaDataSource("database" + i);
        appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(u)));
    }
    assembler.createApplication(config.configureApplication(appModule));
    // context
    final Context ctx = new InitialContext();
    // running persist on all "routed" databases
    final List<String> databases = new ArrayList<String>();
    databases.add("database1");
    databases.add("database2");
    databases.add("database3");
    // convinient bean to create tables for each persistence unit
    final Utility utility = (Utility) ctx.lookup("UtilityBeanLocal");
    utility.initDatabase();
    final RoutedEJB ejb = (RoutedEJB) ctx.lookup("RoutedEJBBeanLocal");
    for (int i = 0; i < 18; i++) {
        final String name = "record " + i;
        final String db = databases.get(i % 3);
        ejb.persist(i, name, db);
    }
    // assert database records number using jdbc
    for (int i = 1; i <= 3; i++) {
        final Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:db" + i, "sa", "");
        final Statement st = connection.createStatement();
        final ResultSet rs = st.executeQuery("select count(*) from \"DynamicDataSourceTest$Person\"");
        rs.next();
        assertEquals(6, rs.getInt(1));
        st.close();
        connection.close();
    }
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) ArrayList(java.util.ArrayList) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) Properties(java.util.Properties) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) ResultSet(java.sql.ResultSet) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) PersistenceContext(javax.persistence.PersistenceContext) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) Statement(java.sql.Statement) Resource(org.apache.openejb.config.sys.Resource) Connection(java.sql.Connection) PersistenceModule(org.apache.openejb.config.PersistenceModule) InitialContext(javax.naming.InitialContext) Persistence(org.apache.openejb.jee.jpa.unit.Persistence) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) Test(org.junit.Test)

Example 19 with StatelessSessionContainerInfo

use of org.apache.openejb.assembler.classic.StatelessSessionContainerInfo in project tomee by apache.

the class TimerContainerTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "10");
    statelessContainerInfo.properties.setProperty("MaxSize", "0");
    statelessContainerInfo.properties.setProperty("StrictPooling", "false");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final StatelessBean bean = new StatelessBean(WidgetBean.class);
    bean.addBusinessLocal(Widget.class.getName());
    bean.addBusinessRemote(RemoteWidget.class.getName());
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);
    assembler.createApplication(config.configureApplication(ejbJar));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 20 with StatelessSessionContainerInfo

use of org.apache.openejb.assembler.classic.StatelessSessionContainerInfo in project tomee by apache.

the class ConfigureServiceTest method testConfigureServiceAddedPropertyViaURI.

public void testConfigureServiceAddedPropertyViaURI() throws Exception {
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URI uri = new URI("new://Container?type=STATELESS&provider=org.acme%23CheddarContainer");
    final Container container = (Container) factory.toConfigDeclaration("MyContainer", uri);
    container.getProperties().setProperty("anotherProperty", "Cheese is good");
    final StatelessSessionContainerInfo myStatelessContainer = factory.configureService(container, StatelessSessionContainerInfo.class);
    assertNotNull(myStatelessContainer);
    assertEquals("MyContainer", myStatelessContainer.id);
    assertEquals("org.acme.SuperContainer", myStatelessContainer.className);
    assertNotNull(myStatelessContainer.constructorArgs);
    assertNotNull(myStatelessContainer.properties);
    assertNotNull(myStatelessContainer.properties.getProperty("myProperty"));
    assertEquals("Yummy Cheese", myStatelessContainer.properties.getProperty("myProperty"));
    assertNotNull(myStatelessContainer.properties.getProperty("anotherProperty"));
    assertEquals("Cheese is good", myStatelessContainer.properties.getProperty("anotherProperty"));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Container(org.apache.openejb.config.sys.Container) URI(java.net.URI)

Aggregations

StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)23 Assembler (org.apache.openejb.assembler.classic.Assembler)16 EjbJar (org.apache.openejb.jee.EjbJar)16 StatelessBean (org.apache.openejb.jee.StatelessBean)16 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)13 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)13 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)12 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)10 InitialContext (javax.naming.InitialContext)9 Container (org.apache.openejb.config.sys.Container)7 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)6 Properties (java.util.Properties)4 Context (javax.naming.Context)4 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)4 ObjectName (javax.management.ObjectName)3 ServerFederation (org.apache.openejb.core.ServerFederation)3 EnvEntry (org.apache.openejb.jee.EnvEntry)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)2