EARContext moduleContext = module.getEarContext();
ClassLoader moduleClassLoader = moduleContext.getClassLoader();
AbstractName moduleName = moduleContext.getModuleName();
WebModule webModule = (WebModule) module;
WebAppType webApp = (WebAppType) webModule.getSpecDD();
JettyWebAppType jettyWebApp = (JettyWebAppType) webModule.getVendorDD();
//N.B. we use the ear context which has all the gbeans we could possibly be looking up from this ear.
Map buildingContext = new HashMap();
buildingContext.put(NamingBuilder.JNDI_KEY, new HashMap());
buildingContext.put(NamingBuilder.GBEAN_NAME_KEY, moduleName);
Configuration earConfiguration = earContext.getConfiguration();
getNamingBuilders().buildNaming(webApp, jettyWebApp, earConfiguration, earConfiguration, (Module) webModule, buildingContext);
Map compContext = (Map) buildingContext.get(NamingBuilder.JNDI_KEY);
GBeanData webModuleData = new GBeanData(moduleName, JettyWebAppContext.GBEAN_INFO);
try {
moduleContext.addGBean(webModuleData);
if (moduleContext.getServerName() != null) {
webModuleData.setReferencePattern("J2EEServer", moduleContext.getServerName());
}
if (!module.isStandAlone()) {
webModuleData.setReferencePattern("J2EEApplication", earContext.getModuleName());
}
webModuleData.setAttribute("deploymentDescriptor", module.getOriginalSpecDD());
Set securityRoles = collectRoleNames(webApp);
Map rolePermissions = new HashMap();
// configure hosts and virtual-hosts
configureHosts(earContext, jettyWebApp, webModuleData);
//Add dependencies on managed connection factories and ejbs in this app
//This is overkill, but allows for people not using java:comp context (even though we don't support it)
//and sidesteps the problem of circular references between ejbs.
Set dependencies = findGBeanDependencies(earContext);
webModuleData.addDependencies(dependencies);
webModuleData.setAttribute("componentContext", compContext);
//classpath may have been augmented with enhanced classes
// webModuleData.setAttribute("webClassPath", webModule.getWebClasspath());
// unsharableResources, applicationManagedSecurityResources
GBeanResourceEnvironmentBuilder rebuilder = new GBeanResourceEnvironmentBuilder(webModuleData);
//N.B. use earContext not moduleContext
//TODO fix this for javaee 5 !!!
resourceEnvironmentSetter.setResourceEnvironment(rebuilder, webApp.getResourceRefArray(), jettyWebApp.getResourceRefArray());
String contextPath = webModule.getContextRoot();
if (contextPath == null) {
throw new DeploymentException("null contextPath");
}
if (!contextPath.startsWith("/")) {
contextPath = "/" + contextPath;
}
webModuleData.setAttribute("contextPath", contextPath);
webModuleData.setReferencePattern("TransactionManager", moduleContext.getTransactionManagerName());
webModuleData.setReferencePattern("TrackedConnectionAssociator", moduleContext.getConnectionTrackerName());
if (jettyWebApp.isSetWebContainer()) {
AbstractNameQuery webContainerName = ENCConfigBuilder.getGBeanQuery(NameFactory.GERONIMO_SERVICE, jettyWebApp.getWebContainer());
webModuleData.setReferencePattern("JettyContainer", webContainerName);
} else {
webModuleData.setReferencePattern("JettyContainer", jettyContainerObjectName);
}
//stuff that jetty6 used to do
if (webApp.getDisplayNameArray().length > 0) {
webModuleData.setAttribute("displayName", webApp.getDisplayNameArray()[0].getStringValue());
}
// configure context parameters.
configureContextParams(webApp, webModuleData);
// configure listeners.
configureListeners(webApp, webModuleData);
Boolean distributable = webApp.getDistributableArray().length == 1 ? Boolean.TRUE : Boolean.FALSE;
webModuleData.setAttribute("distributable", distributable);
if (Boolean.TRUE == distributable) {
clusteringBuilders.build(jettyWebApp, earContext, moduleContext);
if (webModuleData.getReferencePatterns(JettyWebAppContext.GBEAN_REF_SESSION_HANDLER_FACTORY) == null)
{
log.warn("No clustering builders configured: app will not be clustered");
configureNoClustering(moduleContext, webModuleData);
}
} else {
configureNoClustering(moduleContext, webModuleData);
}
webModuleData.setAttribute("sessionTimeoutSeconds",
(webApp.getSessionConfigArray().length == 1 && webApp.getSessionConfigArray(0).getSessionTimeout() != null) ?
new Integer(webApp.getSessionConfigArray(0).getSessionTimeout().getBigIntegerValue().intValue() * 60) :
defaultSessionTimeoutSeconds);
// configure mime mappings.
configureMimeMappings(webApp, webModuleData);
// configure welcome file lists.
configureWelcomeFileLists(webApp, webModuleData);
// configure local encoding mapping lists.
configureLocalEncodingMappingLists(webApp, webModuleData);
// configure error pages.
configureErrorPages(webApp, webModuleData);
// configure tag libs.
configureTagLibs(module, webApp, webModuleData);
// configure login configs.
configureLoginConfigs(module, webApp, jettyWebApp, webModuleData);
// Make sure that servlet mappings point to available servlets and never add a duplicate pattern.
Set knownServletMappings = new HashSet();
Map servletMappings = new HashMap();
buildServletMappings(module, webApp, servletMappings, knownServletMappings);
//"previous" filter mapping for linked list to keep dd's ordering.
AbstractName previous = null;
//add default filters
if (defaultFilters != null) {
previous = addDefaultFiltersGBeans(earContext, moduleContext, moduleName, previous);
}
//add default filtermappings
// if (defaultFilterMappings != null) {
// for (Iterator iterator = defaultFilterMappings.iterator(); iterator.hasNext();) {
// Object defaultFilterMapping = iterator.next();
// GBeanData filterMappingGBeanData = getGBeanData(kernel, defaultFilterMapping);
// String filterName = (String) filterMappingGBeanData.getAttribute("filterName");
// ObjectName defaultFilterMappingObjectName;
// if (filterMappingGBeanData.getAttribute("urlPattern") != null) {
// String urlPattern = (String) filterMappingGBeanData.getAttribute("urlPattern");
// defaultFilterMappingObjectName = NameFactory.getWebFilterMappingName(null, null, null, null, filterName, null, urlPattern, moduleName);
// } else {
// Set servletNames = filterMappingGBeanData.getReferencePatterns("Servlet");
// if (servletNames == null || servletNames.size() != 1) {
// throw new DeploymentException("Exactly one servlet name must be supplied");
// }
// ObjectName servletObjectName = (ObjectName) servletNames.iterator().next();
// String servletName = servletObjectName.getKeyProperty("name");
// defaultFilterMappingObjectName = NameFactory.getWebFilterMappingName(null, null, null, null, filterName, servletName, null, moduleName);
// }
// filterMappingGBeanData.setName(defaultFilterMappingObjectName);
// filterMappingGBeanData.setReferencePattern("JettyFilterMappingRegistration", webModuleName);
// moduleContext.addGBean(filterMappingGBeanData);
// }
// }
// add filter mapping GBeans.
addFilterMappingsGBeans(earContext, moduleContext, moduleName, webApp, previous);
// add filter GBeans.
addFiltersGBeans(earContext, moduleContext, moduleName, webApp);
//add default servlets
if (defaultServlets != null) {
addDefaultServletsGBeans(earContext, moduleContext, moduleName, knownServletMappings);
}
//set up servlet gbeans.
ServletType[] servletTypes = webApp.getServletArray();
addServlets(moduleName, webModule, servletTypes, servletMappings, securityRoles, rolePermissions, moduleContext);
if (jettyWebApp.isSetSecurityRealmName()) {
configureSecurityRealm(earContext, webApp, jettyWebApp, webModuleData, securityRoles, rolePermissions);
}