Search in sources :

Example 1 with ContainerInfo

use of org.apache.openejb.assembler.classic.ContainerInfo in project tomee by apache.

the class AutoConfig method matchContainer.

private String matchContainer(final Class<? extends ContainerInfo> containerInfoType, final Object bean, final Collection<ContainerInfo> list) {
    for (final ContainerInfo containerInfo : list) {
        if (containerInfo.getClass().equals(containerInfoType)) {
            // MDBs must match message listener interface type
            if (MessageDrivenBean.class.isInstance(bean)) {
                final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
                final String messagingType = messageDrivenBean.getMessagingType();
                if (containerInfo.properties.get("MessageListenerInterface").equals(messagingType)) {
                    return containerInfo.id;
                }
            } else {
                return containerInfo.id;
            }
        }
    }
    return null;
}
Also used : MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo)

Example 2 with ContainerInfo

use of org.apache.openejb.assembler.classic.ContainerInfo in project tomee by apache.

the class AppInfoBuilder method build.

public AppInfo build(final AppModule appModule) throws OpenEJBException {
    // send an event so that it becomes pretty easy at this step to dynamically change the module description
    // before going into the info tree. Pretty easy to hack on portability issues.
    SystemInstance.get().fireEvent(new BeforeAppInfoBuilderEvent(appModule));
    final AppInfo appInfo = new AppInfo();
    appInfo.appId = appModule.getModuleId();
    appInfo.path = appModule.getJarLocation();
    appInfo.standaloneModule = appModule.isStandaloneModule() || appModule.isWebapp();
    appInfo.delegateFirst = appModule.isDelegateFirst();
    appInfo.watchedResources.addAll(appModule.getWatchedResources());
    appInfo.mbeans.addAll(appModule.getAdditionalLibMbeans());
    appInfo.jaxRsProviders.addAll(appModule.getJaxRsProviders());
    appInfo.properties.putAll(appModule.getProperties());
    if (appInfo.appId == null) {
        throw new IllegalArgumentException("AppInfo.appId cannot be null");
    }
    if (appInfo.path == null) {
        appInfo.path = appInfo.appId;
    }
    this.buildPojoConfiguration(appModule, appInfo);
    this.buildAppResources(appModule, appInfo);
    this.buildAppContainers(appModule, appInfo);
    this.buildAppServices(appModule, appInfo);
    // 
    // J2EE Connectors
    // 
    this.buildConnectorModules(appModule, appInfo);
    // 
    // Persistence Units
    // 
    this.buildPersistenceModules(appModule, appInfo);
    final List<String> containerIds = this.configFactory.getContainerIds();
    for (final ConnectorInfo connectorInfo : appInfo.connectors) {
        for (final MdbContainerInfo containerInfo : connectorInfo.inbound) {
            containerIds.add(containerInfo.id);
        }
    }
    for (final ContainerInfo containerInfo : appInfo.containers) {
        containerIds.add(containerInfo.id);
    }
    // 
    // EJB Jars
    // 
    final Map<EjbModule, EjbJarInfo> ejbJarInfos = new HashMap<>();
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        try {
            final EjbJarInfo ejbJarInfo = this.ejbJarInfoBuilder.buildInfo(ejbModule);
            ejbJarInfo.mbeans = ejbModule.getMbeans();
            final Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
            for (final EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
                final EjbDeployment d = deploymentsByEjbName.get(bean.ejbName);
                if (d.getContainerId() != null && !containerIds.contains(d.getContainerId())) {
                    for (final ContainerInfo containerInfo : appInfo.containers) {
                        if (containerInfo.id.endsWith("/" + d.getContainerId())) {
                            d.setContainerId(containerInfo.id);
                            break;
                        }
                    }
                }
                /*
                     * JRG - there's probably a better way of handling this, but this code handles the case when:
                     * 
                     * A connector with two or more inbound adapter is registered, causing two containers named with the format:
                     *     <moduleId>-<message listener interface>
                     * 
                     * This code adjusts the container id for the associated MDBs by sticking the message listener interface on the end.
                     * 
                     */
                if (bean instanceof MessageDrivenBeanInfo && !containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
                    final MessageDrivenBeanInfo mdb = (MessageDrivenBeanInfo) bean;
                    final String newContainerId = d.getContainerId() + "-" + mdb.mdbInterface;
                    if (containerIds.contains(newContainerId)) {
                        d.setContainerId(newContainerId);
                    }
                }
                if (!containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
                    final String msg = new Messages("org.apache.openejb.util.resources").format("config.noContainerFound", d.getContainerId(), d.getEjbName());
                    logger.fatal(msg);
                    throw new OpenEJBException(msg);
                }
                bean.containerId = d.getContainerId();
            }
            for (final PojoDeployment pojoDeployment : ejbModule.getOpenejbJar().getPojoDeployment()) {
                final IdPropertiesInfo info = new IdPropertiesInfo();
                info.id = pojoDeployment.getClassName();
                info.properties.putAll(pojoDeployment.getProperties());
                ejbJarInfo.pojoConfigurations.add(info);
            }
            ejbJarInfo.validationInfo = ValidatorBuilder.getInfo(ejbModule.getValidationConfig());
            ejbJarInfo.portInfos.addAll(this.configureWebservices(ejbModule.getWebservices()));
            ejbJarInfo.uniqueId = ejbModule.getUniqueId();
            ejbJarInfo.webapp = ejbModule.isWebapp();
            this.configureWebserviceSecurity(ejbJarInfo, ejbModule);
            ejbJarInfos.put(ejbModule, ejbJarInfo);
            appInfo.ejbJars.add(ejbJarInfo);
        } catch (final OpenEJBException e) {
            ConfigUtils.logger.warning("conf.0004", ejbModule.getJarLocation(), e.getMessage());
            throw e;
        }
    }
    // Create the JNDI info builder
    final JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(appInfo);
    if (appModule.getApplication() != null) {
        // TODO figure out how to prevent adding stuff to the module and comp contexts from the application
        // or maybe validate the xml so this won't happen.
        jndiEncInfoBuilder.build(appModule.getApplication(), appInfo.appId, null, appModule.getModuleUri(), new JndiEncInfo(), new JndiEncInfo());
    }
    final List<EnterpriseBeanInfo> beans = new ArrayList<>();
    // Build the JNDI tree for each ejb
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJarInfo ejbJar = ejbJarInfos.get(ejbModule);
        final Map<String, EnterpriseBean> beanData = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();
        for (final EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
            beans.add(beanInfo);
            // Get the ejb-jar.xml object
            final EnterpriseBean enterpriseBean = beanData.get(beanInfo.ejbName);
            // Build the JNDI info tree for the EJB
            jndiEncInfoBuilder.build(enterpriseBean, beanInfo.ejbName, ejbJar.moduleName, ejbModule.getModuleUri(), ejbJar.moduleJndiEnc, beanInfo.jndiEnc);
            jndiEncInfoBuilder.buildDependsOnRefs(enterpriseBean, beanInfo, ejbJar.moduleName);
        }
    }
    // Check for circular references in Singleton @DependsOn
    try {
        References.sort(beans, new References.Visitor<EnterpriseBeanInfo>() {

            @Override
            public String getName(final EnterpriseBeanInfo bean) {
                return bean.ejbDeploymentId;
            }

            @Override
            public Set<String> getReferences(final EnterpriseBeanInfo bean) {
                return new LinkedHashSet<>(bean.dependsOn);
            }
        });
    } catch (final CircularReferencesException e) {
    // List<List> circuits = e.getCircuits();
    // TODO Seems we lost circular reference detection, or we do it elsewhere and don't need it here
    }
    // 
    // Application Clients
    // 
    this.buildClientModules(appModule, appInfo, jndiEncInfoBuilder);
    // 
    // Webapps
    // 
    this.buildWebModules(appModule, jndiEncInfoBuilder, appInfo);
    // 
    // Final AppInfo creation
    // 
    final List<URL> additionalLibraries = appModule.getAdditionalLibraries();
    for (final URL url : additionalLibraries) {
        final File file = toFile(url);
        try {
            appInfo.libs.add(file.getCanonicalPath());
        } catch (final IOException e) {
            throw new OpenEJBException("Invalid application lib path " + file.getAbsolutePath());
        }
    }
    if (appModule.getCmpMappings() != null) {
        try {
            appInfo.cmpMappingsXml = JpaJaxbUtil.marshal(EntityMappings.class, appModule.getCmpMappings());
        } catch (final JAXBException e) {
            throw new OpenEJBException("Unable to marshal cmp entity mappings", e);
        }
    }
    final ReportValidationResults reportValidationResults = new ReportValidationResults();
    reportValidationResults.deploy(appModule);
    logger.info("config.appLoaded", appInfo.path);
    appInfo.webAppAlone = appModule.isWebapp();
    return appInfo;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) BeforeAppInfoBuilderEvent(org.apache.openejb.config.event.BeforeAppInfoBuilderEvent) URL(java.net.URL) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) Messages(org.apache.openejb.util.Messages) ConnectorInfo(org.apache.openejb.assembler.classic.ConnectorInfo) JndiEncInfo(org.apache.openejb.assembler.classic.JndiEncInfo) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) References(org.apache.openejb.util.References) CircularReferencesException(org.apache.openejb.util.CircularReferencesException) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) EntityMappings(org.apache.openejb.jee.jpa.EntityMappings) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) URLs.toFile(org.apache.openejb.util.URLs.toFile) File(java.io.File)

