Search in sources :

Example 16 with ContainerSystem

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

the class ModulePropertiesTest 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));
    }
    {
        SystemInstance.get().getProperties().put("fooApp.fooModule.color", "orange");
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        map.put("META-INF/module.properties", "color=white");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    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) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 17 with ContainerSystem

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

the class ModulePropertiesTest method testOverrideFromApplicationProperties.

public void testOverrideFromApplicationProperties() 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=\"fooModule\"/>");
        map.put("META-INF/module.properties", "color=white");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        appModule.getProperties().put("fooModule.color", "orange");
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    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) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 18 with ContainerSystem

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

the class ModulePropertiesTest method testOverrideReplace.

public void testOverrideReplace() 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));
    }
    {
        SystemInstance.get().getProperties().put("fooModule.color", "orange");
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        map.put("META-INF/module.properties", "color=white");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    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) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 19 with ContainerSystem

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

the class LazyEjbReference method getObject.

public Object getObject() throws NamingException {
    if (reference != null) {
        return reference.getObject();
    }
    final SystemInstance systemInstance = SystemInstance.get();
    final EjbResolver resolver = systemInstance.getComponent(EjbResolver.class);
    final String deploymentId = resolver.resolve(info, moduleUri);
    if (deploymentId == null) {
        String key = "lazyEjbRefNotResolved";
        if (info.getHome() != null) {
            key += ".home";
        }
        final String message = messages.format(key, info.getName(), info.getEjbLink(), info.getHome(), info.getInterface());
        throw new NameNotFoundException(message);
    }
    final ContainerSystem containerSystem = systemInstance.getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext(deploymentId);
    if (beanContext == null) {
        final String message = messages.format("deploymentNotFound", info.getName(), deploymentId);
        throw new NameNotFoundException(message);
    }
    InterfaceType type = null;
    switch(info.getRefType()) {
        case LOCAL:
            type = InterfaceType.BUSINESS_LOCAL;
            break;
        case REMOTE:
            type = InterfaceType.BUSINESS_REMOTE;
            break;
    }
    final String jndiName = "openejb/Deployment/" + JndiBuilder.format(deploymentId, info.getInterface(), type);
    if (useCrossClassLoaderRef && isRemote(beanContext)) {
        reference = new CrossClassLoaderJndiReference(jndiName);
    } else {
        reference = new IntraVmJndiReference(jndiName);
    }
    return reference.getObject();
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) IntraVmJndiReference(org.apache.openejb.core.ivm.naming.IntraVmJndiReference) InterfaceType(org.apache.openejb.InterfaceType) NameNotFoundException(javax.naming.NameNotFoundException) SystemInstance(org.apache.openejb.loader.SystemInstance) CrossClassLoaderJndiReference(org.apache.openejb.core.ivm.naming.CrossClassLoaderJndiReference)

Example 20 with ContainerSystem

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

the class Assembler method buildContainerSystem.

/////////////////////////////////////////////////////////////////////
////
////    Public Methods Used for Assembly
////
/////////////////////////////////////////////////////////////////////
/**
     * When given a complete OpenEjbConfiguration graph this method
     * will construct an entire container system and return a reference to that
     * container system, as ContainerSystem instance.
     * <p/>
     * This method leverage the other assemble and apply methods which
     * can be used independently.
     * <p/>
     * Assembles and returns the {@link CoreContainerSystem} using the
     * information from the {@link OpenEjbConfiguration} object passed in.
     * <pre>
     * This method performs the following actions(in order):
     *
     * 1  Assembles ProxyFactory
     * 2  Assembles External JNDI Contexts
     * 3  Assembles TransactionService
     * 4  Assembles SecurityService
     * 5  Assembles ConnectionManagers
     * 6  Assembles Connectors
     * 7  Assembles Containers
     * 8  Assembles Applications
     * </pre>
     *
     * @param configInfo OpenEjbConfiguration
     * @throws Exception if there was a problem constructing the ContainerSystem.
     * @see OpenEjbConfiguration
     */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void buildContainerSystem(final OpenEjbConfiguration configInfo) throws Exception {
    final SystemInstance systemInstance = SystemInstance.get();
    if (systemInstance.getOptions().get(OPENEJB_JPA_DEPLOY_TIME_ENHANCEMENT_PROP, false)) {
        systemInstance.addObserver(new DeployTimeEnhancer());
    }
    if (hasBatchEE()) {
        systemInstance.addObserver(new BatchEEServiceManager());
    }
    for (final ServiceInfo serviceInfo : configInfo.facilities.services) {
        createService(serviceInfo);
    }
    final ContainerSystemInfo containerSystemInfo = configInfo.containerSystem;
    if (configInfo.facilities.intraVmServer != null) {
        createProxyFactory(configInfo.facilities.intraVmServer);
    }
    for (final JndiContextInfo contextInfo : configInfo.facilities.remoteJndiContexts) {
        createExternalContext(contextInfo);
    }
    createTransactionManager(configInfo.facilities.transactionService);
    createSecurityService(configInfo.facilities.securityService);
    final Set<String> reservedResourceIds = new HashSet<>(configInfo.facilities.resources.size());
    for (final AppInfo appInfo : containerSystemInfo.applications) {
        reservedResourceIds.addAll(appInfo.resourceIds);
    }
    final Set<String> rIds = new HashSet<>(configInfo.facilities.resources.size());
    for (final ResourceInfo resourceInfo : configInfo.facilities.resources) {
        createResource(configInfo.facilities.services, resourceInfo);
        rIds.add(resourceInfo.id);
    }
    rIds.removeAll(reservedResourceIds);
    final ContainerSystem component = systemInstance.getComponent(ContainerSystem.class);
    if (component != null) {
        postConstructResources(rIds, ParentClassLoaderFinder.Helper.get(), component.getJNDIContext(), null);
    } else {
        throw new RuntimeException("ContainerSystem has not been initialzed");
    }
    // Containers
    for (final ContainerInfo serviceInfo : containerSystemInfo.containers) {
        createContainer(serviceInfo);
    }
    // before any deployment bind global to be able to share the same context
    createJavaGlobal();
    for (final AppInfo appInfo : containerSystemInfo.applications) {
        try {
            createApplication(appInfo, createAppClassLoader(appInfo));
        } catch (final DuplicateDeploymentIdException e) {
        // already logged.
        } catch (final Throwable e) {
            logger.error("appNotDeployed", e, appInfo.path);
            final DeploymentExceptionManager exceptionManager = systemInstance.getComponent(DeploymentExceptionManager.class);
            if (exceptionManager != null && e instanceof Exception) {
                exceptionManager.saveDeploymentException(appInfo, (Exception) e);
            }
        }
    }
    systemInstance.fireEvent(new ContainerSystemPostCreate());
}
Also used : CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) ContainerSystem(org.apache.openejb.spi.ContainerSystem) InvalidObjectException(java.io.InvalidObjectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ObjectStreamException(java.io.ObjectStreamException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) UndeployException(org.apache.openejb.UndeployException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) ConstructionException(org.apache.xbean.recipe.ConstructionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(javax.validation.ValidationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) DeploymentException(javax.enterprise.inject.spi.DeploymentException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) SystemInstance(org.apache.openejb.loader.SystemInstance) BatchEEServiceManager(org.apache.openejb.batchee.BatchEEServiceManager) HashSet(java.util.HashSet) ContainerSystemPostCreate(org.apache.openejb.assembler.classic.event.ContainerSystemPostCreate)

Aggregations

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