Search in sources :

Example 16 with SingletonBean

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

the class LoggingJAXRSCommons method getEjbModule.

protected EjbModule getEjbModule(String pojoDeploymentClassName, String ejbModuleId) throws Exception {
    final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
    if (ejbModuleId != null) {
        module.setModuleId(ejbModuleId);
    }
    final EnterpriseBean bean = new SingletonBean(LogginTestBean.class).localBean();
    module.getEjbJar().addEnterpriseBean(bean);
    final Resources resources = new Resources();
    final Service feature = new Service("xml", null);
    feature.setClassName(JAXBElementProvider.class.getName());
    feature.getProperties().put("eventHandler", "$handler");
    resources.getService().add(feature);
    module.initResources(resources);
    if (pojoDeploymentClassName != null) {
        final PojoDeployment e = new PojoDeployment();
        e.setClassName(pojoDeploymentClassName);
        e.getProperties().setProperty("cxf.jaxrs.providers", "xml");
        module.getOpenejbJar().getPojoDeployment().add(e);
    }
    return module;
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) RESTService(org.apache.openejb.server.rest.RESTService) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) Resources(org.apache.openejb.config.sys.Resources) EjbJar(org.apache.openejb.jee.EjbJar)

Example 17 with SingletonBean

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

the class AdvancedProviderConfigTest method service.

@Module
public static EjbModule service() throws Exception {
    final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
    final EnterpriseBean bean = new SingletonBean(AdvancedBean.class).localBean();
    module.getEjbJar().addEnterpriseBean(bean);
    final Resources resources = new Resources();
    final Service feature = new Service("xml", null);
    feature.setClassName(JAXBElementProvider.class.getName());
    feature.getProperties().put("eventHandler", "$handler");
    resources.getService().add(feature);
    final Service handler = new Service("handler", null);
    handler.setClassName(MyValidator.class.getName());
    resources.getService().add(handler);
    module.initResources(resources);
    final PojoDeployment e = new PojoDeployment();
    e.setClassName("jaxrs-application");
    e.getProperties().setProperty("cxf.jaxrs.providers", "xml");
    module.getOpenejbJar().getPojoDeployment().add(e);
    return module;
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) 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) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module)

Example 18 with SingletonBean

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

the class SystemApps method getSystemModule.

