Search in sources :

Example 56 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.

the class DeploymentContextOptionsTest method testAllLevels.

public void testAllLevels() throws Exception {
    SystemInstance.get().setProperty("color", "orangeSystem");
    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();
        final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        {
            // Set at BeanContext level
            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
            final EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
            deployment.getProperties().put("color", "orangeBean");
        }
        {
            // Set at ModuleContext level
            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
            openejbJar.getProperties().put("color", "orangeModule");
        }
        final AppModule appModule = new AppModule(ejbModule);
        {
            // Set at AppContext level
            appModule.getProperties().put("color", "orangeApp");
        }
        assembler.createApplication(config.configureApplication(appModule));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    assertOption(beanContext.getOptions(), "color", "orangeBean");
    assertOption(beanContext.getModuleContext().getOptions(), "color", "orangeModule");
    assertOption(beanContext.getModuleContext().getAppContext().getOptions(), "color", "orangeApp");
    assertOption(SystemInstance.get().getOptions(), "color", "orangeSystem");
}
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) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 57 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.

the class DeploymentContextOptionsTest method testSystemInstanceOptions.

public void testSystemInstanceOptions() throws Exception {
    SystemInstance.get().setProperty("color", "orange");
    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);
        assembler.createApplication(config.configureApplication(appModule));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    assertOption(beanContext.getOptions(), "color", "orange");
    assertOption(beanContext.getModuleContext().getOptions(), "color", "orange");
    assertOption(beanContext.getModuleContext().getAppContext().getOptions(), "color", "orange");
    assertOption(SystemInstance.get().getOptions(), "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) EjbJar(org.apache.openejb.jee.EjbJar)

Example 58 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem 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 59 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.

the class ApplicationComposers method stopApplication.

public void stopApplication() throws NamingException {
    if (appContext != null && appContext.getWebBeansContext() != null) {
        final ContextsService contextsService = appContext.getWebBeansContext().getContextsService();
        // No need to stop the ConversationContext manually as it gets stored inside the SessionContext as Bean
        contextsService.endContext(SessionScoped.class, session);
        contextsService.endContext(RequestScoped.class, null);
    }
    if (appInfo != null) {
        try {
            assembler.destroyApplication(appInfo.path);
        } catch (final Exception e) {
        // no-op
        }
    }
    final ContainerSystem component = SystemInstance.get().getComponent(ContainerSystem.class);
    if (null != component) {
        final Context context = component.getJNDIContext();
        for (final String entry : globalJndiEntries) {
            context.unbind(entry);
        }
    }
    globalJndiEntries.clear();
    if (mockCdiContexts() && appContext != null && appContext.getWebBeansContext() != null) {
        try {
            ScopeHelper.stopContexts(appContext.getWebBeansContext().getContextsService(), servletContext, session);
        } catch (final Exception e) {
        // no-op
        }
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) WebContext(org.apache.openejb.core.WebContext) InitialContext(javax.naming.InitialContext) MockServletContext(org.apache.webbeans.web.lifecycle.test.MockServletContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) ThreadContext(org.apache.openejb.core.ThreadContext) AppContext(org.apache.openejb.AppContext) ContextsService(org.apache.webbeans.spi.ContextsService) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 60 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.

the class BeanPropertiesTest method testOverrideFromFullDottedPath.

public void testOverrideFromFullDottedPath() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"Foo\"/>");
        map.put("META-INF/openejb-jar.xml", "<openejb-jar>\n" + "  <ejb-deployment ejb-name=\"WidgetBean\">\n" + "    <properties>\n" + "      color=white\n" + "    </properties>\n" + "  </ejb-deployment>\n" + "</openejb-jar>");
        final File app = Archives.fileArchive(map, WidgetBean.class);
        // Foo is both the app-name and module-name
        SystemInstance.get().setProperty("Foo.Foo.WidgetBean.color", "orange");
        assembler.createApplication(config.configureApplication(app));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    assertContexts(containerSystem);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Assembler(org.apache.openejb.assembler.classic.Assembler) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Aggregations

ContainerSystem (org.apache.openejb.spi.ContainerSystem)67 Assembler (org.apache.openejb.assembler.classic.Assembler)33 BeanContext (org.apache.openejb.BeanContext)22 HashMap (java.util.HashMap)21 Map (java.util.Map)19 File (java.io.File)17 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)13 EjbJar (org.apache.openejb.jee.EjbJar)13 StatelessBean (org.apache.openejb.jee.StatelessBean)13 Context (javax.naming.Context)12 AppInfo (org.apache.openejb.assembler.classic.AppInfo)12 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)11 AppContext (org.apache.openejb.AppContext)10 ArrayList (java.util.ArrayList)9 Properties (java.util.Properties)9 EjbModule (org.apache.openejb.config.EjbModule)9 NamingException (javax.naming.NamingException)8 WebContext (org.apache.openejb.core.WebContext)8 InitialContext (javax.naming.InitialContext)7 NameNotFoundException (javax.naming.NameNotFoundException)6