use of org.apache.openejb.assembler.classic.JndiEncInfo 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;
}
use of org.apache.openejb.assembler.classic.JndiEncInfo in project tomee by apache.
the class XmlOverridesTest method test.
public void test() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(AnnotatedBean.class));
bean.getEjbLocalRef().add(new EjbLocalRef(name("annotatedLocal"), "BarBean"));
bean.getEnvEntry().add(new EnvEntry(name("striing"), "java.lang.Integer", "2"));
bean.getEnvEntry().add(new EnvEntry(name("doouble"), "java.lang.String", "two"));
bean.getEnvEntry().add(new EnvEntry(name("loong"), "java.lang.String", "three"));
bean.getEnvEntry().add(new EnvEntry(name("flooat"), "java.lang.String", "four"));
bean.getEnvEntry().add(new EnvEntry(name("inteeger"), "java.lang.String", "five"));
bean.getEnvEntry().add(new EnvEntry(name("shoort"), "java.lang.String", "six"));
bean.getEnvEntry().add(new EnvEntry(name("booolean"), "java.lang.String", "seven"));
bean.getEnvEntry().add(new EnvEntry(name("byyte"), "java.lang.String", "eight"));
bean.getEnvEntry().add(new EnvEntry(name("chaaracter"), "java.lang.String", "nine"));
final EnvEntry lookupEntry = new EnvEntry(name("lookup"), "java.lang.String", null);
lookupEntry.setLookupName("java:app/AppName");
bean.getEnvEntry().add(lookupEntry);
bean.getResourceRef().add(new ResourceRef(name("daataSource"), DataSource.class.getName(), ResAuth.CONTAINER, ResSharingScope.SHAREABLE));
bean.getPersistenceUnitRef().add(new PersistenceUnitRef(name("emf"), "yellow"));
bean.getPersistenceContextRef().add(new PersistenceContextRef(name("em"), "yellow", PersistenceContextType.TRANSACTION, new ArrayList(Arrays.asList(new Property("zzzz", "AAAA")))));
final org.apache.openejb.jee.jpa.unit.PersistenceUnit persistenceUnit = new org.apache.openejb.jee.jpa.unit.PersistenceUnit("yellow");
final AppModule app = new AppModule(this.getClass().getClassLoader(), "app");
app.getEjbModules().add(new EjbModule(ejbJar));
app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
final AppInfo appInfo = config.configureApplication(app);
final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
final JndiEncInfo enc = beanInfo.jndiEnc;
assertEquals("Enc.ejbLocalReferences.size()", 1, enc.ejbLocalReferences.size());
assertEquals("Enc.ejbLocalReferences.get(0).link", "BarBean", enc.ejbLocalReferences.get(0).link);
assertEquals("Enc.ejbReferences.size()", 0, enc.ejbReferences.size());
// 10 + ComponentName
assertEquals("Enc.envEntries.size()", 11, enc.envEntries.size());
final Map<String, EnvEntryInfo> entries = map(enc.envEntries);
assertEnvEntry(entries, name("striing"), "java.lang.Integer", "2");
assertEnvEntry(entries, name("doouble"), "java.lang.String", "two");
assertEnvEntry(entries, name("loong"), "java.lang.String", "three");
assertEnvEntry(entries, name("flooat"), "java.lang.String", "four");
assertEnvEntry(entries, name("inteeger"), "java.lang.String", "five");
assertEnvEntry(entries, name("shoort"), "java.lang.String", "six");
assertEnvEntry(entries, name("booolean"), "java.lang.String", "seven");
assertEnvEntry(entries, name("byyte"), "java.lang.String", "eight");
assertEnvEntry(entries, name("chaaracter"), "java.lang.String", "nine");
assertEnvEntryLookup(entries, name("lookup"), "java.lang.String", "java:app/AppName");
assertEquals("Enc.persistenceContextRefs.size()", 1, enc.persistenceContextRefs.size());
final PersistenceContextReferenceInfo context = enc.persistenceContextRefs.get(0);
assertEquals("Context.extended", false, context.extended);
assertEquals("Context.persistenceUnitName", "yellow", context.persistenceUnitName);
assertEquals("Context.properties.size()", 1, context.properties.size());
assertEquals("Context.properties.getProperty(\"zzzz\")", "AAAA", context.properties.getProperty("zzzz"));
assertEquals("Enc.persistenceUnitRefs.size()", 1, enc.persistenceUnitRefs.size());
final PersistenceUnitReferenceInfo unit = enc.persistenceUnitRefs.get(0);
assertEquals("Unit.persistenceUnitName", "yellow", unit.persistenceUnitName);
assertEquals("Enc.resourceRefs.size()", 1, enc.resourceRefs.size());
final ResourceReferenceInfo resource = enc.resourceRefs.get(0);
assertEquals("Resource.referenceAuth", "CONTAINER", resource.referenceAuth);
}
Aggregations