Search in sources :

Example 51 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class CheckAnnotationTest method testWebServiceWithStateful.

@Keys({ @Key(value = "annotation.invalid.stateful.webservice", type = KeyType.WARNING) })
public AppModule testWebServiceWithStateful() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean(Green.class));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Green.class)).link());
    final AppModule appModule = new AppModule(ejbModule);
    return appModule;
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) Green(org.apache.openejb.test.annotated.Green) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) EjbJar(org.apache.openejb.jee.EjbJar)

Example 52 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class StatelessInterceptorTest method buildTestApp.

public static EjbModule buildTestApp() throws Exception {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.setId(StatelessInterceptorTest.class.getName());
    final AssemblyDescriptor ad = ejbJar.getAssemblyDescriptor();
    ejbJar.addEnterpriseBean(new StatelessBean(Target2Bean.class));
    final EnterpriseBean bean = ejbJar.addEnterpriseBean(new StatelessBean(TargetBean.class));
    Interceptor interceptor;
    interceptor = ejbJar.addInterceptor(new Interceptor(DefaultInterceptor.class));
    ad.addInterceptorBinding(new InterceptorBinding("*", interceptor));
    {
        interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptorViaDD.class));
        final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
        binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo", List.class)));
    }
    {
        interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptorViaDD.class));
        final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
        binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo", int.class)));
    }
    {
        interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptorViaDD.class));
        final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
        binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo", boolean.class)));
    }
    final EnterpriseBean bean3 = ejbJar.addEnterpriseBean(new StatelessBean(Target3Bean.class));
    final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean3));
    binding.setExcludeDefaultInterceptors(true);
    binding.setExcludeClassInterceptors(true);
    return new EjbModule(ejbJar);
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbModule(org.apache.openejb.config.EjbModule) NamedMethod(org.apache.openejb.jee.NamedMethod) InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) ArrayList(java.util.ArrayList) List(java.util.List) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 53 with EjbModule

use of org.apache.openejb.config.EjbModule 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 54 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class CustomContextTest method service.

@Module
public static EjbModule service() throws Exception {
    final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
    final SingletonBean bean = new SingletonBean(CustomContextInjectedBean.class);
    bean.setLocalBean(new Empty());
    module.getEjbJar().addEnterpriseBean(bean);
    final PojoDeployment e = new PojoDeployment();
    e.setClassName("jaxrs-application");
    e.getProperties().setProperty("cxf.jaxrs.providers", CustomProvider.class.getName());
    module.getOpenejbJar().getPojoDeployment().add(e);
    return module;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) Empty(org.apache.openejb.jee.Empty) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbModule(org.apache.openejb.config.EjbModule) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module)

Example 55 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class CheckedExceptionMapperTest method module.

@Module
@Classes({ ExampleExceptionMapper.class })
public EjbModule module() {
    final SingletonBean bean = new SingletonBean(ExampleRest.class);
    bean.setRestService(true);
    final EjbJar ejbJar = new EjbJar("beans");
    ejbJar.addEnterpriseBean(bean);
    final OpenejbJar openejbJar = new OpenejbJar();
    openejbJar.addEjbDeployment(new EjbDeployment(bean));
    final Properties properties = openejbJar.getEjbDeployment().iterator().next().getProperties();
    properties.setProperty("cxf.jaxrs.providers", "org.apache.openejb.server.cxf.rs.CheckedExceptionMapperTest$ExampleExceptionMapper");
    final EjbModule module = new EjbModule(ejbJar);
    module.setOpenejbJar(openejbJar);
    return module;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbModule(org.apache.openejb.config.EjbModule) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module) Classes(org.apache.openejb.testing.Classes)

Aggregations

EjbModule (org.apache.openejb.config.EjbModule)88 EjbJar (org.apache.openejb.jee.EjbJar)78 AppModule (org.apache.openejb.config.AppModule)40 StatelessBean (org.apache.openejb.jee.StatelessBean)37 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)29 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)29 Assembler (org.apache.openejb.assembler.classic.Assembler)26 Properties (java.util.Properties)23 SingletonBean (org.apache.openejb.jee.SingletonBean)21 InitialContext (javax.naming.InitialContext)19 Module (org.apache.openejb.testing.Module)16 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)15 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)12 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)12 Beans (org.apache.openejb.jee.Beans)12 AppInfo (org.apache.openejb.assembler.classic.AppInfo)10 ContainerSystem (org.apache.openejb.spi.ContainerSystem)10 ArrayList (java.util.ArrayList)9 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)9 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)9