Search in sources :

Example 1 with MdbContainerInfo

use of org.apache.openejb.assembler.classic.MdbContainerInfo 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 2 with MdbContainerInfo

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

the class AutoConfigMdbContainerTest method _testConfiguredContainerSelection.

public void _testConfiguredContainerSelection() throws Exception {
    // Create a JMS MDB Container
    final MdbContainerInfo info = config.configureService(MdbContainerInfo.class);
    assertEquals(MessageListener.class.getName(), info.properties.get("MessageListenerInterface"));
    assembler.createContainer(info);
    // Create an Email MDB Container
    final Container container = new Container("EmailContainer", "MESSAGE", null);
    final Properties properties = container.getProperties();
    properties.setProperty("ResourceAdapter", EmailResourceAdapter.class.getSimpleName());
    properties.setProperty("MessageListenerInterface", EmailConsumer.class.getName());
    properties.setProperty("ActivationSpecClass", EmailAccountInfo.class.getName());
    assembler.createContainer(config.configureService(container, MdbContainerInfo.class));
}
Also used : Container(org.apache.openejb.config.sys.Container) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) MessageListener(javax.jms.MessageListener) Properties(java.util.Properties)

Example 3 with MdbContainerInfo

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

the class AppInfoBuilder method buildConnectorModules.

