Skip to content

Commit a747a23

Browse files
committed
Fix jakartaee#316 - clarify behaviour of getMatchValue()
Add more examples, remove unnecessary text and be explicit about removal of leading '/'.
1 parent 812ebd1 commit a747a23

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

api/src/main/java/jakarta/servlet/http/HttpServletMapping.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021 Oracle and/or its affiliates and others.
2+
* Copyright (c) 2017, 2023 Oracle and/or its affiliates and others.
33
* All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -71,23 +71,47 @@
7171
* <td>DEFAULT</td>
7272
* </tr>
7373
* <tr>
74+
* <td>"MyServlet/index.html"</td>
75+
* <td>""</td>
76+
* <td>/</td>
77+
* <td>DEFAULT</td>
78+
* </tr>
79+
* <tr>
7480
* <td>"/MyServlet"</td>
7581
* <td>MyServlet</td>
7682
* <td>/MyServlet</td>
7783
* <td>EXACT</td>
7884
* </tr>
7985
* <tr>
86+
* <td>"MyServlet/foo"</td>
87+
* <td>""</td>
88+
* <td>/</td>
89+
* <td>DEFAULT</td>
90+
* </tr>
91+
* <tr>
8092
* <td>"/foo.extension"</td>
8193
* <td>foo</td>
8294
* <td>*.extension</td>
8395
* <td>EXTENSION</td>
8496
* </tr>
8597
* <tr>
98+
* <td>"/bar/foo.extension"</td>
99+
* <td>bar/foo</td>
100+
* <td>*.extension</td>
101+
* <td>EXTENSION</td>
102+
* </tr>
103+
* <tr>
86104
* <td>"/path/foo"</td>
87105
* <td>foo</td>
88106
* <td>/path/*</td>
89107
* <td>PATH</td>
90108
* </tr>
109+
* <tr>
110+
* <td>"/path/foo/bar"</td>
111+
* <td>foo/bar</td>
112+
* <td>/path/*</td>
113+
* <td>PATH</td>
114+
* </tr>
91115
*
92116
* </table>
93117
*
@@ -98,12 +122,10 @@ public interface HttpServletMapping {
98122
/**
99123
* <p>
100124
* Return the portion of the URI path that caused this request to be matched. If the {@link #getMappingMatch} value is
101-
* {@code
102-
* CONTEXT_ROOT} or {@code DEFAULT}, this method must return the empty string. If the {@link #getMappingMatch} value is
103-
* {@code
104-
* EXACT}, this method must return the portion of the path that matched the servlet, omitting any leading slash. If the
105-
* {@link #getMappingMatch} value is {@code EXTENSION} or {@code PATH}, this method must return the value that matched
106-
* the '*'. See the class javadoc for examples.
125+
* {@code CONTEXT_ROOT} or {@code DEFAULT}, this method must return the empty string. If the {@link #getMappingMatch}
126+
* value is {@code EXACT}, this method must return the portion of the path that matched the servlet, omitting any
127+
* leading slash. If the {@link #getMappingMatch} value is {@code EXTENSION} or {@code PATH}, this method must return
128+
* the value that matched the '*' excluding any leading '/'. See the class javadoc for examples.
107129
* </p>
108130
*
109131
* @return the match.
@@ -112,11 +134,8 @@ public interface HttpServletMapping {
112134

113135
/**
114136
* <p>
115-
* Return the String representation for the {@code url-pattern} for this mapping. If the {@link #getMappingMatch} value
116-
* is {@code
117-
* CONTEXT_ROOT}, this method must return the empty string. If the {@link #getMappingMatch} value is {@code
118-
* EXTENSION}, this method must return the pattern, without any leading slash. Otherwise, this method returns the
119-
* pattern exactly as specified in the descriptor or Java configuration.
137+
* Return the String representation for the {@code url-pattern} for this mapping. This method returns the pattern
138+
* exactly as specified in the descriptor or Java configuration.
120139
* </p>
121140
*
122141
* @return the String representation for the {@code url-pattern} for this mapping.
@@ -135,7 +154,7 @@ public interface HttpServletMapping {
135154

136155
/**
137156
* <p>
138-
* Return the {@link MappingMatch} for this instance
157+
* Return the {@link MappingMatch} for this instance.
139158
* </p>
140159
*
141160
* @return the {@code MappingMatch} for this instance.

spec/src/main/asciidoc/servlet-spec-body.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8560,6 +8560,9 @@ link:https://github.com/eclipse-ee4j/servlet-api/issues/275[Issue 275]::
85608560
Containers may provide an option to send redirects using a location header with
85618561
a relative URL.
85628562

8563+
link:https://github.com/eclipse-ee4j/servlet-api/issues/316[Issue 316]::
8564+
Clarify the behaviour of `HttpServletMapping.getMatchValue()`.
8565+
85638566
link:https://github.com/eclipse-ee4j/servlet-api/issues/325[Issue 325]::
85648567
Clarify the behaviour of `getDateHeader()` and `getIntHeader()` when multiple
85658568
headers with the same name are present in the `HttpServletRequest`. The expected

0 commit comments

Comments
 (0)