Search in sources :

Example 6 with JndiConsumer

use of org.apache.openejb.jee.JndiConsumer in project tomee by apache.

the class CleanEnvEntries method fillInMissingType.

public AppModule fillInMissingType(final AppModule appModule) throws OpenEJBException {
    for (final ClientModule module : appModule.getClientModules()) {
        final JndiConsumer consumer = module.getApplicationClient();
        if (consumer == null) {
            continue;
        }
        fillInMissingType(consumer, module);
    }
    for (final WebModule module : appModule.getWebModules()) {
        final JndiConsumer consumer = module.getWebApp();
        if (consumer == null) {
            continue;
        }
        fillInMissingType(consumer, module);
    }
    for (final EjbModule module : appModule.getEjbModules()) {
        final EjbJar ejbJar = module.getEjbJar();
        if (ejbJar == null) {
            continue;
        }
        for (final EnterpriseBean consumer : ejbJar.getEnterpriseBeans()) {
            fillInMissingType(consumer, module);
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) JndiConsumer(org.apache.openejb.jee.JndiConsumer) EjbJar(org.apache.openejb.jee.EjbJar)

Example 7 with JndiConsumer

use of org.apache.openejb.jee.JndiConsumer in project tomee by apache.

the class ConvertDataSourceDefinitions method deploy.

@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    final List<JndiConsumer> jndiConsumers = collectConsumers(appModule);
    final KeyedCollection<String, DataSource> dataSources = new KeyedCollection<String, DataSource>();
    final KeyedCollection<String, DataSource> dataSourcesFromCompManagedBeans = new KeyedCollection<String, DataSource>();
    for (final JndiConsumer consumer : jndiConsumers) {
        if (consumer == null) {
            continue;
        }
        if (consumer instanceof org.apache.openejb.config.CompManagedBean) {
            /*
                 * TOMEE-2053: It may contain invalid datasource definitions
                 * because it is never updated with content from the ejb-jar.xml
                 * Wait until all other consumers have been processed, to safely
                 * decide which data sources to transfer;
                 */
            dataSourcesFromCompManagedBeans.addAll(consumer.getDataSource());
            continue;
        }
        dataSources.addAll(consumer.getDataSource());
    }
    final Map<String, DataSource> dataSourcesMap = dataSources.toMap();
    for (DataSource dataSource : dataSourcesFromCompManagedBeans) {
        // Interested only in DataSources that come from non-JndiConsumers
        if (!dataSourcesMap.containsKey(dataSource.getKey())) {
            dataSources.add(dataSource);
        }
    }
    for (final DataSource dataSource : dataSources) {
        appModule.getResources().add(toResource(dataSource));
    }
    return appModule;
}
Also used : KeyedCollection(org.apache.openejb.jee.KeyedCollection) JndiConsumer(org.apache.openejb.jee.JndiConsumer) DataSource(org.apache.openejb.jee.DataSource)

Example 8 with JndiConsumer

use of org.apache.openejb.jee.JndiConsumer in project tomee by apache.

the class AutoConfig method processApplicationResources.

private void processApplicationResources(final AppModule module) throws OpenEJBException {
    final Collection<Resource> resources = module.getResources();
    if (resources.size() == 0) {
        return;
    }
    final List<JndiConsumer> jndiConsumers = new ArrayList<JndiConsumer>();
    for (final WebModule webModule : module.getWebModules()) {
        final JndiConsumer consumer = webModule.getWebApp();
        jndiConsumers.add(consumer);
    }
    for (final EjbModule ejbModule : module.getEjbModules()) {
        Collections.addAll(jndiConsumers, ejbModule.getEjbJar().getEnterpriseBeans());
    }
    List<ResourceInfo> resourceInfos = new ArrayList<ResourceInfo>();
    final Map<ResourceInfo, Resource> resourcesMap = new HashMap<ResourceInfo, Resource>(resources.size());
    for (final Resource resource : resources) {
        final String originalId = PropertyPlaceHolderHelper.value(resource.getId());
        final String modulePrefix = module.getModuleId() + "/";
        if ("/".equals(modulePrefix) || originalId.startsWith("global") || originalId.startsWith("/global")) {
            resource.setId(replaceJavaAndSlash(originalId));
        } else {
            resource.getProperties().setProperty(ORIGINAL_ID, originalId);
            resource.setId(modulePrefix + replaceJavaAndSlash(originalId));
        }
        resource.setJndi(PropertyPlaceHolderHelper.value(resource.getJndi()));
        final Thread thread = Thread.currentThread();
        final ClassLoader oldCl = thread.getContextClassLoader();
        thread.setContextClassLoader(module.getClassLoader());
        try {
            resource.getProperties().putAll(PropertyPlaceHolderHelper.holds(resource.getProperties()));
        } finally {
            thread.setContextClassLoader(oldCl);
        }
        final Collection<String> aliases = resource.getAliases();
        if (!aliases.isEmpty()) {
            final Collection<String> newAliases = new ArrayList<String>();
            for (final String s : aliases) {
                newAliases.add(module.getModuleId() + "/" + s);
            }
            resource.getAliases().clear();
            resource.getAliases().addAll(newAliases);
        }
        final Properties properties = resource.getProperties();
        if (DataSource.class.getName().equals(resource.getType()) || DataSource.class.getSimpleName().equals(resource.getType())) {
            DataSourceFactory.trimNotSupportedDataSourceProperties(properties);
        }
        final boolean shouldGenerateJdbcUrl = DataSource.class.getName().equals(resource.getType()) && resource.getProperties().containsKey(ORIGIN_FLAG) && resource.getProperties().getProperty(ORIGIN_FLAG).equals(ORIGIN_ANNOTATION);
        if (shouldGenerateJdbcUrl && properties.get("JdbcUrl") == null) {
            final String url = getVendorUrl(properties);
            if (url != null) {
                properties.put("JdbcUrl", url);
            }
        }
        final ResourceInfo resourceInfo = configFactory.configureService(resource, ResourceInfo.class);
        resourceInfo.originAppName = module.getModuleId();
        final ResourceRef resourceRef = new ResourceRef();
        resourceRef.setResType(chooseType(module.getClassLoader(), resourceInfo, resource.getType()));
        if (shouldGenerateJdbcUrl) {
            properties.remove(ORIGIN_FLAG);
            resourceRef.setResRefName(dataSourceLookupName(resource));
        } else {
            resourceRef.setResRefName(OPENEJB_RESOURCE_JNDI_PREFIX + resourceInfo.id);
        }
        resourceRef.setMappedName(resourceInfo.id);
        final ResourceRef strictRef = new ResourceRef(OPENEJB_RESOURCE_JNDI_PREFIX + originalId, resourceRef.getResType(), resourceRef.getResAuth(), resourceRef.getResSharingScope());
        strictRef.setMappedName(resourceInfo.id);
        for (final JndiConsumer consumer : jndiConsumers) {
            // for injections etc...
            addResource(consumer, resourceRef);
            if (!"/".equals(modulePrefix)) {
                // for lookups (without prefix)
                addResource(consumer, strictRef);
            }
        }
        resourceInfos.add(resourceInfo);
        resourcesMap.put(resourceInfo, resource);
    }
    resourceInfos = ConfigurationFactory.sort(resourceInfos, module.getModuleId() + "/");
    for (final ResourceInfo resourceInfo : resourceInfos) {
        final int originalSize = resourceInfo.aliases.size();
        final String id = installResource(module.getModuleId(), resourceInfo);
        final Resource resource = resourcesMap.remove(resourceInfo);
        resource.setId(id);
        if (resourceInfo.aliases.size() > originalSize) {
            // an aliases is generally added to be able to bind in global jndi tree
            resource.getAliases().add(resourceInfo.aliases.get(resourceInfo.aliases.size() - 1));
        }
    }
    resourceInfos.clear();
// resources.clear(); // don't clear it since we want to keep this to be able to undeploy resources with the app
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) HashMap(java.util.HashMap) Resource(org.apache.openejb.config.sys.Resource) ArrayList(java.util.ArrayList) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) DataSource(javax.sql.DataSource) ResourceRef(org.apache.openejb.jee.ResourceRef) JndiConsumer(org.apache.openejb.jee.JndiConsumer)

