*/
// @Override
private void startInternal(final StandardContext standardContext) {
if (isIgnored(standardContext)) return;
final CoreContainerSystem cs = getContainerSystem();
final Assembler a = getAssembler();
if (a == null) {
logger.warning("OpenEJB has not been initialized so war will not be scanned for nested modules " + standardContext.getPath());
return;
}
AppContext appContext = null;
//Look for context info, maybe context is already scanned
ContextInfo contextInfo = getContextInfo(standardContext);
ClassLoader classLoader = standardContext.getLoader().getClassLoader();
if (contextInfo == null) {
final AppModule appModule = loadApplication(standardContext);
if (standardContext.getNamingResources() instanceof OpenEJBNamingResource) {
// add them to the app as resource
final OpenEJBNamingResource nr = (OpenEJBNamingResource) standardContext.getNamingResources();
for (ResourceBase resource : nr.getTomcatResources()) {
final String name = resource.getName();
boolean found = false;
for (ResourceInfo r : SystemInstance.get().getComponent(OpenEjbConfiguration.class).facilities.resources) {
if (r.id.equals(name)) {
nr.removeResource(name);
found = true;
logger.warning(name + " resource was defined in both tomcat and tomee so removing tomcat one");
break;
}
}
if (!found) {
final Resource newResource = new Resource(name, resource.getType(), "org.apache.tomee:ProvidedByTomcat");
newResource.getProperties().setProperty("jndiName", newResource.getId());
newResource.getProperties().setProperty("appName", getId(standardContext));
newResource.getProperties().setProperty("factory", (String) resource.getProperty("factory"));
appModule.getResources().add(newResource);
}
}
}
if (appModule != null) {
try {
contextInfo = addContextInfo(standardContext.getHostname(), standardContext);
contextInfo.standardContext = standardContext; // ensure to do it before an exception can be thrown
contextInfo.appInfo = configurationFactory.configureApplication(appModule);
final Boolean autoDeploy = DeployerEjb.AUTO_DEPLOY.get();
contextInfo.appInfo.autoDeploy = autoDeploy == null || autoDeploy;
DeployerEjb.AUTO_DEPLOY.remove();
if (!appModule.isWebapp()) {
classLoader = appModule.getClassLoader();
}
appContext = a.createApplication(contextInfo.appInfo, classLoader);
// todo add watched resources to context
} catch (Exception e) {
logger.error("Unable to deploy collapsed ear in war " + standardContext, e);
undeploy(standardContext, contextInfo);
// just to force tomee to start without EE part
if (System.getProperty(TOMEE_EAT_EXCEPTION_PROP) == null) {
final TomEERuntimeException tre = new TomEERuntimeException(e);
final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
dem.saveDeploymentException(contextInfo.appInfo, tre);
throw tre;
}
return;
}
}
} else {
contextInfo.standardContext = standardContext;
}
final String id = getId(standardContext);
WebAppInfo webAppInfo = null;
// appInfo is null when deployment fails
if (contextInfo.appInfo != null) {
for (final WebAppInfo w : contextInfo.appInfo.webApps) {
final String wId = getId(w.host, w.contextRoot);
if (id.equals(wId)) {
webAppInfo = w;
if (appContext == null) {
appContext = cs.getAppContext(contextInfo.appInfo.appId);
}
break;
}
}
}
if (webAppInfo != null) {
if (appContext == null) {
appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId);
}
// ensure matching (see getId() usage)
webAppInfo.host = standardContext.getHostname();
webAppInfo.contextRoot = standardContext.getName();
// save jsf stuff
final Map<String, Set<String>> scannedJsfClasses = new HashMap<String, Set<String>>();
for (final ClassListInfo info : webAppInfo.jsfAnnotatedClasses) {
scannedJsfClasses.put(info.name, info.list);
}
jsfClasses.put(standardContext.getLoader().getClassLoader(), scannedJsfClasses);
try {
// determine the injections
final Set<Injection> injections = new HashSet<Injection>();
injections.addAll(appContext.getInjections());
if (!contextInfo.appInfo.webAppAlone) {
updateInjections(injections, classLoader, false);
for (final BeanContext bean : appContext.getBeanContexts()) { // TODO: how if the same class in multiple webapps?
updateInjections(bean.getInjections(), classLoader, true);
}
}
injections.addAll(new InjectionBuilder(classLoader).buildInjections(webAppInfo.jndiEnc));
// jndi bindings
final Map<String, Object> bindings = new HashMap<String, Object>();
bindings.putAll(appContext.getBindings());
bindings.putAll(getJndiBuilder(classLoader, webAppInfo, injections).buildBindings(JndiEncBuilder.JndiScope.comp));
// merge OpenEJB jndi into Tomcat jndi
final TomcatJndiBuilder jndiBuilder = new TomcatJndiBuilder(standardContext, webAppInfo, injections);
NamingUtil.setCurrentContext(standardContext);
try {
jndiBuilder.mergeJndi();
} finally {
NamingUtil.setCurrentContext(null);
}
// add WebDeploymentInfo to ContainerSystem
final WebContext webContext = new WebContext(appContext);
webContext.setJndiEnc(new InitialContext());
webContext.setClassLoader(classLoader);
webContext.setId(webAppInfo.moduleId);
webContext.setContextRoot(webAppInfo.contextRoot);
webContext.setBindings(bindings);
webContext.getInjections().addAll(injections);
appContext.getWebContexts().add(webContext);
cs.addWebContext(webContext);
if (!contextInfo.appInfo.webAppAlone) {
new CdiBuilder().build(contextInfo.appInfo, appContext, appContext.getBeanContexts(), webContext);
}