Example 3 with ContainerInfo

use of org.apache.openejb.assembler.classic.ContainerInfo in project tomee by apache.

the class ConfigurationFactory method getContainerIds.

protected List<String> getContainerIds() {
    final List<String> containerIds = new ArrayList<>();
    final OpenEjbConfiguration runningConfig = getRunningConfig();
    if (runningConfig != null) {
        for (final ContainerInfo containerInfo : runningConfig.containerSystem.containers) {
            containerIds.add(containerInfo.id);
        }
    }
    if (sys != null) {
        for (final ContainerInfo containerInfo : sys.containerSystem.containers) {
            containerIds.add(containerInfo.id);
        }
        // the above sys instance
        if (openejb != null) {
            for (final Container container : openejb.getContainer()) {
                containerIds.add(container.getId());
            }
        }
    }
    return containerIds;
}
Also used : EJBContainer(javax.ejb.embeddable.EJBContainer) Container(org.apache.openejb.config.sys.Container) ArrayList(java.util.ArrayList) 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) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration)

Example 4 with ContainerInfo

use of org.apache.openejb.assembler.classic.ContainerInfo in project tomee by apache.

the class AutoConfig method matchContainer.

private String matchContainer(final Class<? extends ContainerInfo> containerInfoType, final EnterpriseBean bean, final Collection<ContainerInfo> list) {
    for (final ContainerInfo containerInfo : list) {
        if (containerInfo.getClass().equals(containerInfoType)) {
            // MDBs must match message listener interface type
            if (MessageDrivenBean.class.isInstance(bean)) {
                final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
                final String messagingType = messageDrivenBean.getMessagingType();
                if (containerInfo.properties.get("MessageListenerInterface").equals(messagingType)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Container {0} matches container type {1} and MessageListenerInterface {2} for bean {3}, this container will be used.", containerInfo.id, containerInfoType.getName(), messagingType, bean.getEjbName());
                    }
                    return containerInfo.id;
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Container {0} of type {1} does not have the matching MessageListenerInterface. Bean listener interface is {2}, " + "container listener interface is {3} for bean {4}. Skipping.", containerInfo.id, containerInfoType.getName(), messagingType, containerInfo.properties.get("MessageListenerInterface"), bean.getEjbName());
                    }
                }
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Container {0} matches container type {1} for bean {2}, this container will be used.", containerInfo.id, containerInfoType.getName(), bean.getEjbName());
                }
                return containerInfo.id;
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Skipping container {0} of type {1}", containerInfo.id, containerInfoType.getName());
        }
    }
    return null;
}
Also used : MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo)