Example 9 with JndiConsumer

use of org.apache.openejb.jee.JndiConsumer in project tomee by apache.

the class AutoConfig method resolvePersistenceRefs.

private void resolvePersistenceRefs(final AppModule appModule) {
    final LinkResolver<PersistenceUnit> persistenceUnits = new PersistenceUnitLinkResolver(appModule);
    for (final PersistenceModule module : appModule.getPersistenceModules()) {
        final String rootUrl = module.getRootUrl();
        for (final PersistenceUnit unit : module.getPersistence().getPersistenceUnit()) {
            unit.setId(appModule.persistenceUnitId(rootUrl, unit.getName()));
            persistenceUnits.add(rootUrl, unit.getName(), unit);
        }
    }
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final URI moduleURI = ejbModule.getModuleUri();
        for (final JndiConsumer component : ejbModule.getEjbJar().getEnterpriseBeans()) {
            processPersistenceRefs(component, ejbModule, persistenceUnits, moduleURI);
        }
    }
    for (final ClientModule clientModule : appModule.getClientModules()) {
        final URI moduleURI = URLs.uri(clientModule.getModuleId());
        processPersistenceRefs(clientModule.getApplicationClient(), clientModule, persistenceUnits, moduleURI);
    }
    for (final WebModule webModule : appModule.getWebModules()) {
        final URI moduleURI = URLs.uri(webModule.getModuleId());
        processPersistenceRefs(webModule.getWebApp(), webModule, persistenceUnits, moduleURI);
    }
}
Also used : PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) JndiConsumer(org.apache.openejb.jee.JndiConsumer) URI(java.net.URI)

