Skip to content

Commit

Permalink
Fixes #4466 - Add logging to HttpWebApplicationServerRequestMapper fo…
Browse files Browse the repository at this point in the history
…r debugging purposes (#4480)
  • Loading branch information
mnriem authored Jan 6, 2025
1 parent d6345b6 commit 2936183
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
28 changes: 0 additions & 28 deletions external/webprofile-tck/pom.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<String, WebApplication> mappings = new ConcurrentHashMap<>();
private static final Logger LOGGER
= System.getLogger(HttpWebApplicationServerRequestMapper.class.getName());

/**
* Stores the web application mappings.
*/
private final ConcurrentHashMap<String, WebApplication> mappings;

/**
* Constructor.
*/
public HttpWebApplicationServerRequestMapper() {
this.mappings = new ConcurrentHashMap<>();
}

/**
* Add a mapping.
Expand All @@ -62,6 +76,9 @@ public Set<String> 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);
}
}
Expand All @@ -77,11 +94,21 @@ public Set<String> 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;
}

Expand All @@ -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;

Expand All @@ -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;
}

Expand Down

0 comments on commit 2936183

Please sign in to comment.