private WebModule createWebModule(StandardContext standardContext) {
// todo replace this code with DeploymentLoader
ServletContext servletContext = standardContext.getServletContext();
// read the web.xml
WebApp webApp = new WebApp();
try {
URL webXmlUrl = servletContext.getResource("/WEB-INF/web.xml");
if (webXmlUrl != null) {
webApp = ReadDescriptors.readWebApp(webXmlUrl);
}
} catch (Exception e) {
logger.error("Unable to load web.xml in war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
}
// create the web module
String basePath = new File(servletContext.getRealPath(".")).getParentFile().getAbsolutePath();
ClassLoader classLoader = ClassLoaderUtil.createTempClassLoader(standardContext.getLoader().getClassLoader());
String path = standardContext.getPath();
System.out.println("context path = " + path);
WebModule webModule = new WebModule(webApp, path, classLoader, basePath, getId(standardContext));
webModule.setHost(standardContext.getHostname());
// add faces configurations
try {
addFacesConfigs(webModule);
} catch (OpenEJBException e1) {
logger.error("Unable to add faces config modules in " + standardContext.getPath() + ": Exception: " + e1.getMessage(), e1);
// TODO :kmalhi:: Remove stack trace after testing
e1.printStackTrace();
}
// Add all Tomcat env entries to context so they can be overriden by the env.properties file
NamingResources naming = standardContext.getNamingResources();
for (ContextEnvironment environment : naming.findEnvironments()) {
EnvEntry envEntry = webApp.getEnvEntryMap().get(environment.getName());
if (envEntry == null) {
envEntry = new EnvEntry();
envEntry.setName(environment.getName());
webApp.getEnvEntry().add(envEntry);
}
envEntry.setEnvEntryValue(environment.getValue());
envEntry.setEnvEntryType(environment.getType());
}
// process the annotations
try {
AnnotationDeployer annotationDeployer = new AnnotationDeployer();
annotationDeployer.deploy(webModule);
} catch (OpenEJBException e) {
logger.error("Unable to process annotation in " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
}
// remove all jndi entries where there is a configured Tomcat resource or resource-link
webApp = webModule.getWebApp();
for (ContextResource resource : naming.findResources()) {
String name = resource.getName();
removeRef(webApp, name);
}
for (ContextResourceLink resourceLink : naming.findResourceLinks()) {
String name = resourceLink.getName();
removeRef(webApp, name);
}
// remove all env entries from the web xml that are not overridable
for (ContextEnvironment environment : naming.findEnvironments()) {
if (!environment.getOverride()) {
// overrides are not allowed
webApp.getEnvEntryMap().remove(environment.getName());
}
}
return webModule;
}