You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by me...@apache.org on 2023/02/27 12:40:40 UTC
[myfaces] branch main updated: MYFACES-4573: 4.0 Quarkus native exception registration (#536)
This is an automated email from the ASF dual-hosted git repository.
melloware pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/main by this push:
new bd78d331a MYFACES-4573: 4.0 Quarkus native exception registration (#536)
bd78d331a is described below
commit bd78d331a7ff9c89c5030cb1ac61aa785c59c32b
Author: Melloware <me...@gmail.com>
AuthorDate: Mon Feb 27 07:40:34 2023 -0500
MYFACES-4573: 4.0 Quarkus native exception registration (#536)
---
.../quarkus/deployment/MyFacesProcessor.java | 27 ++++++++++++++-
.../java/org/apache/myfaces/util/WebXmlParser.java | 39 ++++++++++++++--------
2 files changed, 51 insertions(+), 15 deletions(-)
diff --git a/extensions/quarkus/deployment/src/main/java/org/apache/myfaces/core/extensions/quarkus/deployment/MyFacesProcessor.java b/extensions/quarkus/deployment/src/main/java/org/apache/myfaces/core/extensions/quarkus/deployment/MyFacesProcessor.java
index 89c855e45..40876a132 100644
--- a/extensions/quarkus/deployment/src/main/java/org/apache/myfaces/core/extensions/quarkus/deployment/MyFacesProcessor.java
+++ b/extensions/quarkus/deployment/src/main/java/org/apache/myfaces/core/extensions/quarkus/deployment/MyFacesProcessor.java
@@ -22,7 +22,10 @@ import java.io.IOException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -99,6 +102,7 @@ import org.apache.myfaces.renderkit.ErrorPageWriter;
import org.apache.myfaces.spi.FactoryFinderProviderFactory;
import org.apache.myfaces.spi.impl.DefaultWebConfigProviderFactory;
import org.apache.myfaces.util.ExternalContextUtils;
+import org.apache.myfaces.util.WebXmlParser;
import org.apache.myfaces.util.lang.ClassUtils;
import org.apache.myfaces.view.ViewScopeProxyMap;
import org.apache.myfaces.view.facelets.compiler.SAXCompiler;
@@ -139,6 +143,7 @@ import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.quarkus.undertow.deployment.ListenerBuildItem;
@@ -471,7 +476,8 @@ class MyFacesProcessor
classNames.addAll(Arrays.asList(
"jakarta.faces.component._DeltaStateHelper",
"jakarta.faces.component._DeltaStateHelper$InternalMap",
- "jakarta.validation.groups.Default"));
+ "jakarta.validation.groups.Default",
+ "jakarta.validation.Validation"));
classes.addAll(Arrays.asList(ApplicationImplEventManager.class,
DefaultWebConfigProviderFactory.class,
@@ -547,6 +553,24 @@ class MyFacesProcessor
new ReflectiveClassBuildItem(true, false, classes.toArray(new Class[classes.size()])));
}
+ @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
+ void registerErrorPageClassesForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
+ CombinedIndexBuildItem combinedIndex)
+ {
+ final Set<String> classNames = new HashSet<>();
+ classNames.add(jakarta.faces.application.ViewExpiredException.class.getName());
+
+ Map<String, String> errorPages = WebXmlParser.getErrorPages(null);
+ for (String key : errorPages.keySet())
+ {
+ if (key != null)
+ {
+ classNames.add(key);
+ }
+ }
+
+ reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, classNames.toArray(new String[0])));
+ }
@BuildStep
@Record(ExecutionTime.STATIC_INIT)
@@ -575,6 +599,7 @@ class MyFacesProcessor
"org/apache/myfaces/resource/default.dtd",
"org/apache/myfaces/resource/datatypes.dtd",
"META-INF/web-fragment.xml",
+ "META-INF/web.xml",
"META-INF/standard-faces-config.xml",
"META-INF/resources/org/apache/myfaces/windowId/windowhandler.html",
"org/apache/myfaces/resource/facelet-taglib_1_0.dtd",
diff --git a/impl/src/main/java/org/apache/myfaces/util/WebXmlParser.java b/impl/src/main/java/org/apache/myfaces/util/WebXmlParser.java
index 2e94d0046..cf6ed5351 100755
--- a/impl/src/main/java/org/apache/myfaces/util/WebXmlParser.java
+++ b/impl/src/main/java/org/apache/myfaces/util/WebXmlParser.java
@@ -67,24 +67,27 @@ public class WebXmlParser
/**
* Parses the web.xml and web-fragements.xml for error pages.
- * "null" as key represents the default error page. Otherwise the key is the exception class.
+ * "null" as key represents the default error page. Otherwise, the key is the exception class.
*
- * @param context
- * @return
+ * @param context the External Context or NULL if checking current classload
+ * @return a Map of Exception to XHTML pages
*/
public static Map<String, String> getErrorPages(ExternalContext context)
{
- // it would be nicer if the cache would probably directly in DefaultWebConfigProvider
- // as its currently the only caller of the method
- // however it's recreated every request, we have to refactor the SPI thing a bit probably.
- Map<String, String> cached = (Map<String, String>) context.getApplicationMap().get(KEY_ERROR_PAGES);
- if (cached != null)
+ if (context != null)
{
- return cached;
+ // it would be nicer if the cache would probably directly in DefaultWebConfigProvider
+ // as it's currently the only caller of the method
+ // however it's recreated every request, we have to refactor the SPI thing a bit, probably.
+ Map<String, String> cached = (Map<String, String>) context.getApplicationMap().get(KEY_ERROR_PAGES);
+ if (cached != null)
+ {
+ return cached;
+ }
}
Map<String, String> webXmlErrorPages = getWebXmlErrorPages(context);
- Map<String, String> webFragmentXmlsErrorPages = getWebFragmentXmlsErrorPages(context);
+ Map<String, String> webFragmentXmlsErrorPages = getWebFragmentXmlsErrorPages();
Map<String, String> errorPages = webXmlErrorPages;
if (errorPages == null)
@@ -102,7 +105,10 @@ public class WebXmlParser
}
}
- context.getApplicationMap().put(KEY_ERROR_PAGES, errorPages);
+ if (context != null)
+ {
+ context.getApplicationMap().put(KEY_ERROR_PAGES, errorPages);
+ }
return errorPages;
}
@@ -111,8 +117,13 @@ public class WebXmlParser
{
try
{
- Document webXml = toDocument(context.getResource("/WEB-INF/web.xml"));
-
+ Document webXml = null;
+ if (context != null)
+ {
+ // only try web app if external context is loaded
+ webXml = toDocument(context.getResource("/WEB-INF/web.xml"));
+ }
+
if (webXml == null)
{
// Quarkus
@@ -132,7 +143,7 @@ public class WebXmlParser
return null;
}
- private static Map<String, String> getWebFragmentXmlsErrorPages(ExternalContext context)
+ private static Map<String, String> getWebFragmentXmlsErrorPages()
{
Map<String, String> webFragmentXmlsErrorPages = null;