22
22
import java .util .LinkedHashSet ;
23
23
import java .util .List ;
24
24
import java .util .Set ;
25
-
26
25
import javax .servlet .http .HttpServletRequest ;
27
26
28
27
import org .springframework .util .PathMatcher ;
29
28
import org .springframework .util .StringUtils ;
30
29
import org .springframework .web .bind .annotation .RequestMethod ;
31
- import org .springframework .web .servlet .mvc .method .condition .RequestCondition ;
32
- import org .springframework .web .servlet .mvc .method .condition .RequestConditionFactory ;
30
+ import org .springframework .web .servlet .mvc .method .condition .ConsumesRequestCondition ;
31
+ import org .springframework .web .servlet .mvc .method .condition .HeadersRequestCondition ;
32
+ import org .springframework .web .servlet .mvc .method .condition .ParamsRequestCondition ;
33
33
34
34
/**
35
35
* Contains a set of conditions to match to a given request such as URL patterns, HTTP methods, request parameters
@@ -49,16 +49,16 @@ public final class RequestMappingInfo {
49
49
50
50
private final Set <RequestMethod > methods ;
51
51
52
- private final RequestCondition paramsCondition ;
52
+ private final ParamsRequestCondition paramsCondition ;
53
53
54
- private final RequestCondition headersCondition ;
54
+ private final HeadersRequestCondition headersCondition ;
55
55
56
- private final RequestCondition consumesCondition ;
56
+ private final ConsumesRequestCondition consumesCondition ;
57
57
58
58
private int hash ;
59
59
60
60
/**
61
- * Creates a new {@code RequestKey } instance with the given URL patterns and HTTP methods.
61
+ * Creates a new {@code RequestMappingInfo } instance with the given URL patterns and HTTP methods.
62
62
*
63
63
* <p>Package protected for testing purposes.
64
64
*/
@@ -67,18 +67,18 @@ public final class RequestMappingInfo {
67
67
}
68
68
69
69
/**
70
- * Creates a new {@code RequestKey } instance with a full set of conditions.
70
+ * Creates a new {@code RequestMappingInfo } instance with a full set of conditions.
71
71
*/
72
72
public RequestMappingInfo (Collection <String > patterns ,
73
73
Collection <RequestMethod > methods ,
74
- RequestCondition paramsCondition ,
75
- RequestCondition headersCondition ,
76
- RequestCondition consumesCondition ) {
74
+ ParamsRequestCondition paramsCondition ,
75
+ HeadersRequestCondition headersCondition ,
76
+ ConsumesRequestCondition consumesCondition ) {
77
77
this .patterns = asUnmodifiableSet (prependLeadingSlash (patterns ));
78
78
this .methods = asUnmodifiableSet (methods );
79
- this .paramsCondition = paramsCondition != null ? paramsCondition : RequestConditionFactory . trueCondition ();
80
- this .headersCondition = headersCondition != null ? headersCondition : RequestConditionFactory . trueCondition ();
81
- this .consumesCondition = consumesCondition != null ? consumesCondition : RequestConditionFactory . trueCondition ();
79
+ this .paramsCondition = paramsCondition != null ? paramsCondition : new ParamsRequestCondition ();
80
+ this .headersCondition = headersCondition != null ? headersCondition : new HeadersRequestCondition ();
81
+ this .consumesCondition = consumesCondition != null ? consumesCondition : new ConsumesRequestCondition ();
82
82
}
83
83
84
84
private static Set <String > prependLeadingSlash (Collection <String > patterns ) {
@@ -118,21 +118,28 @@ public Set<RequestMethod> getMethods() {
118
118
}
119
119
120
120
/**
121
- * Returns the request parameters of this request key.
121
+ * Returns the request parameters conditions of this request key.
122
122
*/
123
- public RequestCondition getParams () {
123
+ public ParamsRequestCondition getParams () {
124
124
return paramsCondition ;
125
125
}
126
126
127
127
/**
128
- * Returns the request headers of this request key.
128
+ * Returns the request headers conditions of this request key.
129
129
*/
130
- public RequestCondition getHeaders () {
130
+ public HeadersRequestCondition getHeaders () {
131
131
return headersCondition ;
132
132
}
133
133
134
134
/**
135
- * Combines this {@code RequestKey} with another as follows:
135
+ * Returns the request consumes conditions of this request key.
136
+ */
137
+ public ConsumesRequestCondition getConsumes () {
138
+ return consumesCondition ;
139
+ }
140
+
141
+ /**
142
+ * Combines this {@code RequestMappingInfo} with another as follows:
136
143
* <ul>
137
144
* <li>URL patterns:
138
145
* <ul>
@@ -141,9 +148,9 @@ public RequestCondition getHeaders() {
141
148
* <li>If neither contains patterns use ""
142
149
* </ul>
143
150
* <li>HTTP methods are combined as union of all HTTP methods listed in both keys.
144
- * <li>Request parameter are combined into a logical AND .
145
- * <li>Request header are combined into a logical AND .
146
- * <li>Consumes .. TODO
151
+ * <li>Request parameters are combined as per {@link ParamsRequestCondition#combine(ParamsRequestCondition)} .
152
+ * <li>Request headers are combined as per {@link HeadersRequestCondition#combine(HeadersRequestCondition)} .
153
+ * <li>Consumes are combined as per {@link ConsumesRequestCondition#combine(ConsumesRequestCondition)}.
147
154
* </ul>
148
155
* @param methodKey the key to combine with
149
156
* @param pathMatcher to {@linkplain PathMatcher#combine(String, String) combine} the patterns
@@ -152,9 +159,9 @@ public RequestCondition getHeaders() {
152
159
public RequestMappingInfo combine (RequestMappingInfo methodKey , PathMatcher pathMatcher ) {
153
160
Set <String > patterns = combinePatterns (this .patterns , methodKey .patterns , pathMatcher );
154
161
Set <RequestMethod > methods = union (this .methods , methodKey .methods );
155
- RequestCondition params = RequestConditionFactory . and ( this .paramsCondition , methodKey .paramsCondition );
156
- RequestCondition headers = RequestConditionFactory . and ( this .headersCondition , methodKey .headersCondition );
157
- RequestCondition consumes = RequestConditionFactory . mostSpecific (methodKey . consumesCondition , this .consumesCondition );
162
+ ParamsRequestCondition params = this .paramsCondition . combine ( methodKey .paramsCondition );
163
+ HeadersRequestCondition headers = this .headersCondition . combine ( methodKey .headersCondition );
164
+ ConsumesRequestCondition consumes = this . consumesCondition . combine (methodKey .consumesCondition );
158
165
159
166
return new RequestMappingInfo (patterns , methods , params , headers , consumes );
160
167
}
@@ -189,7 +196,7 @@ private static <T> Set<T> union(Collection<T> s1, Collection<T> s2) {
189
196
}
190
197
191
198
/**
192
- * Returns a new {@code RequestKey } that contains all conditions of this key that are relevant to the request.
199
+ * Returns a new {@code RequestMappingInfo } that contains all conditions of this key that are relevant to the request.
193
200
* <ul>
194
201
* <li>The list of URL path patterns is trimmed to contain the patterns that match the URL with matching patterns
195
202
* sorted via {@link PathMatcher#getPatternComparator(String)}.
@@ -203,16 +210,20 @@ private static <T> Set<T> union(Collection<T> s1, Collection<T> s2) {
203
210
* @return a new request key that contains all matching attributes, or {@code null} if not all conditions match
204
211
*/
205
212
public RequestMappingInfo getMatchingRequestMapping (String lookupPath , HttpServletRequest request , PathMatcher pathMatcher ) {
206
- if (!checkMethod (request ) || !paramsCondition .match (request ) || !headersCondition .match (request ) ||
207
- !consumesCondition .match (request )) {
213
+ ParamsRequestCondition matchingParamsCondition = paramsCondition .getMatchingCondition (request );
214
+ HeadersRequestCondition matchingHeadersCondition = headersCondition .getMatchingCondition (request );
215
+ ConsumesRequestCondition matchingConsumesCondition = consumesCondition .getMatchingCondition (request );
216
+
217
+ if (!checkMethod (request ) || matchingParamsCondition == null || matchingHeadersCondition == null ||
218
+ matchingConsumesCondition == null ) {
208
219
return null ;
209
220
}
210
221
else {
211
222
List <String > matchingPatterns = getMatchingPatterns (lookupPath , request , pathMatcher );
212
223
if (!matchingPatterns .isEmpty ()) {
213
224
Set <RequestMethod > matchingMethods = getMatchingMethod (request );
214
- return new RequestMappingInfo (matchingPatterns , matchingMethods , this . paramsCondition , this . headersCondition ,
215
- this . consumesCondition );
225
+ return new RequestMappingInfo (matchingPatterns , matchingMethods , matchingParamsCondition ,
226
+ matchingHeadersCondition , matchingConsumesCondition );
216
227
}
217
228
else {
218
229
return null ;
@@ -277,7 +288,8 @@ public boolean equals(Object obj) {
277
288
RequestMappingInfo other = (RequestMappingInfo ) obj ;
278
289
return (this .patterns .equals (other .patterns ) && this .methods .equals (other .methods ) &&
279
290
this .paramsCondition .equals (other .paramsCondition ) &&
280
- this .headersCondition .equals (other .headersCondition ));
291
+ this .headersCondition .equals (other .headersCondition ) &&
292
+ this .consumesCondition .equals (other .consumesCondition ));
281
293
}
282
294
return false ;
283
295
}
@@ -290,6 +302,7 @@ public int hashCode() {
290
302
result = 31 * result + methods .hashCode ();
291
303
result = 31 * result + paramsCondition .hashCode ();
292
304
result = 31 * result + headersCondition .hashCode ();
305
+ result = 31 * result + consumesCondition .hashCode ();
293
306
hash = result ;
294
307
}
295
308
return result ;
0 commit comments