3030import org .springframework .web .servlet .mvc .method .condition .ConsumesRequestCondition ;
3131import org .springframework .web .servlet .mvc .method .condition .HeadersRequestCondition ;
3232import org .springframework .web .servlet .mvc .method .condition .ParamsRequestCondition ;
33+ import org .springframework .web .servlet .mvc .method .condition .ProducesRequestCondition ;
3334import org .springframework .web .servlet .mvc .method .condition .RequestConditionFactory ;
3435import org .springframework .web .servlet .mvc .method .condition .RequestMethodsRequestCondition ;
3536
@@ -57,6 +58,8 @@ public final class RequestMappingInfo {
5758
5859 private final ConsumesRequestCondition consumesCondition ;
5960
61+ private final ProducesRequestCondition producesCondition ;
62+
6063 private int hash ;
6164
6265 /**
@@ -65,7 +68,7 @@ public final class RequestMappingInfo {
6568 * <p>Package protected for testing purposes.
6669 */
6770 RequestMappingInfo (Collection <String > patterns , RequestMethod [] methods ) {
68- this (patterns , RequestConditionFactory .parseMethods (methods ), null , null , null );
71+ this (patterns , RequestConditionFactory .parseMethods (methods ), null , null , null , null );
6972 }
7073
7174 /**
@@ -75,12 +78,14 @@ public RequestMappingInfo(Collection<String> patterns,
7578 RequestMethodsRequestCondition methodsCondition ,
7679 ParamsRequestCondition paramsCondition ,
7780 HeadersRequestCondition headersCondition ,
78- ConsumesRequestCondition consumesCondition ) {
81+ ConsumesRequestCondition consumesCondition ,
82+ ProducesRequestCondition producesCondition ) {
7983 this .patterns = asUnmodifiableSet (prependLeadingSlash (patterns ));
8084 this .methodsCondition = methodsCondition != null ? methodsCondition : new RequestMethodsRequestCondition ();
8185 this .paramsCondition = paramsCondition != null ? paramsCondition : new ParamsRequestCondition ();
8286 this .headersCondition = headersCondition != null ? headersCondition : new HeadersRequestCondition ();
8387 this .consumesCondition = consumesCondition != null ? consumesCondition : new ConsumesRequestCondition ();
88+ this .producesCondition = producesCondition != null ? producesCondition : new ProducesRequestCondition ();
8489 }
8590
8691 private static Set <String > prependLeadingSlash (Collection <String > patterns ) {
@@ -106,40 +111,47 @@ private static <T> Set<T> asUnmodifiableSet(Collection<T> collection) {
106111 }
107112
108113 /**
109- * Returns the patterns of this request key .
114+ * Returns the patterns of this request mapping info .
110115 */
111116 public Set <String > getPatterns () {
112117 return patterns ;
113118 }
114119
115120 /**
116- * Returns the request method conditions of this request key .
121+ * Returns the request method conditions of this request mapping info .
117122 */
118123 public RequestMethodsRequestCondition getMethods () {
119124 return methodsCondition ;
120125 }
121126
122127 /**
123- * Returns the request parameters conditions of this request key .
128+ * Returns the request parameters conditions of this request mapping info .
124129 */
125130 public ParamsRequestCondition getParams () {
126131 return paramsCondition ;
127132 }
128133
129134 /**
130- * Returns the request headers conditions of this request key .
135+ * Returns the request headers conditions of this request mapping info .
131136 */
132137 public HeadersRequestCondition getHeaders () {
133138 return headersCondition ;
134139 }
135140
136141 /**
137- * Returns the request consumes conditions of this request key .
142+ * Returns the request consumes conditions of this request mapping info .
138143 */
139144 public ConsumesRequestCondition getConsumes () {
140145 return consumesCondition ;
141146 }
142147
148+ /**
149+ * Returns the request produces conditions of this request mapping info.
150+ */
151+ public ProducesRequestCondition getProduces () {
152+ return producesCondition ;
153+ }
154+
143155 /**
144156 * Combines this {@code RequestMappingInfo} with another as follows:
145157 * <ul>
@@ -156,16 +168,17 @@ public ConsumesRequestCondition getConsumes() {
156168 * </ul>
157169 * @param methodKey the key to combine with
158170 * @param pathMatcher to {@linkplain PathMatcher#combine(String, String) combine} the patterns
159- * @return a new request key containing conditions from both keys
171+ * @return a new request mapping info containing conditions from both keys
160172 */
161173 public RequestMappingInfo combine (RequestMappingInfo methodKey , PathMatcher pathMatcher ) {
162174 Set <String > patterns = combinePatterns (this .patterns , methodKey .patterns , pathMatcher );
163175 RequestMethodsRequestCondition methods = this .methodsCondition .combine (methodKey .methodsCondition );
164176 ParamsRequestCondition params = this .paramsCondition .combine (methodKey .paramsCondition );
165177 HeadersRequestCondition headers = this .headersCondition .combine (methodKey .headersCondition );
166178 ConsumesRequestCondition consumes = this .consumesCondition .combine (methodKey .consumesCondition );
179+ ProducesRequestCondition produces = this .producesCondition .combine (methodKey .producesCondition );
167180
168- return new RequestMappingInfo (patterns , methods , params , headers , consumes );
181+ return new RequestMappingInfo (patterns , methods , params , headers , consumes , produces );
169182 }
170183
171184 private static Set <String > combinePatterns (Collection <String > typePatterns ,
@@ -203,23 +216,24 @@ else if (!methodPatterns.isEmpty()) {
203216 * @param lookupPath mapping lookup path within the current servlet mapping if applicable
204217 * @param request the current request
205218 * @param pathMatcher to check for matching patterns
206- * @return a new request key that contains all matching attributes, or {@code null} if not all conditions match
219+ * @return a new request mapping info that contains all matching attributes, or {@code null} if not all conditions match
207220 */
208221 public RequestMappingInfo getMatchingRequestMapping (String lookupPath , HttpServletRequest request , PathMatcher pathMatcher ) {
209222 RequestMethodsRequestCondition matchingMethodCondition = methodsCondition .getMatchingCondition (request );
210223 ParamsRequestCondition matchingParamsCondition = paramsCondition .getMatchingCondition (request );
211224 HeadersRequestCondition matchingHeadersCondition = headersCondition .getMatchingCondition (request );
212225 ConsumesRequestCondition matchingConsumesCondition = consumesCondition .getMatchingCondition (request );
226+ ProducesRequestCondition matchingProducesCondition = producesCondition .getMatchingCondition (request );
213227
214228 if (matchingMethodCondition == null || matchingParamsCondition == null || matchingHeadersCondition == null ||
215- matchingConsumesCondition == null ) {
229+ matchingConsumesCondition == null || matchingProducesCondition == null ) {
216230 return null ;
217231 }
218232 else {
219233 List <String > matchingPatterns = getMatchingPatterns (lookupPath , pathMatcher );
220234 if (!matchingPatterns .isEmpty ()) {
221235 return new RequestMappingInfo (matchingPatterns , matchingMethodCondition , matchingParamsCondition ,
222- matchingHeadersCondition , matchingConsumesCondition );
236+ matchingHeadersCondition , matchingConsumesCondition , matchingProducesCondition );
223237 }
224238 else {
225239 return null ;
@@ -271,7 +285,8 @@ public boolean equals(Object obj) {
271285 this .methodsCondition .equals (other .methodsCondition ) &&
272286 this .paramsCondition .equals (other .paramsCondition ) &&
273287 this .headersCondition .equals (other .headersCondition ) &&
274- this .consumesCondition .equals (other .consumesCondition ));
288+ this .consumesCondition .equals (other .consumesCondition ) &&
289+ this .producesCondition .equals (other .producesCondition ));
275290 }
276291 return false ;
277292 }
@@ -285,6 +300,7 @@ public int hashCode() {
285300 result = 31 * result + paramsCondition .hashCode ();
286301 result = 31 * result + headersCondition .hashCode ();
287302 result = 31 * result + consumesCondition .hashCode ();
303+ result = 31 * result + producesCondition .hashCode ();
288304 hash = result ;
289305 }
290306 return result ;
@@ -298,6 +314,7 @@ public String toString() {
298314 builder .append (",params=" ).append (paramsCondition );
299315 builder .append (",headers=" ).append (headersCondition );
300316 builder .append (",consumes=" ).append (consumesCondition );
317+ builder .append (",produces=" ).append (producesCondition );
301318 builder .append ('}' );
302319 return builder .toString ();
303320 }
0 commit comments