Class ProducesRequestCondition
java.lang.Object
org.springframework.web.reactive.result.condition.AbstractRequestCondition<ProducesRequestCondition>
org.springframework.web.reactive.result.condition.ProducesRequestCondition
- All Implemented Interfaces:
- RequestCondition<ProducesRequestCondition>
public final class ProducesRequestCondition
extends AbstractRequestCondition<ProducesRequestCondition>
A logical disjunction (' || ') request condition to match a request's 'Accept' header
 to a list of media type expressions. Two kinds of media type expressions are
 supported, which are described in 
RequestMapping.produces() and
 RequestMapping.headers() where the header name is 'Accept'.
 Regardless of which syntax is used, the semantics are the same.- Since:
- 5.0
- Author:
- Rossen Stoyanchev
- 
Constructor SummaryConstructorsConstructorDescriptionProducesRequestCondition(String... produces) Creates a new instance from "produces" expressions.ProducesRequestCondition(String @Nullable [] produces, String @Nullable [] headers) Creates a new instance with "produces" and "header" expressions.ProducesRequestCondition(String @Nullable [] produces, String @Nullable [] headers, @Nullable RequestedContentTypeResolver resolver) Same asProducesRequestCondition(String[], String[])but also accepting aContentNegotiationManager.
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidclearMediaTypesAttribute(ServerWebExchange exchange) Use this to clearMEDIA_TYPES_ATTRIBUTEthat contains the parsed, requested media types.combine(ProducesRequestCondition other) Returns the "other" instance if it has any expressions; returns "this" instance otherwise.intcompareTo(ProducesRequestCondition other, ServerWebExchange exchange) Compares this and another "produces" condition as follows: Sort 'Accept' header media types by quality value viaMimeTypeUtils.sortBySpecificity(List)and iterate the list.protected List<org.springframework.web.reactive.result.condition.ProducesRequestCondition.ProduceMediaTypeExpression> Return the discrete items a request condition is composed of.Return the contained "produces" expressions.getMatchingCondition(ServerWebExchange exchange) Checks if any of the contained media type expressions match the given request 'Content-Type' header and returns an instance that is guaranteed to contain matching expressions only.Return the contained producible media types excluding negated expressions.protected StringThe notation to use when printing discrete items of content.booleanisEmpty()Whether the condition has any media type expressions.Methods inherited from class org.springframework.web.reactive.result.condition.AbstractRequestConditionequals, hashCode, toString
- 
Constructor Details- 
ProducesRequestConditionCreates a new instance from "produces" expressions. If 0 expressions are provided in total, this condition will match to any request.- Parameters:
- produces- expressions with syntax defined by- RequestMapping.produces()
 
- 
ProducesRequestConditionCreates a new instance with "produces" and "header" expressions. "Header" expressions where the header name is not 'Accept' or have no header value defined are ignored. If 0 expressions are provided in total, this condition will match to any request.- Parameters:
- produces- expressions with syntax defined by- RequestMapping.produces()
- headers- expressions with syntax defined by- RequestMapping.headers()
 
- 
ProducesRequestConditionpublic ProducesRequestCondition(String @Nullable [] produces, String @Nullable [] headers, @Nullable RequestedContentTypeResolver resolver) Same asProducesRequestCondition(String[], String[])but also accepting aContentNegotiationManager.- Parameters:
- produces- expressions with syntax defined by- RequestMapping.produces()
- headers- expressions with syntax defined by- RequestMapping.headers()
- resolver- used to determine requested content type
 
 
- 
- 
Method Details- 
getExpressionsReturn the contained "produces" expressions.
- 
getProducibleMediaTypes
- 
isEmptypublic boolean isEmpty()Whether the condition has any media type expressions.- Overrides:
- isEmptyin class- AbstractRequestCondition<ProducesRequestCondition>
- Returns:
- trueif empty;- falseotherwise
 
- 
getContentprotected List<org.springframework.web.reactive.result.condition.ProducesRequestCondition.ProduceMediaTypeExpression> getContent()Description copied from class:AbstractRequestConditionReturn the discrete items a request condition is composed of.For example URL patterns, HTTP request methods, param expressions, etc. - Specified by:
- getContentin class- AbstractRequestCondition<ProducesRequestCondition>
- Returns:
- a collection of objects (never null)
 
- 
getToStringInfixDescription copied from class:AbstractRequestConditionThe notation to use when printing discrete items of content.For example " || "for URL patterns or" && "for param expressions.- Specified by:
- getToStringInfixin class- AbstractRequestCondition<ProducesRequestCondition>
 
- 
combineReturns the "other" instance if it has any expressions; returns "this" instance otherwise. Practically that means a method-level "produces" overrides a type-level "produces" condition.- Parameters:
- other- the condition to combine with.
- Returns:
- a request condition instance that is the result of combining the two condition instances.
 
- 
getMatchingConditionChecks if any of the contained media type expressions match the given request 'Content-Type' header and returns an instance that is guaranteed to contain matching expressions only. The match is performed viaMediaType.isCompatibleWith(MediaType).- Parameters:
- exchange- the current exchange
- Returns:
- the same instance if there are no expressions;
 or a new condition with matching expressions;
 or nullif no expressions match.
 
- 
compareToCompares this and another "produces" condition as follows:- Sort 'Accept' header media types by quality value via
 MimeTypeUtils.sortBySpecificity(List)and iterate the list.
- Get the first index of matching media types in each "produces"
 condition first matching with MimeType.equals(Object)and then withMediaType.includes(MediaType).
- If a lower index is found, the condition at that index wins.
- If both indexes are equal, the media types at the index are
 compared further with MediaType.isMoreSpecific(MimeType).
 It is assumed that both instances have been obtained via getMatchingCondition(ServerWebExchange)and each instance contains the matching producible media type expression only or is otherwise empty.
- Sort 'Accept' header media types by quality value via
 
- 
clearMediaTypesAttributeUse this to clearMEDIA_TYPES_ATTRIBUTEthat contains the parsed, requested media types.- Parameters:
- exchange- the current exchange
- Since:
- 5.2
 
 
-