diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java index b6259635f0b..fceeffbf7d9 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java @@ -270,7 +270,7 @@ public BeansXml getBeansXml() { if (beansXmlURLs.size() == 1) { result = weldBootstrap.parse(beansXmlURLs.get(0)); } else { - // This method attempts to performs a merge, but loses some + // This method attempts to perform a merge, but loses some // information (e.g., version, bean-discovery-mode) result = weldBootstrap.parse(beansXmlURLs); } diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/DeploymentImpl.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/DeploymentImpl.java index 7b2dda8df1e..b6ea7827b11 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/DeploymentImpl.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/DeploymentImpl.java @@ -199,8 +199,10 @@ List getRootBDAs() { return ejbRootBdas; } else if (rarRootBdas != null) { return rarRootBdas; - } else { + } else if (libJarRootBdas != null) { return libJarRootBdas; + } else { + return Collections.emptyList(); } } diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/WeldDeployer.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/WeldDeployer.java index dd147219f3a..a9d4c710078 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/WeldDeployer.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/WeldDeployer.java @@ -275,7 +275,7 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext ReadableArchive archive = context.getSource(); - getOrCreateWeldBootstrap(context, applicationInfo); + ensureWeldBootstrapCreated(context, applicationInfo); EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context); EjbServices ejbServices = null; @@ -468,28 +468,28 @@ public String getContextIdForArchive(BeanDeploymentArchive archive) { // ### Private methods - - private WeldBootstrap getOrCreateWeldBootstrap(DeploymentContext context, ApplicationInfo appInfo) { - // See if a WeldBootsrap has already been created - only want one per context. - WeldBootstrap bootstrap = context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); - List toShutdown = appInfo.getTransientAppMetaData(WELD_BOOTSTRAP, List.class); + private WeldBootstrap ensureWeldBootstrapCreated(DeploymentContext context, ApplicationInfo applicationInfo) { + @SuppressWarnings("unchecked") + List toShutdown = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, List.class); if (toShutdown == null) { toShutdown = new ArrayList<>(); - appInfo.addTransientAppMetaData(WELD_BOOTSTRAP, toShutdown); + applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP, toShutdown); } + // See if a WeldBootstrap has already been created - only want one per context. + WeldBootstrap bootstrap = context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); + if (bootstrap == null) { bootstrap = new WeldBootstrap(); - // Stash the WeldBootstrap instance, so we may access the WeldManager later.. + // Stash the WeldBootstrap instance, so we may access the WeldManager later... context.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap); toShutdown.add(bootstrap); // Making sure that if WeldBootstrap is added, shutdown is set to false, as it is/would not have // been called. - appInfo.addTransientAppMetaData(WELD_BOOTSTRAP_SHUTDOWN, "false"); + applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP_SHUTDOWN, "false"); } - return bootstrap; } @@ -515,23 +515,18 @@ private void processApplicationLoaded(ApplicationInfo applicationInfo) { try { invocationManager.preInvoke(componentInvocation); - for (RootBeanDeploymentArchive rootBDA : deploymentImpl.getRootBDAs()) { - DeploymentImpl filtered = deploymentImpl.filter(rootBDA); - WeldBootstrap bootstrap = filtered.context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); - bootstrap.startExtensions(postProcessExtensions(filtered.getExtensions(), - filtered.getBeanDeploymentArchives())); - bootstrap.startContainer(filtered.getContextId(), SERVLET, filtered); - - //This changes added to pass the following test - // CreateBeanAttributesTest#testBeanAttributesForSessionBean - if (!rootBDA.getBeanDeploymentArchives().isEmpty()) { - createProxyEJBs(rootBDA, bootstrap, componentInvocation, filtered); + // Modern, multiple WARs in an EAR scenario + if (deploymentImpl.ejbRootBdas == null || deploymentImpl.ejbRootBdas.isEmpty()) { + for (RootBeanDeploymentArchive rootBDA : deploymentImpl.getRootBDAs()) { + DeploymentImpl filtered = deploymentImpl.filter(rootBDA); + WeldBootstrap bootstrap = filtered.context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); + startWeldBootstrap(applicationInfo, rootBDA, bootstrap, filtered, componentInvocation); } - bootstrap.startInitialization(); - fireProcessInjectionTargetEvents(bootstrap, applicationInfo, filtered); - bootstrap.deployBeans(); - bootstrap.validateBeans(); - bootstrap.endInitialization(); + } else if (!deploymentImpl.getRootBDAs().isEmpty()) { + // Legacy EJB-Jar scenario, one Weld instance per EAR + RootBeanDeploymentArchive bda = deploymentImpl.getRootBDAs().get(0); + WeldBootstrap bootstrap = unifyBootstrap(bda, applicationInfo); + startWeldBootstrap(applicationInfo, bda, bootstrap, deploymentImpl, componentInvocation); } } catch (Throwable t) { doBootstrapShutdown(applicationInfo); @@ -554,6 +549,32 @@ private void processApplicationLoaded(ApplicationInfo applicationInfo) { } } + private WeldBootstrap unifyBootstrap(BeanDeploymentArchiveImpl rootArchive, ApplicationInfo applicationInfo) { + WeldBootstrap bootstrap = ensureWeldBootstrapCreated(rootArchive.context, applicationInfo); + rootArchive.getBeanDeploymentArchives().stream().map(BeanDeploymentArchiveImpl.class::cast) + .forEach(bda -> bda.weldBootstrap = bootstrap); + return bootstrap; + } + + private void startWeldBootstrap(ApplicationInfo applicationInfo, RootBeanDeploymentArchive rootBDA, + WeldBootstrap bootstrap, DeploymentImpl deploymentImpl, + ComponentInvocation componentInvocation) { + bootstrap.startExtensions(postProcessExtensions(deploymentImpl.getExtensions(), + deploymentImpl.getBeanDeploymentArchives())); + bootstrap.startContainer(deploymentImpl.getContextId(), SERVLET, deploymentImpl); + + //This changes added to pass the following test + // CreateBeanAttributesTest#testBeanAttributesForSessionBean + if (!rootBDA.getBeanDeploymentArchives().isEmpty()) { + createProxyEJBs(rootBDA, bootstrap, componentInvocation, deploymentImpl); + } + bootstrap.startInitialization(); + fireProcessInjectionTargetEvents(bootstrap, applicationInfo, deploymentImpl); + bootstrap.deployBeans(); + bootstrap.validateBeans(); + bootstrap.endInitialization(); + } + private static void createProxyEJBs(RootBeanDeploymentArchive warRootBDA, WeldBootstrap bootstrap, ComponentInvocation componentInvocation, DeploymentImpl deploymentImpl) { BeanManagerImpl beanManager = bootstrap.getManager(warRootBDA);