27
27
*/
28
28
package cloud .piranha .http .webapp ;
29
29
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 ;
30
34
import java .util .Enumeration ;
31
35
import java .util .HashSet ;
32
36
import java .util .Set ;
33
37
import java .util .concurrent .ConcurrentHashMap ;
34
38
35
- import cloud .piranha .core .api .WebApplication ;
36
- import cloud .piranha .core .api .WebApplicationServerRequestMapper ;
37
-
38
39
/**
39
- * The default WebApplicationServerRequestMapper.
40
+ * The HTTP WebApplicationServerRequestMapper.
40
41
*
41
42
* @author Manfred Riem ([email protected] )
42
43
*/
43
44
public class HttpWebApplicationServerRequestMapper implements WebApplicationServerRequestMapper {
44
45
45
46
/**
46
- * Stores the mappings .
47
+ * Stores the logger .
47
48
*/
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
+ }
49
63
50
64
/**
51
65
* Add a mapping.
@@ -62,6 +76,9 @@ public Set<String> addMapping(WebApplication webApplication, String... urlPatter
62
76
if (this .mappings .containsKey (urlPattern )) {
63
77
result .add (urlPattern );
64
78
} else {
79
+ if (LOGGER .isLoggable (TRACE )) {
80
+ LOGGER .log (TRACE , "Adding url pattern: %s" , urlPattern );
81
+ }
65
82
this .mappings .put (urlPattern , webApplication );
66
83
}
67
84
}
@@ -77,11 +94,21 @@ public Set<String> addMapping(WebApplication webApplication, String... urlPatter
77
94
*/
78
95
@ Override
79
96
public WebApplication findMapping (String path ) {
97
+ if (LOGGER .isLoggable (TRACE )) {
98
+ LOGGER .log (TRACE , "Finding web application for: %s" , path );
99
+ }
80
100
WebApplication result = null ;
81
101
String mapping = findPrefixMatch (path );
82
102
if (mapping != null ) {
83
103
result = this .mappings .get (mapping );
84
104
}
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
+ }
85
112
return result ;
86
113
}
87
114
@@ -92,6 +119,9 @@ public WebApplication findMapping(String path) {
92
119
* @return the mapping, or null if not found.
93
120
*/
94
121
private String findPrefixMatch (String path ) {
122
+ if (LOGGER .isLoggable (TRACE )) {
123
+ LOGGER .log (TRACE , "Find prefix for: %s" , path );
124
+ }
95
125
String result = null ;
96
126
String found ;
97
127
@@ -104,6 +134,13 @@ private String findPrefixMatch(String path) {
104
134
}
105
135
}
106
136
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
+ }
107
144
return result ;
108
145
}
109
146
0 commit comments