Search in sources :

Example 16 with Container

use of org.apache.openejb.config.sys.Container in project tomee by apache.

the class ConfigurationFactory method getOpenEjbConfiguration.

public OpenEjbConfiguration getOpenEjbConfiguration(final Openejb providedConf) throws OpenEJBException {
    if (sys != null) {
        return sys;
    }
    if (providedConf != null) {
        openejb = providedConf;
    } else if (configLocation != null) {
        openejb = JaxbOpenejb.readConfig(configLocation);
    } else {
        openejb = JaxbOpenejb.createOpenejb();
    }
    for (final SystemProperty sp : openejb.getSystemProperties()) {
        final String name = sp.getName();
        final String value = sp.getValue();
        SystemInstance.get().setProperty(name, value);
        JavaSecurityManagers.setSystemProperty(name, value);
    }
    loadPropertiesDeclaredConfiguration(openejb);
    sys = new OpenEjbConfiguration();
    sys.containerSystem = new ContainerSystemInfo();
    sys.facilities = new FacilitiesInfo();
    // listener + some config can be defined as service
    for (final Service service : openejb.getServices()) {
        final ServiceInfo info = configureService(service, ServiceInfo.class);
        sys.facilities.services.add(info);
    }
    for (final JndiProvider provider : openejb.getJndiProvider()) {
        final JndiContextInfo info = configureService(provider, JndiContextInfo.class);
        sys.facilities.remoteJndiContexts.add(info);
    }
    sys.facilities.securityService = configureService(openejb.getSecurityService(), SecurityServiceInfo.class);
    sys.facilities.transactionService = configureService(openejb.getTransactionManager(), TransactionServiceInfo.class);
    List<ResourceInfo> resources = new ArrayList<>();
    for (final Resource resource : openejb.getResource()) {
        final ResourceInfo resourceInfo = configureService(resource, ResourceInfo.class);
        resources.add(resourceInfo);
    }
    resources = sort(resources, null);
    sys.facilities.resources.addAll(resources);
    if (openejb.getProxyFactory() != null) {
        sys.facilities.intraVmServer = configureService(openejb.getProxyFactory(), ProxyFactoryInfo.class);
    }
    for (final Container declaration : openejb.getContainer()) {
        final ContainerInfo info = createContainerInfo(declaration);
        sys.containerSystem.containers.add(info);
    }
    final List<File> declaredApps = getDeclaredApps();
    for (final File jarFile : declaredApps) {
        try {
            final AppInfo appInfo = configureApplication(jarFile);
            sys.containerSystem.applications.add(appInfo);
        } catch (final OpenEJBException alreadyHandled) {
            final DeploymentExceptionManager exceptionManager = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
            if (exceptionManager != null) {
                exceptionManager.pushDelpoymentException(alreadyHandled);
            }
        }
    }
    final boolean embedded = SystemInstance.get().hasProperty(EJBContainer.class.getName());
    final Options options = SystemInstance.get().getOptions();
    if (options.get("openejb.system.apps", false)) {
        try {
            final boolean extended = SystemApps.isExtended();
            final AppInfo appInfo;
            if (!extended) {
                // do it manually, we know what we need and can skip a bunch of processing
                appInfo = SystemAppInfo.preComputedInfo(this);
            } else {
                appInfo = configureApplication(new AppModule(SystemApps.getSystemModule()));
            }
            // they doesn't use CDI so no need to activate it
            // 1) will be faster
            // 2) will let embedded containers (tomee-embedded mainly) not be noised by it in our singleton service
            appInfo.properties.put("openejb.cdi.activated", "false");
            sys.containerSystem.applications.add(appInfo);
        } catch (final OpenEJBException e) {
            logger.error("Unable to load the system applications.", e);
        }
    } else if (options.get(DEPLOYMENTS_CLASSPATH_PROPERTY, !embedded)) {
        final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        final ArrayList<File> jarFiles = getModulesFromClassPath(declaredApps, classLoader);
        final String appId = "classpath.ear";
        final boolean classpathAsEar = options.get(CLASSPATH_AS_EAR, true);
        try {
            if (classpathAsEar && !jarFiles.isEmpty()) {
                final AppInfo appInfo = configureApplication(classLoader, appId, jarFiles);
                sys.containerSystem.applications.add(appInfo);
            } else {
                for (final File jarFile : jarFiles) {
                    final AppInfo appInfo = configureApplication(jarFile);
                    sys.containerSystem.applications.add(appInfo);
                }
            }
            if (jarFiles.size() == 0) {
                logger.warning("config.noModulesFoundToDeploy");
            }
        } catch (final OpenEJBException alreadyHandled) {
            logger.debug("config.alreadyHandled");
        }
    }
    for (final Deployments deployments : openejb.getDeployments()) {
        if (deployments.isAutoDeploy()) {
            if (deployments.getDir() != null) {
                sys.containerSystem.autoDeploy.add(deployments.getDir());
            }
        }
    }
    final OpenEjbConfiguration finished = sys;
    sys = null;
    openejb = null;
    return finished;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) Options(org.apache.openejb.loader.Options) ArrayList(java.util.ArrayList) AdditionalDeployments(org.apache.openejb.config.sys.AdditionalDeployments) Deployments(org.apache.openejb.config.sys.Deployments) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) ServiceInfo(org.apache.openejb.assembler.classic.ServiceInfo) EJBContainer(javax.ejb.embeddable.EJBContainer) Container(org.apache.openejb.config.sys.Container) JndiContextInfo(org.apache.openejb.assembler.classic.JndiContextInfo) EJBContainer(javax.ejb.embeddable.EJBContainer) ContainerSystemInfo(org.apache.openejb.assembler.classic.ContainerSystemInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) DeploymentExceptionManager(org.apache.openejb.assembler.classic.DeploymentExceptionManager) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) JndiProvider(org.apache.openejb.config.sys.JndiProvider) Resource(org.apache.openejb.config.sys.Resource) AbstractService(org.apache.openejb.config.sys.AbstractService) SecurityService(org.apache.openejb.config.sys.SecurityService) Service(org.apache.openejb.config.sys.Service) AppInfo(org.apache.openejb.assembler.classic.AppInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) FacilitiesInfo(org.apache.openejb.assembler.classic.FacilitiesInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ManagedContainerInfo(org.apache.openejb.assembler.classic.ManagedContainerInfo) BmpEntityContainerInfo(org.apache.openejb.assembler.classic.BmpEntityContainerInfo) StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) CmpEntityContainerInfo(org.apache.openejb.assembler.classic.CmpEntityContainerInfo) StatefulSessionContainerInfo(org.apache.openejb.assembler.classic.StatefulSessionContainerInfo) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo) File(java.io.File)

