Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FacesServletFactory #5424

Merged
merged 1 commit into from Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,17 +1,22 @@
package com.sun.faces.config.configpopulator;

import jakarta.faces.application.ApplicationConfigurationPopulator;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import jakarta.faces.application.ApplicationConfigurationPopulator;

public final class MojarraRuntimePopulator extends ApplicationConfigurationPopulator {
@Override
public void populateApplicationConfiguration(Document toPopulate) {
String ns = toPopulate.getDocumentElement().getNamespaceURI();
Element faces_configElement = toPopulate.getDocumentElement();
{
Element factoryElement = toPopulate.createElementNS(ns, "factory");
{
Element faces_servlet_factoryElement = toPopulate.createElementNS(ns, "faces-servlet-factory");
faces_servlet_factoryElement.appendChild(toPopulate.createTextNode("com.sun.faces.webapp.FacesServletFactoryImpl"));
factoryElement.appendChild(faces_servlet_factoryElement);
}
{
Element application_factoryElement = toPopulate.createElementNS(ns, "application-factory");
application_factoryElement.appendChild(toPopulate.createTextNode("com.sun.faces.application.ApplicationFactoryImpl"));
Expand Down
Expand Up @@ -28,6 +28,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import jakarta.faces.FactoryFinder;
import jakarta.faces.context.FacesContext;
import jakarta.servlet.ServletContext;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -39,10 +43,6 @@
import com.sun.faces.context.InjectionFacesContextFactory;
import com.sun.faces.util.FacesLogger;

import jakarta.faces.FactoryFinder;
import jakarta.faces.context.FacesContext;
import jakarta.servlet.ServletContext;

/**
* <p>
* This <code>ConfigProcessor</code> handles all elements defined under <code>/faces-config/factory</code>.
Expand All @@ -57,6 +57,11 @@ public class FactoryConfigProcessor extends AbstractConfigProcessor {
*/
private static final String FACTORY = "factory";

/**
* <code>faces-config/factory/faces-servlet-factory</code>
*/
private static final String FACES_SERVLET_FACTORY = "faces-servlet-factory";

/**
* <code>/faces-config/factory/application-factory</code>
*/
Expand Down Expand Up @@ -135,7 +140,7 @@ public class FactoryConfigProcessor extends AbstractConfigProcessor {
/**
* <code>Array of Factory names for post-configuration validation.</code>
*/
private final List<String> factoryNames = asList(FactoryFinder.APPLICATION_FACTORY, FactoryFinder.CLIENT_WINDOW_FACTORY,
private final List<String> factoryNames = asList(FactoryFinder.FACES_SERVLET_FACTORY, FactoryFinder.APPLICATION_FACTORY, FactoryFinder.CLIENT_WINDOW_FACTORY,
FactoryFinder.EXCEPTION_HANDLER_FACTORY, FactoryFinder.EXTERNAL_CONTEXT_FACTORY, FactoryFinder.FACES_CONTEXT_FACTORY, FactoryFinder.FLASH_FACTORY,
FactoryFinder.LIFECYCLE_FACTORY, FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY, FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
FactoryFinder.RENDER_KIT_FACTORY, FactoryFinder.VISIT_CONTEXT_FACTORY, FactoryFinder.FACELET_CACHE_FACTORY,
Expand Down Expand Up @@ -204,8 +209,11 @@ private void processFactories(NodeList factories, String namespace, AtomicIntege
for (int c = 0, csize = children.getLength(); c < csize; c++) {
Node childNode = children.item(c);
switch (childNode.getLocalName()) {
case FACES_SERVLET_FACTORY:
setFactory(FactoryFinder.FACES_SERVLET_FACTORY, getNodeText(childNode));
break;
case APPLICATION_FACTORY:
int cnt = appCount.incrementAndGet();
appCount.incrementAndGet();
setFactory(FactoryFinder.APPLICATION_FACTORY, getNodeText(childNode));
break;
case EXCEPTION_HANDLER_FACTORY:
Expand Down
Expand Up @@ -16,10 +16,13 @@
*/
package com.sun.faces.webapp;

import java.util.HashMap;

import jakarta.faces.FacesException;
import jakarta.faces.webapp.FacesServletFactory;
import jakarta.servlet.Servlet;
import jakarta.servlet.ServletConfig;
import java.util.HashMap;
import jakarta.servlet.ServletException;

/**
* The implementation of the FacesServletFactory.
Expand All @@ -37,8 +40,13 @@ public class FacesServletFactoryImpl extends FacesServletFactory {
public Servlet getFacesServlet(ServletConfig config) {
Servlet servlet = servlets.get(config);
if (servlet == null) {
servlets.put(config, servlet);
servlet = new FacesServletImpl();
try {
servlet.init(config);
} catch (ServletException e) {
throw new FacesException(e);
}
servlets.put(config, servlet);
}
return servlet;
}
Expand Down