Example 5 with ContainerInfo

use of org.apache.openejb.assembler.classic.ContainerInfo in project tomee by apache.

the class AutoConfig method deploy.

private void deploy(final EjbModule ejbModule, final AppResources appResources) throws OpenEJBException {
    final OpenejbJar openejbJar;
    if (ejbModule.getOpenejbJar() != null) {
        openejbJar = ejbModule.getOpenejbJar();
    } else {
        openejbJar = new OpenejbJar();
        ejbModule.setOpenejbJar(openejbJar);
    }
    final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        final EjbDeployment ejbDeployment = deployments.get(bean.getEjbName());
        if (ejbDeployment == null) {
            throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
        }
        final String beanType = getType(bean);
        final Class<? extends ContainerInfo> containerInfoType = ConfigurationFactory.getContainerInfoType(beanType);
        logger.debug("Bean type of bean {0} is {1}", bean.getEjbName(), beanType);
        if (ejbDeployment.getContainerId() == null && !skipMdb(bean)) {
            logger.debug("Container for bean {0} is not set, looking for a suitable container", bean.getEjbName());
            String containerId = getUsableContainer(containerInfoType, bean, appResources);
            if (containerId == null) {
                logger.debug("Suitable container for bean {0} not found, creating one", bean.getEjbName());
                containerId = createContainer(containerInfoType, ejbDeployment, bean);
            }
            logger.debug("Setting container ID {0} for bean {1}", containerId, bean.getEjbName());
            ejbDeployment.setContainerId(containerId);
        }
        logger.debug("Container ID for bean {0} is {1}", bean.getEjbName(), ejbDeployment.getContainerId());
        // create the container if it doesn't exist
        final List<String> containerIds = configFactory.getContainerIds();
        final Collection<ContainerInfo> containerInfos = appResources.getContainerInfos();
        for (final ContainerInfo containerInfo : containerInfos) {
            containerIds.add(containerInfo.id);
        }
        if (!containerIds.contains(ejbDeployment.getContainerId()) && !skipMdb(bean)) {
            logger.debug("Desired container {0} not found. Containers available: {1}. Creating a new container.", ejbDeployment.getContainerId(), Join.join(", ", containerIds));
            createContainer(containerInfoType, ejbDeployment, bean);
        }
        // Resource reference
        for (final ResourceRef ref : bean.getResourceRef()) {
            processResourceRef(ref, ejbDeployment, appResources, ejbModule);
        }
        // Resource env reference
        for (final JndiReference ref : bean.getResourceEnvRef()) {
            processResourceEnvRef(ref, ejbDeployment, appResources, ejbModule.getClassLoader());
        }
        // Message destination reference
        for (final MessageDestinationRef ref : bean.getMessageDestinationRef()) {
            processResourceEnvRef(ref, ejbDeployment, appResources, ejbModule.getClassLoader());
        }
        // mdb message destination id
        if (autoCreateResources && bean instanceof MessageDrivenBean) {
            final MessageDrivenBean mdb = (MessageDrivenBean) bean;
            final ResourceLink resourceLink = ejbDeployment.getResourceLink("openejb/destination");
            if (resourceLink != null) {
                try {
                    final String destinationId = getResourceEnvId(bean.getEjbName(), resourceLink.getResId(), mdb.getMessageDestinationType(), appResources);
                    resourceLink.setResId(destinationId);
                } catch (final OpenEJBException e) {
                    // The MDB doesn't need the auto configured "openejb/destination" env entry
                    ejbDeployment.removeResourceLink("openejb/destination");
                }
            }
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) MessageDestinationRef(org.apache.openejb.jee.MessageDestinationRef) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) JndiReference(org.apache.openejb.jee.JndiReference) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ResourceRef(org.apache.openejb.jee.ResourceRef)

