From 29361833675dad5416bd184cb0003d063ce58e27 Mon Sep 17 00:00:00 2001 From: Manfred Riem Date: Mon, 6 Jan 2025 16:40:33 -0600 Subject: [PATCH] Fixes #4466 - Add logging to HttpWebApplicationServerRequestMapper for debugging purposes (#4480) --- external/webprofile-tck/pom.xml | 28 ----------- ...HttpWebApplicationServerRequestMapper.java | 49 ++++++++++++++++--- 2 files changed, 43 insertions(+), 34 deletions(-) delete mode 100644 external/webprofile-tck/pom.xml diff --git a/external/webprofile-tck/pom.xml b/external/webprofile-tck/pom.xml deleted file mode 100644 index 5f60e7163..000000000 --- a/external/webprofile-tck/pom.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - 4.0.0 - - cloud.piranha.external - project - 25.1.0-SNAPSHOT - - cloud.piranha.external.webprofiletck - project - pom - Piranha - External - Web Profile TCK - Project - - 2.0.2 - 4.0.13 - - - atinject - cdi - jsonb - jsonp - - diff --git a/http/webapp/src/main/java/cloud/piranha/http/webapp/HttpWebApplicationServerRequestMapper.java b/http/webapp/src/main/java/cloud/piranha/http/webapp/HttpWebApplicationServerRequestMapper.java index 559aa3279..498c63d0d 100644 --- a/http/webapp/src/main/java/cloud/piranha/http/webapp/HttpWebApplicationServerRequestMapper.java +++ b/http/webapp/src/main/java/cloud/piranha/http/webapp/HttpWebApplicationServerRequestMapper.java @@ -27,25 +27,39 @@ */ package cloud.piranha.http.webapp; +import cloud.piranha.core.api.WebApplication; +import cloud.piranha.core.api.WebApplicationServerRequestMapper; +import java.lang.System.Logger; +import static java.lang.System.Logger.Level.TRACE; import java.util.Enumeration; import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import cloud.piranha.core.api.WebApplication; -import cloud.piranha.core.api.WebApplicationServerRequestMapper; - /** - * The default WebApplicationServerRequestMapper. + * The HTTP WebApplicationServerRequestMapper. * * @author Manfred Riem (mriem@manorrock.com) */ public class HttpWebApplicationServerRequestMapper implements WebApplicationServerRequestMapper { /** - * Stores the mappings. + * Stores the logger. */ - private final ConcurrentHashMap mappings = new ConcurrentHashMap<>(); + private static final Logger LOGGER + = System.getLogger(HttpWebApplicationServerRequestMapper.class.getName()); + + /** + * Stores the web application mappings. + */ + private final ConcurrentHashMap mappings; + + /** + * Constructor. + */ + public HttpWebApplicationServerRequestMapper() { + this.mappings = new ConcurrentHashMap<>(); + } /** * Add a mapping. @@ -62,6 +76,9 @@ public Set addMapping(WebApplication webApplication, String... urlPatter if (this.mappings.containsKey(urlPattern)) { result.add(urlPattern); } else { + if (LOGGER.isLoggable(TRACE)) { + LOGGER.log(TRACE, "Adding url pattern: %s", urlPattern); + } this.mappings.put(urlPattern, webApplication); } } @@ -77,11 +94,21 @@ public Set addMapping(WebApplication webApplication, String... urlPatter */ @Override public WebApplication findMapping(String path) { + if (LOGGER.isLoggable(TRACE)) { + LOGGER.log(TRACE, "Finding web application for: %s", path); + } WebApplication result = null; String mapping = findPrefixMatch(path); if (mapping != null) { result = this.mappings.get(mapping); } + if (LOGGER.isLoggable(TRACE)) { + if (result != null) { + LOGGER.log(TRACE, "Found web application at: %s", result.getContextPath()); + } else { + LOGGER.log(TRACE, "Unable to find web application for: %s", path); + } + } return result; } @@ -92,6 +119,9 @@ public WebApplication findMapping(String path) { * @return the mapping, or null if not found. */ private String findPrefixMatch(String path) { + if (LOGGER.isLoggable(TRACE)) { + LOGGER.log(TRACE, "Find prefix for: %s", path); + } String result = null; String found; @@ -104,6 +134,13 @@ private String findPrefixMatch(String path) { } } + if (LOGGER.isLoggable(TRACE)) { + if (result != null) { + LOGGER.log(TRACE, "Found prefix: %s", result); + } else { + LOGGER.log(TRACE, "Unable to find prefix for: %s", path); + } + } return result; }