Search in sources :

Example 61 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class DeploymentContextPropertiesTest method testAppContextProperties.

public void testAppContextProperties() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        // Setup the descriptor information
        final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final AppModule appModule = new AppModule(ejbModule);
        appModule.getProperties().setProperty("color", "orange");
        final AppInfo appInfo = config.configureApplication(appModule);
        assertProperty(appInfo.properties, "color", "orange");
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final Properties properties = beanContext.getModuleContext().getAppContext().getProperties();
    assertProperty(properties, "color", "orange");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 62 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class GreetingServiceTest method app.

@Module
public EjbModule app() {
    final SingletonBean bean = (SingletonBean) new SingletonBean(GreetingService.class).localBean();
    bean.setRestService(true);
    // now create an ejbjar and an openejb-jar to hold the provider config
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);
    final OpenejbJar openejbJar = new OpenejbJar();
    openejbJar.addEjbDeployment(new EjbDeployment(ejbJar.getEnterpriseBeans()[0]));
    final Properties properties = openejbJar.getEjbDeployment().iterator().next().getProperties();
    properties.setProperty("cxf.jaxrs.providers", IllegalArgumentExceptionMapper.class.getName());
    // link all and return this module
    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)

Example 63 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class Container method addCallersAsEjbModule.

private static void addCallersAsEjbModule(final ClassLoader loader, final AppModule app, final String... additionalCallers) {
    final Set<String> callers = new HashSet<>(NewLoaderLogic.callers(Filters.classes(Container.class.getName(), "org.apache.openejb.maven.plugins.TomEEEmbeddedMojo")));
    // we don't care of these
    callers.remove("org.apache.tomee.embedded.Container");
    callers.remove("org.apache.tomee.gradle.embedded.TomEEEmbeddedTask");
    final Iterator<String> callerIt = callers.iterator();
    while (callerIt.hasNext()) {
        // TomEEEmbeddedMojo is also used with some anonymous classes (TomEEEmbeddedMojo$x)
        if (callerIt.next().startsWith("org.apache.openejb.maven.plugins.TomEEEmbeddedMojo")) {
            callerIt.remove();
        // no break since we remove anonymous class+the mojo itself
        }
    }
    if (additionalCallers != null && additionalCallers.length > 0) {
        callers.addAll(asList(additionalCallers));
    }
    if (callers.isEmpty()) {
        return;
    }
    final EjbJar ejbJar = new EjbJar();
    final OpenejbJar openejbJar = new OpenejbJar();
    for (final String caller : callers) {
        try {
            if (!AnnotationDeployer.isInstantiable(loader.loadClass(caller))) {
                continue;
            }
        } catch (final ClassNotFoundException e) {
            continue;
        }
        final String name = caller.replace("$", "_");
        final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(caller.replace("$", "_"), caller, true));
        bean.localBean();
        bean.setTransactionType(TransactionType.BEAN);
        final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
        ejbDeployment.setDeploymentId(name);
    }
    final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
    ejbModule.setBeans(new Beans());
    app.getEjbModules().add(ejbModule);
}
Also used : Beans(org.apache.openejb.jee.Beans) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbModule(org.apache.openejb.config.EjbModule) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ManagedBean(org.apache.openejb.jee.ManagedBean) HashSet(java.util.HashSet) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)62 EjbJar (org.apache.openejb.jee.EjbJar)50 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)36 EjbModule (org.apache.openejb.config.EjbModule)29 Properties (java.util.Properties)20 StatelessBean (org.apache.openejb.jee.StatelessBean)18 Assembler (org.apache.openejb.assembler.classic.Assembler)17 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)15 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)12 ContainerSystem (org.apache.openejb.spi.ContainerSystem)12 SingletonBean (org.apache.openejb.jee.SingletonBean)10 Module (org.apache.openejb.testing.Module)9 AppModule (org.apache.openejb.config.AppModule)8 InitialContext (javax.naming.InitialContext)7 OpenEJBException (org.apache.openejb.OpenEJBException)7 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)7 PojoDeployment (org.apache.openejb.jee.oejb3.PojoDeployment)7 File (java.io.File)6 HashMap (java.util.HashMap)6 Resources (org.apache.openejb.config.sys.Resources)6