Aggregations

ContainerInfo (org.apache.openejb.assembler.classic.ContainerInfo)17 MdbContainerInfo (org.apache.openejb.assembler.classic.MdbContainerInfo)9 Container (org.apache.openejb.config.sys.Container)7 ArrayList (java.util.ArrayList)5 OpenEJBException (org.apache.openejb.OpenEJBException)4 SingletonSessionContainerInfo (org.apache.openejb.assembler.classic.SingletonSessionContainerInfo)4 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)4 AppInfo (org.apache.openejb.assembler.classic.AppInfo)3 BmpEntityContainerInfo (org.apache.openejb.assembler.classic.BmpEntityContainerInfo)3 CmpEntityContainerInfo (org.apache.openejb.assembler.classic.CmpEntityContainerInfo)3 ManagedContainerInfo (org.apache.openejb.assembler.classic.ManagedContainerInfo)3 OpenEjbConfiguration (org.apache.openejb.assembler.classic.OpenEjbConfiguration)3 StatefulSessionContainerInfo (org.apache.openejb.assembler.classic.StatefulSessionContainerInfo)3 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)3 File (java.io.File)2 EJBContainer (javax.ejb.embeddable.EJBContainer)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2 EjbJar (org.apache.openejb.jee.EjbJar)2 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)2 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)2