Skip to content

Commit 2936183

Browse files
authored
Fixes piranhacloud#4466 - Add logging to HttpWebApplicationServerRequestMapper for debugging purposes (piranhacloud#4480)
1 parent d6345b6 commit 2936183

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

Diff for: external/webprofile-tck/pom.xml

-28
This file was deleted.

Diff for: http/webapp/src/main/java/cloud/piranha/http/webapp/HttpWebApplicationServerRequestMapper.java

+43-6
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,39 @@
2727
*/
2828
package cloud.piranha.http.webapp;
2929

30+
import cloud.piranha.core.api.WebApplication;
31+
import cloud.piranha.core.api.WebApplicationServerRequestMapper;
32+
import java.lang.System.Logger;
33+
import static java.lang.System.Logger.Level.TRACE;
3034
import java.util.Enumeration;
3135
import java.util.HashSet;
3236
import java.util.Set;
3337
import java.util.concurrent.ConcurrentHashMap;
3438

35-
import cloud.piranha.core.api.WebApplication;
36-
import cloud.piranha.core.api.WebApplicationServerRequestMapper;
37-
3839
/**
39-
* The default WebApplicationServerRequestMapper.
40+
* The HTTP WebApplicationServerRequestMapper.
4041
*
4142
* @author Manfred Riem ([email protected])
4243
*/
4344
public class HttpWebApplicationServerRequestMapper implements WebApplicationServerRequestMapper {
4445

4546
/**
46-
* Stores the mappings.
47+
* Stores the logger.
4748
*/
48-
private final ConcurrentHashMap<String, WebApplication> mappings = new ConcurrentHashMap<>();
49+
private static final Logger LOGGER
50+
= System.getLogger(HttpWebApplicationServerRequestMapper.class.getName());
51+
52+
/**
53+
* Stores the web application mappings.
54+
*/
55+
private final ConcurrentHashMap<String, WebApplication> mappings;
56+
57+
/**
58+
* Constructor.
59+
*/
60+
public HttpWebApplicationServerRequestMapper() {
61+
this.mappings = new ConcurrentHashMap<>();
62+
}
4963

5064
/**
5165
* Add a mapping.
@@ -62,6 +76,9 @@ public Set<String> addMapping(WebApplication webApplication, String... urlPatter
6276
if (this.mappings.containsKey(urlPattern)) {
6377
result.add(urlPattern);
6478
} else {
79+
if (LOGGER.isLoggable(TRACE)) {
80+
LOGGER.log(TRACE, "Adding url pattern: %s", urlPattern);
81+
}
6582
this.mappings.put(urlPattern, webApplication);
6683
}
6784
}
@@ -77,11 +94,21 @@ public Set<String> addMapping(WebApplication webApplication, String... urlPatter
7794
*/
7895
@Override
7996
public WebApplication findMapping(String path) {
97+
if (LOGGER.isLoggable(TRACE)) {
98+
LOGGER.log(TRACE, "Finding web application for: %s", path);
99+
}
80100
WebApplication result = null;
81101
String mapping = findPrefixMatch(path);
82102
if (mapping != null) {
83103
result = this.mappings.get(mapping);
84104
}
105+
if (LOGGER.isLoggable(TRACE)) {
106+
if (result != null) {
107+
LOGGER.log(TRACE, "Found web application at: %s", result.getContextPath());
108+
} else {
109+
LOGGER.log(TRACE, "Unable to find web application for: %s", path);
110+
}
111+
}
85112
return result;
86113
}
87114

@@ -92,6 +119,9 @@ public WebApplication findMapping(String path) {
92119
* @return the mapping, or null if not found.
93120
*/
94121
private String findPrefixMatch(String path) {
122+
if (LOGGER.isLoggable(TRACE)) {
123+
LOGGER.log(TRACE, "Find prefix for: %s", path);
124+
}
95125
String result = null;
96126
String found;
97127

@@ -104,6 +134,13 @@ private String findPrefixMatch(String path) {
104134
}
105135
}
106136

137+
if (LOGGER.isLoggable(TRACE)) {
138+
if (result != null) {
139+
LOGGER.log(TRACE, "Found prefix: %s", result);
140+
} else {
141+
LOGGER.log(TRACE, "Unable to find prefix for: %s", path);
142+
}
143+
}
107144
return result;
108145
}
109146

0 commit comments

Comments
 (0)