Skip to content

Commit

Permalink
Merge pull request #5238 from eclipse-ee4j/mojarra_issue_5232
Browse files Browse the repository at this point in the history
Mojarra fails to initialize when BDA is empty according to Weld
  • Loading branch information
arjantijms authored Sep 7, 2023
2 parents d216c10 + d324508 commit a1f0134
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void contextInitialized(ServletContextEvent servletContextEvent) {
}

InitFacesContext initFacesContext = new InitFacesContext(servletContext);
Util.getCdiBeanManager(initFacesContext); // #5232 Fail fast when CDI is really not available.

LOGGER.log(FINE, () -> format("ConfigureListener.contextInitialized({0})", servletContext.getContextPath()));

Expand Down
15 changes: 15 additions & 0 deletions impl/src/main/java/com/sun/faces/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static java.util.Collections.emptyList;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.SEVERE;
import static java.util.logging.Level.WARNING;

import java.beans.FeatureDescriptor;
import java.io.IOException;
Expand Down Expand Up @@ -100,6 +101,7 @@
import jakarta.faces.event.AbortProcessingException;
import jakarta.faces.render.ResponseStateManager;
import jakarta.faces.webapp.FacesServlet;
import jakarta.servlet.ServletContainerInitializer;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletRegistration;
import jakarta.servlet.http.HttpServletMapping;
Expand Down Expand Up @@ -1474,6 +1476,19 @@ public static BeanManager getCdiBeanManager(FacesContext facesContext) {
if (result == null && facesContext != null) {
Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();
result = (BeanManager) applicationMap.get("org.jboss.weld.environment.servlet.jakarta.enterprise.inject.spi.BeanManager");

if (result == null && applicationMap.get("org.jboss.weld.environment.servlet.enhancedListenerUsed") == Boolean.TRUE) {
LOGGER.log(WARNING, "Weld skipped initialization - forcing it to reinitialize");
try {
ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
servletContext.setInitParameter("org.jboss.weld.environment.servlet.archive.isolation", "false");
ServletContainerInitializer weld = (ServletContainerInitializer) Class.forName("org.jboss.weld.environment.servlet.EnhancedListener").getConstructor().newInstance();
weld.onStartup(null, servletContext);
result = (BeanManager) applicationMap.get("org.jboss.weld.environment.servlet.jakarta.enterprise.inject.spi.BeanManager");
} catch (Exception | LinkageError e) {
LOGGER.log(WARNING, "Reinitializing Weld failed - giving up, please make sure your project contains at least one bean class with a bean defining annotation and retry", e);
}
}
}

if (result != null && facesContext != null) {
Expand Down

0 comments on commit a1f0134

Please sign in to comment.