Search in sources :

Example 76 with EjbModule

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

the class PropertiesPropogationTest method test.

public void test() throws Exception {
    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("color", "orange");
    deployment.getProperties().put("openejb.client.color", "red");
    EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
    EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    assertTrue(beanInfo.properties.containsKey("color"));
    assertTrue(beanInfo.properties.containsKey("openejb.client.color"));
    assertEquals("orange", beanInfo.properties.get("color"));
    assertEquals("red", beanInfo.properties.get("openejb.client.color"));
    assembler.createApplication(ejbJarInfo);
    ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
    BeanContext info = cs.getBeanContext("WidgetBean");
    assertNotNull(info);
    assertTrue(info.getProperties().containsKey("color"));
    assertTrue(info.getProperties().containsKey("openejb.client.color"));
    assertEquals("orange", info.getProperties().get("color"));
    assertEquals("red", info.getProperties().get("openejb.client.color"));
    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");
    InvocationHandler handler = ProxyManager.getInvocationHandler(remote);
    EJBObjectHandler objectHandler = EJBObjectHandler.class.cast(handler);
    Properties properties = objectHandler.getEjb().getProperties();
    // Should only contain "openejb.client.*" properties
    assertFalse(properties.containsKey("color"));
    // The openejb.client.color property should have been propogated
    assertTrue(properties.containsKey("openejb.client.color"));
    assertEquals("red", properties.getProperty("openejb.client.color"));
    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) EJBObjectHandler(org.apache.openejb.client.EJBObjectHandler) ServicePool(org.apache.openejb.server.ServicePool) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InvocationHandler(org.apache.openejb.client.proxy.InvocationHandler) InitialContext(javax.naming.InitialContext) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) 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) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 77 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)

Example 78 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 79 with EjbModule

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

the class FeatureTest method app.

@Module
public EjbModule app() {
    final StatelessBean bean = (StatelessBean) new StatelessBean(MySecondRestClass.class).localBean();
    bean.setRestService(true);
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);
    final OpenejbJar openejbJar = new OpenejbJar();
    final PojoDeployment e = new PojoDeployment();
    openejbJar.getPojoDeployment().add(e);
    e.setClassName("jaxrs-application");
    final Properties properties = e.getProperties();
    properties.setProperty(CxfRsHttpListener.CXF_JAXRS_PREFIX + CxfUtil.FEATURES, "my-feature");
    final EjbModule module = new EjbModule(ejbJar);
    module.setOpenejbJar(openejbJar);
    final Resources resources = new Resources();
    final Service feature = new Service("my-feature", null);
    feature.setClassName(MyFeature.class.getName());
    resources.getService().add(feature);
    module.initResources(resources);
    return module;
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) Resources(org.apache.openejb.config.sys.Resources) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module)

Example 80 with EjbModule

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

Aggregations

EjbModule (org.apache.openejb.config.EjbModule)91 EjbJar (org.apache.openejb.jee.EjbJar)81 AppModule (org.apache.openejb.config.AppModule)41 StatelessBean (org.apache.openejb.jee.StatelessBean)37 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)30 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)29 Assembler (org.apache.openejb.assembler.classic.Assembler)27 Properties (java.util.Properties)24 SingletonBean (org.apache.openejb.jee.SingletonBean)21 InitialContext (javax.naming.InitialContext)20 Module (org.apache.openejb.testing.Module)18 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)15 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)13 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)13 Beans (org.apache.openejb.jee.Beans)12 AppInfo (org.apache.openejb.assembler.classic.AppInfo)11 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)10 ContainerSystem (org.apache.openejb.spi.ContainerSystem)10 ArrayList (java.util.ArrayList)9 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)9