public static EjbModule getSystemModule() {
    final EjbModule module = new EjbModule(new EjbJar("openejb"), new OpenejbJar());
    final OpenejbJar openejbJar = module.getOpenejbJar();
    final EjbJar ejbJar = module.getEjbJar();
    //
    //
    // DONT MODIFY IT WITHOUT VALIDATING org.apache.openejb.config.SystemAppInfo.preComputedInfo()
    //
    //
    ejbJar.addEnterpriseBean(singleton(DeployerEjb.class));
    ejbJar.addEnterpriseBean(singleton(ConfigurationInfoEjb.class));
    ejbJar.addEnterpriseBean(singleton(MEJBBean.class));
    ejbJar.addInterceptor(new Interceptor(InternalSecurityInterceptor.class));
    ejbJar.getAssemblyDescriptor().addInterceptorBinding(new InterceptorBinding("*", InternalSecurityInterceptor.class.getName()));
    module.getMbeans().add(JMXDeployer.class.getName());
    final SingletonBean bean = ejbJar.addEnterpriseBean(new SingletonBean("openejb/WebappDeployer", "org.apache.tomee.catalina.deployer.WebappDeployer"));
    final EjbDeployment deployment = openejbJar.addEjbDeployment(bean);
    deployment.getProperties().put("openejb.jndiname.format", "{deploymentId}{interfaceType.annotationName}");
    final SingletonBean exceptionManager = ejbJar.addEnterpriseBean(new SingletonBean("openejb/ExceptionManagerFacade", "org.apache.tomee.catalina.facade.ExceptionManagerFacadeBean"));
    final EjbDeployment exceptionMgr = openejbJar.addEjbDeployment(exceptionManager);
    exceptionMgr.getProperties().put("openejb.jndiname.format", "{deploymentId}{interfaceType.annotationName}");
    openejbJar.getProperties().put("openejb.deploymentId.format", "{ejbName}");
    openejbJar.getProperties().put("openejb.jndiname.format", "{deploymentId}{interfaceType.openejbLegacyName}");
    return module;
}
Also used : MEJBBean(org.apache.openejb.mgmt.MEJBBean) InternalSecurityInterceptor(org.apache.openejb.security.internal.InternalSecurityInterceptor) InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) DeployerEjb(org.apache.openejb.assembler.DeployerEjb) JMXDeployer(org.apache.openejb.assembler.monitoring.JMXDeployer) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ConfigurationInfoEjb(org.apache.openejb.assembler.classic.cmd.ConfigurationInfoEjb) Interceptor(org.apache.openejb.jee.Interceptor) InternalSecurityInterceptor(org.apache.openejb.security.internal.InternalSecurityInterceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 19 with SingletonBean

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

the class OpenEJBXmlByModuleTest method setUp.

@Before
public void setUp() throws OpenEJBException, NamingException, IOException {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final AppModule app = new AppModule(OpenEJBXmlByModuleTest.class.getClassLoader(), OpenEJBXmlByModuleTest.class.getSimpleName());
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(UselessBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    app.getEjbModules().iterator().next().getAltDDs().put("resources.xml", getClass().getClassLoader().getResource("META-INF/resource/appresource.openejb.xml"));
    assembler.createApplication(config.configureApplication(app));
    final Properties properties = new Properties();
    properties.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    properties.setProperty("openejb.embedded.initialcontext.close", "destroy");
    // some hack to be sure to call destroy()
    context = new InitialContext(properties);
    bean = (UselessBean) context.lookup("UselessBeanLocalBean");
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) SingletonBean(org.apache.openejb.jee.SingletonBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Example 20 with SingletonBean

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

the class AccessTimeoutTest method test.

public void test() throws Exception {
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    //TODO alternative to hack in CidBuilder to initialize if missing
    //        SystemInstance.get().setComponent(ThreadSingletonService.class, new ThreadSingletonServiceImpl(getClass().getClassLoader()));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(Color.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Red.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Crimson.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Scarlet.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    loadAttributes(ejbJarInfo, "Color");
    assertAttribute(2, TimeUnit.SECONDS, Color.class.getMethod("color"));
    assertAttribute(3, TimeUnit.SECONDS, Color.class.getMethod("color", Object.class));
    assertAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", String.class));
    assertAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", Boolean.class));
    assertAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", Integer.class));
    loadAttributes(ejbJarInfo, "Red");
    assertAttribute(2, TimeUnit.SECONDS, Red.class.getMethod("color"));
    assertNullAttribute(Red.class.getMethod("color", Object.class));
    assertAttribute(1, TimeUnit.SECONDS, Red.class.getMethod("color", String.class));
    assertAttribute(1, TimeUnit.SECONDS, Red.class.getMethod("color", Boolean.class));
    assertAttribute(1, TimeUnit.SECONDS, Red.class.getMethod("color", Integer.class));
    assertAttribute(1, TimeUnit.MINUTES, Red.class.getMethod("red"));
    assertNullAttribute(Red.class.getMethod("red", Object.class));
    assertNullAttribute(Red.class.getMethod("red", String.class));
    loadAttributes(ejbJarInfo, "Crimson");
    assertAttribute(1, TimeUnit.HOURS, Crimson.class.getMethod("color"));
    assertNullAttribute(Crimson.class.getMethod("color", Object.class));
    assertAttribute(1, TimeUnit.HOURS, Crimson.class.getMethod("color", String.class));
    assertAttribute(1, TimeUnit.SECONDS, Crimson.class.getMethod("color", Boolean.class));
    assertAttribute(1, TimeUnit.SECONDS, Crimson.class.getMethod("color", Integer.class));
    assertAttribute(1, TimeUnit.MINUTES, Crimson.class.getMethod("red"));
    assertNullAttribute(Crimson.class.getMethod("red", Object.class));
    assertNullAttribute(Crimson.class.getMethod("red", String.class));
    assertAttribute(2, TimeUnit.HOURS, Crimson.class.getMethod("crimson"));
    assertAttribute(1, TimeUnit.HOURS, Crimson.class.getMethod("crimson", String.class));
    loadAttributes(ejbJarInfo, "Scarlet");
    assertAttribute(2, TimeUnit.SECONDS, Scarlet.class.getMethod("color"));
    assertNullAttribute(Scarlet.class.getMethod("color", Object.class));
    assertAttribute(1, TimeUnit.SECONDS, Scarlet.class.getMethod("color", String.class));
    assertAttribute(1, TimeUnit.SECONDS, Scarlet.class.getMethod("color", Boolean.class));
    assertAttribute(1, TimeUnit.SECONDS, Scarlet.class.getMethod("color", Integer.class));
    assertAttribute(1, TimeUnit.MINUTES, Scarlet.class.getMethod("red"));
    assertNullAttribute(Scarlet.class.getMethod("red", Object.class));
    assertNullAttribute(Scarlet.class.getMethod("red", String.class));
    assertAttribute(2, TimeUnit.DAYS, Scarlet.class.getMethod("scarlet"));
    assertAttribute(1, TimeUnit.DAYS, Scarlet.class.getMethod("scarlet", String.class));
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

SingletonBean (org.apache.openejb.jee.SingletonBean)49 EjbJar (org.apache.openejb.jee.EjbJar)42 EjbModule (org.apache.openejb.config.EjbModule)21 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)17 Module (org.apache.openejb.testing.Module)16 Assembler (org.apache.openejb.assembler.classic.Assembler)14 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)12 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)12 AppModule (org.apache.openejb.config.AppModule)11 Properties (java.util.Properties)10 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)10 InitialContext (javax.naming.InitialContext)8 StatelessBean (org.apache.openejb.jee.StatelessBean)8 SingletonSessionContainerInfo (org.apache.openejb.assembler.classic.SingletonSessionContainerInfo)7 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)7 AppInfo (org.apache.openejb.assembler.classic.AppInfo)6 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)6 Empty (org.apache.openejb.jee.Empty)6 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)5 Test (org.junit.Test)5