public void addGBeans(EARContext earContext, Module module, Bundle bundle, Collection repository) throws DeploymentException {
EARContext moduleContext = module.getEarContext();
AbstractName moduleName = module.getModuleName();
WebModule webModule = (WebModule) module;
WebApp webApp = webModule.getSpecDD();
JettyWebAppType jettyWebApp = (JettyWebAppType) webModule.getVendorDD();
GBeanData webModuleData = new GBeanData(moduleName, WebAppContextWrapper.class);
configureBasicWebModuleAttributes(webApp, jettyWebApp, moduleContext, earContext, webModule, webModuleData);
// unsharableResources, applicationManagedSecurityResources
GBeanResourceEnvironmentBuilder rebuilder = new GBeanResourceEnvironmentBuilder(webModuleData);
//N.B. use earContext not moduleContext
//TODO fix this for javaee 5 !!!
resourceEnvironmentSetter.setResourceEnvironment(rebuilder, webApp.getResourceRef(), jettyWebApp.getResourceRefArray());
try {
moduleContext.addGBean(webModuleData);
// configure WebAppContextManager with right priority so that it starts last
AbstractName contextManagerName = earContext.getNaming().createChildName(moduleName, "WebAppContextManager", NameFactory.SERVICE_MODULE);
GBeanData contextManagerGBean = new GBeanData(contextManagerName, WebAppContextManager.class);
contextManagerGBean.setPriority(100);
contextManagerGBean.setReferencePattern("webApp", moduleName);
moduleContext.addGBean(contextManagerGBean);
// configure hosts and virtual-hosts
configureHosts(earContext, jettyWebApp, webModuleData);
String contextPath = webModule.getContextRoot();
if (contextPath == null) {
throw new DeploymentException("null contextPath");
}
if (!contextPath.startsWith("/")) {
contextPath = "/" + contextPath;
}
webModuleData.setAttribute("contextPath", contextPath);
if (jettyWebApp.isSetWorkDir()) {
String workDir = jettyWebApp.getWorkDir();
webModuleData.setAttribute("workDir", workDir);
}
if (jettyWebApp.isSetWebContainer()) {
AbstractNameQuery webContainerName = ENCConfigBuilder.getGBeanQuery(GBeanInfoBuilder.DEFAULT_J2EE_TYPE, jettyWebApp.getWebContainer());
webModuleData.setReferencePattern("JettyContainer", webContainerName);
} else {
webModuleData.setReferencePattern("JettyContainer", jettyContainerObjectName);
}
//stuff that jetty used to do
webModuleData.setAttribute("displayName", webApp.getDisplayName());
WebAppInfoBuilder webAppInfoBuilder = new WebAppInfoBuilder(webApp, webAppInfoFactory);
WebAppInfo webAppInfo = webAppInfoBuilder.build();
webModuleData.setAttribute("webAppInfo", webAppInfo);
webModule.getSharedContext().put(WebModule.WEB_APP_INFO, webAppInfoBuilder);
//TODO merge from default web app
if (webAppInfo.sessionConfig != null) {
if (webAppInfo.sessionConfig.sessionTimeoutMinutes == -1 && defaultSessionTimeoutMinutes != -1) {
webAppInfo.sessionConfig.sessionTimeoutMinutes = defaultSessionTimeoutMinutes;
}
}
if (webAppInfo.distributable) {
clusteringBuilders.build(jettyWebApp, earContext, moduleContext);
if (webModuleData.getReferencePatterns(WebAppContextWrapper.GBEAN_REF_SESSION_HANDLER_FACTORY) == null) {
log.warn("No clustering builders configured: app will not be clustered");
configureNoClustering(moduleContext, webModuleData);
}
} else {
configureNoClustering(moduleContext, webModuleData);
}
// configure login configs.
configureAuthentication(module, webAppInfo.loginConfig, jettyWebApp, webModuleData);
if (jettyWebApp.isSetSecurityRealmName()) {
configureSecurityRealm(earContext, webApp, jettyWebApp, bundle, webModuleData);
}
//See Jetty-386, GERONIMO-3738
if (jettyWebApp.getCompactPath()) {
webModuleData.setAttribute("compactPath", Boolean.TRUE);
}
LinkedHashSet<Module<?, ?>> submodules = module.getModules();
for (Module<?, ?> subModule: submodules) {
if (subModule.getSharedContext().get(SharedOwbContext.class) != null) {
GBeanData data = (GBeanData) subModule.getSharedContext().get(SharedOwbContext.class);
AbstractName name = data.getAbstractName();
webModuleData.setReferencePattern("SharedOwbContext", name);
}
}
//Save Deployment Attributes
Map<String, Object> deploymentAttributes = new HashMap<String, Object>();
deploymentAttributes.put(WebApplicationConstants.META_COMPLETE, webApp.isMetadataComplete());
deploymentAttributes.put(WebApplicationConstants.SCHEMA_VERSION, INITIAL_WEB_XML_SCHEMA_VERSION.get(webModule.getEarContext().getGeneralData()));
deploymentAttributes.put(WebApplicationConstants.ORDERED_LIBS, AbstractWebModuleBuilder.ORDERED_LIBS.get(webModule.getEarContext().getGeneralData()));
deploymentAttributes.put(WebApplicationConstants.SERVLET_CONTAINER_INITIALIZERS, AbstractWebModuleBuilder.SERVLET_CONTAINER_INITIALIZERS.get(webModule.getEarContext().getGeneralData()));
webModuleData.setAttribute("deploymentAttributes", deploymentAttributes);
//TODO this may definitely not be the best place for this!
for (ModuleBuilderExtension mbe : moduleBuilderExtensions) {
mbe.addGBeans(earContext, module, bundle, repository);
}
if (jettyWebApp.isSetSecurityRealmName()) {
webModuleData.setReferencePattern("applicationPolicyConfigurationManager", EARContext.JACC_MANAGER_NAME_KEY.get(earContext.getGeneralData()));
}
//not truly metadata complete until MBEs have run
if (!webApp.isMetadataComplete()) {
webApp.setMetadataComplete(true);
if (INITIAL_WEB_XML_SCHEMA_VERSION.get(webModule.getEarContext().getGeneralData()) >= 2.5f) {
String specDeploymentPlan = getSpecDDAsString(webModule);
module.setOriginalSpecDD(specDeploymentPlan);
earContext.addFile(new URI("./WEB-INF/web.xml"), specDeploymentPlan);
}