Example 17 with Container

use of org.apache.openejb.config.sys.Container in project tomee by apache.

the class ActivationConfigPropertyOverrideTest method testOverrideFromContainerDefinedInAppModule.

@Test
public void testOverrideFromContainerDefinedInAppModule() throws Exception {
    SystemInstance.reset();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Yellow", Orange.class));
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Orange", Yellow.class));
    final AppModule appModule = new AppModule(new EjbModule(ejbJar));
    appModule.setModuleId("mymodule");
    final Container container = new Container();
    container.setId("mycontainer");
    container.setCtype("MESSAGE");
    container.getProperties().setProperty("activation.DeliveryActive", "false");
    appModule.getContainers().add(container);
    final AppInfo appInfo = config.configureApplication(appModule);
    assertEquals(1, appInfo.ejbJars.size());
    final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
    assertEquals("false", orange.activationProperties.get("DeliveryActive"));
    assertEquals("false", yellow.activationProperties.get("DeliveryActive"));
}
Also used : Container(org.apache.openejb.config.sys.Container) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test) ActivationContainerOverwriteBothConfigurationTest(org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest)

Example 18 with Container

use of org.apache.openejb.config.sys.Container in project tomee by apache.

the class ApplicationWideTest method testShouldCreateAResourceAndRemoveOnUndeploy.