Example 10 with JndiConsumer

use of org.apache.openejb.jee.JndiConsumer in project tomee by apache.

the class BaseConvertDefinitions method collectConsumers.

protected List<JndiConsumer> collectConsumers(final AppModule appModule) {
    final List<JndiConsumer> jndiConsumers = new ArrayList<JndiConsumer>();
    for (final ClientModule module : appModule.getClientModules()) {
        final JndiConsumer consumer = module.getApplicationClient();
        if (consumer == null) {
            continue;
        }
        jndiConsumers.add(consumer);
    }
    for (final WebModule webModule : appModule.getWebModules()) {
        final JndiConsumer consumer = webModule.getWebApp();
        if (consumer == null) {
            continue;
        }
        jndiConsumers.add(consumer);
    }
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        Collections.addAll(jndiConsumers, ejbModule.getEjbJar().getEnterpriseBeans());
    }
    if (appModule.getApplication() != null) {
        jndiConsumers.add(appModule.getApplication());
    }
    return jndiConsumers;
}
Also used : ArrayList(java.util.ArrayList) JndiConsumer(org.apache.openejb.jee.JndiConsumer)

Aggregations

JndiConsumer (org.apache.openejb.jee.JndiConsumer)11 EjbJar (org.apache.openejb.jee.EjbJar)5 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)5 KeyedCollection (org.apache.openejb.jee.KeyedCollection)3 ArrayList (java.util.ArrayList)2 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 DataSource (javax.sql.DataSource)1 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)1 Resource (org.apache.openejb.config.sys.Resource)1 DataSource (org.apache.openejb.jee.DataSource)1 EnvEntry (org.apache.openejb.jee.EnvEntry)1 JMSConnectionFactory (org.apache.openejb.jee.JMSConnectionFactory)1 JMSDestination (org.apache.openejb.jee.JMSDestination)1 ResourceRef (org.apache.openejb.jee.ResourceRef)1 SessionBean (org.apache.openejb.jee.SessionBean)1 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)1 SuperProperties (org.apache.openejb.util.SuperProperties)1