From 96c69cd96fed552b715d8db2b7e1a6fbce69c9a6 Mon Sep 17 00:00:00 2001 From: Manfred Riem Date: Thu, 9 Jan 2025 17:00:49 -0600 Subject: [PATCH] Fixes #4478 - Add logging to DefaultInvocationFinder for debugging purposes --- .../core/impl/DefaultInvocationFinder.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/core/impl/src/main/java/cloud/piranha/core/impl/DefaultInvocationFinder.java b/core/impl/src/main/java/cloud/piranha/core/impl/DefaultInvocationFinder.java index 57863fd76..68350e7db 100644 --- a/core/impl/src/main/java/cloud/piranha/core/impl/DefaultInvocationFinder.java +++ b/core/impl/src/main/java/cloud/piranha/core/impl/DefaultInvocationFinder.java @@ -48,6 +48,8 @@ import jakarta.servlet.FilterChain; import jakarta.servlet.Servlet; import jakarta.servlet.ServletException; +import java.lang.System.Logger; +import static java.lang.System.Logger.Level.TRACE; /** * The invocation finder tries to find a servlet invocation matching a request @@ -57,12 +59,16 @@ * Invocations returned by this finder take into account the various mappings, * filters, welcome files and the default servlet. * - * * @author Arjan Tijms - * */ public class DefaultInvocationFinder { + /** + * Stores the logger. + */ + private static final Logger LOGGER + = System.getLogger(DefaultInvocationFinder.class.getName()); + /** * Stores the web application. */ @@ -101,6 +107,12 @@ public DefaultServletInvocation findServletInvocationByPath(String servletPath, * @throws ServletException when a Servlet error occurs. */ public DefaultServletInvocation findServletInvocationByPath(DispatcherType dispatcherType, String servletPath, String pathInfo) throws IOException, ServletException { + if (LOGGER.isLoggable(TRACE)) { + LOGGER.log(TRACE, "Find servlet invocation by path"); + LOGGER.log(TRACE, "DispatcherType: {0}", dispatcherType.name()); + LOGGER.log(TRACE, "Servlet path: {0}", servletPath); + LOGGER.log(TRACE, "Path info: {0}", pathInfo); + } DefaultServletInvocation servletInvocation = getDirectServletInvocationByPath(servletPath, pathInfo); if (servletInvocation == null) { @@ -143,14 +155,14 @@ public DefaultServletInvocation addFilters(DispatcherType dispatcherType, Defaul return servletInvocation; } - List filterEnvironments = - findFilterEnvironments( - dispatcherType, - // Look at the servletInvocation if there is one, as a welcome file can be set - // that differs from the request path - servletInvocation == null ? servletPath : servletInvocation.getServletPath(), - servletInvocation == null ? pathInfo : servletInvocation.getPathInfo(), - servletInvocation == null ? null : servletInvocation.getServletName()); + List filterEnvironments + = findFilterEnvironments( + dispatcherType, + // Look at the servletInvocation if there is one, as a welcome file can be set + // that differs from the request path + servletInvocation == null ? servletPath : servletInvocation.getServletPath(), + servletInvocation == null ? pathInfo : servletInvocation.getPathInfo(), + servletInvocation == null ? null : servletInvocation.getServletName()); if (filterEnvironments != null) { if (servletInvocation == null) {