public void testShouldCreateAResourceAndRemoveOnUndeploy() throws Exception {
    final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    final EjbJar ejbJar = ejbModule.getEjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(EchoBean.class));
    final AppModule appModule = new AppModule(ejbModule);
    final Container container = new Container();
    container.setId("My Container");
    container.setCtype("STATELESS");
    container.getProperties().setProperty("ApplicationWide", "false");
    appModule.getContainers().add(container);
    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 AppInfo appInfo = config.configureApplication(appModule);
    assembler.createApplication(appInfo);
    {
        final ContainerSystem containerSystem = assembler.getContainerSystem();
        final org.apache.openejb.Container appContainer = containerSystem.getContainer(ejbModule.getModuleId() + "/My Container");
        assertNotNull(appContainer);
    }
    assembler.destroyApplication(appInfo);
    {
        final ContainerSystem containerSystem = assembler.getContainerSystem();
        final org.apache.openejb.Container appContainer = containerSystem.getContainer(ejbModule.getModuleId() + "/My Container");
        assertNull(appContainer);
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Container(org.apache.openejb.config.sys.Container) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 19 with Container

use of org.apache.openejb.config.sys.Container in project tomee by apache.

the class ConfigureServiceTest method testConfigureServiceAddedPropertyViaURI.

public void testConfigureServiceAddedPropertyViaURI() throws Exception {
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URI uri = new URI("new://Container?type=STATELESS&provider=org.acme%23CheddarContainer");
    final Container container = (Container) factory.toConfigDeclaration("MyContainer", uri);
    container.getProperties().setProperty("anotherProperty", "Cheese is good");
    final StatelessSessionContainerInfo myStatelessContainer = factory.configureService(container, StatelessSessionContainerInfo.class);
    assertNotNull(myStatelessContainer);
    assertEquals("MyContainer", myStatelessContainer.id);
    assertEquals("org.acme.SuperContainer", myStatelessContainer.className);
    assertNotNull(myStatelessContainer.constructorArgs);
    assertNotNull(myStatelessContainer.properties);
    assertNotNull(myStatelessContainer.properties.getProperty("myProperty"));
    assertEquals("Yummy Cheese", myStatelessContainer.properties.getProperty("myProperty"));
    assertNotNull(myStatelessContainer.properties.getProperty("anotherProperty"));
    assertEquals("Cheese is good", myStatelessContainer.properties.getProperty("anotherProperty"));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Container(org.apache.openejb.config.sys.Container) URI(java.net.URI)

Example 20 with Container

use of org.apache.openejb.config.sys.Container in project tomee by apache.

the class ConfigureServiceTest method testConfigureServiceAddedProperty.

public void testConfigureServiceAddedProperty() throws Exception {
    final ConfigurationFactory factory = new ConfigurationFactory();
    final Container container = new Container("MyContainer", "STATELESS", "org.acme#CheddarContainer");
    container.getProperties().setProperty("anotherProperty", "Cheese is good");
    final StatelessSessionContainerInfo myStatelessContainer = factory.configureService(container, StatelessSessionContainerInfo.class);
    assertNotNull(myStatelessContainer);
    assertEquals("MyContainer", myStatelessContainer.id);
    assertEquals("org.acme.SuperContainer", myStatelessContainer.className);
    assertNotNull(myStatelessContainer.constructorArgs);
    assertNotNull(myStatelessContainer.properties);
    assertNotNull(myStatelessContainer.properties.getProperty("myProperty"));
    assertEquals("Yummy Cheese", myStatelessContainer.properties.getProperty("myProperty"));
    assertNotNull(myStatelessContainer.properties.getProperty("anotherProperty"));
    assertEquals("Cheese is good", myStatelessContainer.properties.getProperty("anotherProperty"));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Container(org.apache.openejb.config.sys.Container)

Aggregations

Container (org.apache.openejb.config.sys.Container)22 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)10 ContainerInfo (org.apache.openejb.assembler.classic.ContainerInfo)7 AppInfo (org.apache.openejb.assembler.classic.AppInfo)4 MdbContainerInfo (org.apache.openejb.assembler.classic.MdbContainerInfo)4 Resource (org.apache.openejb.config.sys.Resource)4 EjbJar (org.apache.openejb.jee.EjbJar)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 File (java.io.File)2 URI (java.net.URI)2 Properties (java.util.Properties)2 EJBContainer (javax.ejb.embeddable.EJBContainer)2 MessageListener (javax.jms.MessageListener)2 Assembler (org.apache.openejb.assembler.classic.Assembler)2 BmpEntityContainerInfo (org.apache.openejb.assembler.classic.BmpEntityContainerInfo)2 CmpEntityContainerInfo (org.apache.openejb.assembler.classic.CmpEntityContainerInfo)2 ManagedContainerInfo (org.apache.openejb.assembler.classic.ManagedContainerInfo)2 OpenEjbConfiguration (org.apache.openejb.assembler.classic.OpenEjbConfiguration)2 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)2