private void buildConnectorModules(final AppModule appModule, final AppInfo appInfo) throws OpenEJBException {
    final String appId = appModule.getModuleId();
    for (final ConnectorModule connectorModule : appModule.getConnectorModules()) {
        // 
        // DEVELOPERS NOTE:  if you change the id generation code here, you must change
        // the id generation code in AutoConfig$AppResources
        // 
        final Connector connector = connectorModule.getConnector();
        final ConnectorInfo connectorInfo = new ConnectorInfo();
        connectorInfo.description = connector.getDescription();
        connectorInfo.displayName = connector.getDisplayName();
        connectorInfo.path = connectorModule.getJarLocation();
        connectorInfo.moduleId = connectorModule.getModuleId();
        connectorInfo.watchedResources.addAll(connectorModule.getWatchedResources());
        connectorInfo.validationInfo = ValidatorBuilder.getInfo(connectorModule.getValidationConfig());
        connectorInfo.uniqueId = connectorModule.getUniqueId();
        connectorInfo.mbeans = connectorModule.getMbeans();
        final List<URL> libraries = connectorModule.getLibraries();
        for (final URL url : libraries) {
            final File file = toFile(url);
            try {
                connectorInfo.libs.add(file.getCanonicalPath());
            } catch (final IOException e) {
                throw new IllegalArgumentException("Invalid application lib path " + file.getAbsolutePath());
            }
        }
        final ResourceAdapter resourceAdapter = connector.getResourceAdapter();
        if (resourceAdapter.getResourceAdapterClass() != null) {
            final String id = this.getId(connectorModule);
            final String className = resourceAdapter.getResourceAdapterClass();
            final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
            provider.getTypes().add(className);
            ServiceUtils.registerServiceProvider(appId, provider);
            final Resource resource = new Resource(id, className, appId + "#" + id);
            for (final ConfigProperty property : resourceAdapter.getConfigProperty()) {
                final String name = property.getConfigPropertyName();
                final String value = property.getConfigPropertyValue();
                if (value != null) {
                    resource.getProperties().setProperty(name, value);
                }
            }
            connectorInfo.resourceAdapter = this.configFactory.configureService(resource, ResourceInfo.class);
        }
        final OutboundResourceAdapter outbound = resourceAdapter.getOutboundResourceAdapter();
        if (outbound != null) {
            String transactionSupport = "none";
            final TransactionSupportType transactionSupportType = outbound.getTransactionSupport();
            if (transactionSupportType != null) {
                switch(transactionSupportType) {
                    case LOCAL_TRANSACTION:
                        transactionSupport = "local";
                        break;
                    case NO_TRANSACTION:
                        transactionSupport = "none";
                        break;
                    case XA_TRANSACTION:
                        transactionSupport = "xa";
                        break;
                }
            }
            for (final ConnectionDefinition connection : outbound.getConnectionDefinition()) {
                final String id = this.getId(connection, outbound, connectorModule);
                final String className = connection.getManagedConnectionFactoryClass();
                final String type = connection.getConnectionFactoryInterface();
                final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
                provider.getTypes().add(type);
                ServiceUtils.registerServiceProvider(appId, provider);
                final Resource resource = new Resource(id, type, appId + "#" + id);
                final Properties properties = resource.getProperties();
                for (final ConfigProperty property : connection.getConfigProperty()) {
                    final String name = property.getConfigPropertyName();
                    final String value = property.getConfigPropertyValue();
                    if (value != null) {
                        properties.setProperty(name, value);
                    }
                }
                properties.setProperty("TransactionSupport", transactionSupport);
                if (connectorInfo.resourceAdapter != null) {
                    properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
                }
                final ResourceInfo resourceInfo = this.configFactory.configureService(resource, ResourceInfo.class);
                connectorInfo.outbound.add(resourceInfo);
            }
        }
        final InboundResourceadapter inbound = resourceAdapter.getInboundResourceAdapter();
        if (inbound != null) {
            for (final MessageListener messageListener : inbound.getMessageAdapter().getMessageListener()) {
                final String id = this.getId(messageListener, inbound, connectorModule);
                final Container container = new Container(id, "MESSAGE", null);
                final Properties properties = container.getProperties();
                properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
                properties.setProperty("MessageListenerInterface", messageListener.getMessageListenerType());
                properties.setProperty("ActivationSpecClass", messageListener.getActivationSpec().getActivationSpecClass());
                final MdbContainerInfo mdbContainerInfo = this.configFactory.configureService(container, MdbContainerInfo.class);
                connectorInfo.inbound.add(mdbContainerInfo);
            }
        }
        for (final AdminObject adminObject : resourceAdapter.getAdminObject()) {
            final String id = this.getId(adminObject, resourceAdapter, connectorModule);
            final String className = adminObject.getAdminObjectClass();
            final String type = adminObject.getAdminObjectInterface();
            final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
            provider.getTypes().add(type);
            ServiceUtils.registerServiceProvider(appId, provider);
            final Resource resource = new Resource(id, type, appId + "#" + id);
            final Properties properties = resource.getProperties();
            for (final ConfigProperty property : adminObject.getConfigProperty()) {
                final String name = property.getConfigPropertyName();
                final String value = property.getConfigPropertyValue();
                if (value != null) {
                    properties.setProperty(name, value);
                }
            }
            final ResourceInfo resourceInfo = this.configFactory.configureService(resource, ResourceInfo.class);
            connectorInfo.adminObject.add(resourceInfo);
        }
        appInfo.connectors.add(connectorInfo);
    }
}
Also used : Connector(org.apache.openejb.jee.Connector) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) ConnectionDefinition(org.apache.openejb.jee.ConnectionDefinition) ConnectorInfo(org.apache.openejb.assembler.classic.ConnectorInfo) TransactionSupportType(org.apache.openejb.jee.TransactionSupportType) Resource(org.apache.openejb.config.sys.Resource) MessageListener(org.apache.openejb.jee.MessageListener) IOException(java.io.IOException) Properties(java.util.Properties) URL(java.net.URL) Container(org.apache.openejb.config.sys.Container) ServiceProvider(org.apache.openejb.config.sys.ServiceProvider) ConfigProperty(org.apache.openejb.jee.ConfigProperty) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) OutboundResourceAdapter(org.apache.openejb.jee.OutboundResourceAdapter) ResourceAdapter(org.apache.openejb.jee.ResourceAdapter) InboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter) URLs.toFile(org.apache.openejb.util.URLs.toFile) File(java.io.File) OutboundResourceAdapter(org.apache.openejb.jee.OutboundResourceAdapter) AdminObject(org.apache.openejb.jee.AdminObject)

Aggregations

MdbContainerInfo (org.apache.openejb.assembler.classic.MdbContainerInfo)3 File (java.io.File)2 IOException (java.io.IOException)2 URL (java.net.URL)2 Properties (java.util.Properties)2 ConnectorInfo (org.apache.openejb.assembler.classic.ConnectorInfo)2 Container (org.apache.openejb.config.sys.Container)2 URLs.toFile (org.apache.openejb.util.URLs.toFile)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 MessageListener (javax.jms.MessageListener)1 JAXBException (javax.xml.bind.JAXBException)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 AppInfo (org.apache.openejb.assembler.classic.AppInfo)1 ContainerInfo (org.apache.openejb.assembler.classic.ContainerInfo)1 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)1 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)1