Top Description Inners Fields Constructors Methods
org.springframework.web.reactive.result.condition

public final Class ProducesRequestCondition

extends AbstractRequestCondition<ProducesRequestCondition>
Class Inheritance
Imports
java.util.ArrayList, .Collections, .LinkedHashSet, .List, .Set, org.springframework.http.MediaType, org.springframework.lang.Nullable, org.springframework.util.CollectionUtils, .MimeType, .ObjectUtils, org.springframework.web.accept.ContentNegotiationManager, org.springframework.web.bind.annotation.RequestMapping, org.springframework.web.cors.reactive.CorsUtils, org.springframework.web.reactive.accept.RequestedContentTypeResolver, .RequestedContentTypeResolverBuilder, org.springframework.web.server.NotAcceptableStatusException, .ServerWebExchange, .UnsupportedMediaTypeStatusException

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.
Author
Rossen Stoyanchev
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
ProducesRequestCondition.ProduceMediaTypeExpression

Parses and matches a single media type expression to a request's 'Accept' header.

Field Summary

Modifier and TypeField and Description
private final RequestedContentTypeResolver
private static final RequestedContentTypeResolver
private static final ProducesRequestCondition
private final List<ProducesRequestCondition.ProduceMediaTypeExpression>
private static final String
private final List<ProducesRequestCondition.ProduceMediaTypeExpression>

Constructor Summary

AccessConstructor and Description
public
ProducesRequestCondition(String...
expressions with syntax defined by RequestMapping#produces()
produces
)

Creates a new instance from "produces" expressions.

public
ProducesRequestCondition(String[]
expressions with syntax defined by RequestMapping#produces()
produces
,
String[]
expressions with syntax defined by RequestMapping#headers()
headers
)

Creates a new instance with "produces" and "header" expressions.

public
ProducesRequestCondition(String[]
expressions with syntax defined by RequestMapping#produces()
produces
,
String[]
expressions with syntax defined by RequestMapping#headers()
headers
,
RequestedContentTypeResolver
used to determine requested content type
resolver
)

Same as ProducesRequestCondition(String[], String[]) but also accepting a ContentNegotiationManager.

private
ProducesRequestCondition(List<ProducesRequestCondition.ProduceMediaTypeExpression> expressions, ProducesRequestCondition other)

Private constructor for internal use to create matching conditions.

Method Summary

Modifier and TypeMethod and Description
public static void
clearMediaTypesAttribute(ServerWebExchange
the current exchange
exchange
)

Use this to clear MEDIA_TYPES_ATTRIBUTE that contains the parsed, requested media types.

public ProducesRequestCondition
combine(ProducesRequestCondition
the condition to combine with.
other
)

Implements org.springframework.web.reactive.result.condition.RequestCondition.combine.

Returns the "other" instance if it has any expressions; returns "this" instance otherwise.

private int
compareMatchingMediaTypes(ProducesRequestCondition condition1, int index1, ProducesRequestCondition condition2, int index2)

public int
compareTo(ProducesRequestCondition other, ServerWebExchange exchange)

Implements org.springframework.web.reactive.result.condition.RequestCondition.compareTo.

Compares this and another "produces" condition as follows:

  1. Sort 'Accept' header media types by quality value via org.springframework.util.MimeTypeUtils#sortBySpecificity(List) and iterate the list.
  2. Get the first index of matching media types in each "produces" condition first matching with MediaType#equals(Object) and then with MediaType#includes(MediaType).
  3. If a lower index is found, the condition at that index wins.
  4. If both indexes are equal, the media types at the index are compared further with MediaType#isMoreSpecific(MimeType).
private List<MediaType>
protected List<ProducesRequestCondition.ProduceMediaTypeExpression>
getContent()

Implements abstract org.springframework.web.reactive.result.condition.AbstractRequestCondition.getContent.

Return the discrete items a request condition is composed of.

public Set<MediaTypeExpression>
getExpressions()

Return the contained "produces" expressions.

private List<ProducesRequestCondition.ProduceMediaTypeExpression>
getExpressionsToCompare()

Return the contained "produces" expressions or if that's empty, a list with a */* expression.

public ProducesRequestCondition

Returns:

the same instance if there are no expressions; or a new condition with matching expressions; or null if no expressions match.
getMatchingCondition
(ServerWebExchange
the current exchange
exchange
)

Implements org.springframework.web.reactive.result.condition.RequestCondition.getMatchingCondition.

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.

private List<ProducesRequestCondition.ProduceMediaTypeExpression>
public Set<MediaType>
getProducibleMediaTypes()

Return the contained producible media types excluding negated expressions.

protected String
getToStringInfix()

Implements abstract org.springframework.web.reactive.result.condition.AbstractRequestCondition.getToStringInfix.

The notation to use when printing discrete items of content.

private int
private int
public boolean
isEmpty()

Overrides org.springframework.web.reactive.result.condition.AbstractRequestCondition.isEmpty.

Whether the condition has any media type expressions.

private List<ProducesRequestCondition.ProduceMediaTypeExpression>
parseExpressions(String[] produces, String[] headers)

Inherited from org.springframework.web.reactive.result.condition.AbstractRequestCondition:
equalshashCodetoString

Field Detail

contentTypeResolverback to summary
private final RequestedContentTypeResolver contentTypeResolver
DEFAULT_CONTENT_TYPE_RESOLVERback to summary
private static final RequestedContentTypeResolver DEFAULT_CONTENT_TYPE_RESOLVER
EMPTY_CONDITIONback to summary
private static final ProducesRequestCondition EMPTY_CONDITION
expressionsback to summary
private final List<ProducesRequestCondition.ProduceMediaTypeExpression> expressions
MEDIA_TYPES_ATTRIBUTEback to summary
private static final String MEDIA_TYPES_ATTRIBUTE
mediaTypeAllListback to summary
private final List<ProducesRequestCondition.ProduceMediaTypeExpression> mediaTypeAllList

Constructor Detail

ProducesRequestConditionback to summary
public ProducesRequestCondition(String... produces)

Creates a new instance from "produces" expressions. If 0 expressions are provided in total, this condition will match to any request.

Parameters
produces:String[]

expressions with syntax defined by RequestMapping#produces()

ProducesRequestConditionback to summary
public ProducesRequestCondition(String[] produces, String[] headers)

Creates 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:String[]

expressions with syntax defined by RequestMapping#produces()

headers:String[]

expressions with syntax defined by RequestMapping#headers()

ProducesRequestConditionback to summary
public ProducesRequestCondition(String[] produces, String[] headers, RequestedContentTypeResolver resolver)

Same as ProducesRequestCondition(String[], String[]) but also accepting a ContentNegotiationManager.

Parameters
produces:String[]

expressions with syntax defined by RequestMapping#produces()

headers:String[]

expressions with syntax defined by RequestMapping#headers()

resolver:RequestedContentTypeResolver

used to determine requested content type

ProducesRequestConditionback to summary
private ProducesRequestCondition(List<ProducesRequestCondition.ProduceMediaTypeExpression> expressions, ProducesRequestCondition other)

Private constructor for internal use to create matching conditions. Note the expressions List is neither sorted, nor deep copied.

Method Detail

clearMediaTypesAttributeback to summary
public static void clearMediaTypesAttribute(ServerWebExchange exchange)

Use this to clear MEDIA_TYPES_ATTRIBUTE that contains the parsed, requested media types.

Parameters
exchange:ServerWebExchange

the current exchange

Since
5.2
combineback to summary
public ProducesRequestCondition combine(ProducesRequestCondition other)

Implements org.springframework.web.reactive.result.condition.RequestCondition.combine.

Returns 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:ProducesRequestCondition

Doc from org.springframework.web.reactive.result.condition.RequestCondition.combine.

the condition to combine with.

Returns:ProducesRequestCondition

Doc from org.springframework.web.reactive.result.condition.RequestCondition.combine.

a request condition instance that is the result of combining the two condition instances.

Annotations
@Override
compareMatchingMediaTypesback to summary
private int compareMatchingMediaTypes(ProducesRequestCondition condition1, int index1, ProducesRequestCondition condition2, int index2)
compareToback to summary
public int compareTo(ProducesRequestCondition other, ServerWebExchange exchange)

Implements org.springframework.web.reactive.result.condition.RequestCondition.compareTo.

Compares this and another "produces" condition as follows:

  1. Sort 'Accept' header media types by quality value via org.springframework.util.MimeTypeUtils#sortBySpecificity(List) and iterate the list.
  2. Get the first index of matching media types in each "produces" condition first matching with MediaType#equals(Object) and then with MediaType#includes(MediaType).
  3. If a lower index is found, the condition at that index wins.
  4. 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.

Annotations
@Override
getAcceptedMediaTypesback to summary
private List<MediaType> getAcceptedMediaTypes(ServerWebExchange exchange) throws NotAcceptableStatusException
getContentback to summary
protected List<ProducesRequestCondition.ProduceMediaTypeExpression> getContent()

Implements abstract org.springframework.web.reactive.result.condition.AbstractRequestCondition.getContent.

Doc from org.springframework.web.reactive.result.condition.AbstractRequestCondition.getContent.

Return the discrete items a request condition is composed of.

For example URL patterns, HTTP request methods, param expressions, etc.

Returns:List<ProducesRequestCondition.ProduceMediaTypeExpression>

a collection of objects (never null)

Annotations
@Override
getExpressionsback to summary
public Set<MediaTypeExpression> getExpressions()

Return the contained "produces" expressions.

getExpressionsToCompareback to summary
private List<ProducesRequestCondition.ProduceMediaTypeExpression> getExpressionsToCompare()

Return the contained "produces" expressions or if that's empty, a list with a */* expression.

getMatchingConditionback to summary
public ProducesRequestCondition getMatchingCondition(ServerWebExchange exchange)

Implements org.springframework.web.reactive.result.condition.RequestCondition.getMatchingCondition.

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. The match is performed via MediaType#isCompatibleWith(MediaType).

Parameters
exchange:ServerWebExchange

the current exchange

Returns:ProducesRequestCondition

the same instance if there are no expressions; or a new condition with matching expressions; or null if no expressions match.

Annotations
@Override
@Nullable
getMatchingExpressionsback to summary
private List<ProducesRequestCondition.ProduceMediaTypeExpression> getMatchingExpressions(ServerWebExchange exchange)
Annotations
@Nullable
getProducibleMediaTypesback to summary
public Set<MediaType> getProducibleMediaTypes()

Return the contained producible media types excluding negated expressions.

getToStringInfixback to summary
protected String getToStringInfix()

Implements abstract org.springframework.web.reactive.result.condition.AbstractRequestCondition.getToStringInfix.

Doc from org.springframework.web.reactive.result.condition.AbstractRequestCondition.getToStringInfix.

The notation to use when printing discrete items of content.

For example " || " for URL patterns or " && " for param expressions.

Annotations
@Override
indexOfEqualMediaTypeback to summary
private int indexOfEqualMediaType(MediaType mediaType)
indexOfIncludedMediaTypeback to summary
private int indexOfIncludedMediaType(MediaType mediaType)
isEmptyback to summary
public boolean isEmpty()

Overrides org.springframework.web.reactive.result.condition.AbstractRequestCondition.isEmpty.

Whether the condition has any media type expressions.

Returns:boolean

Doc from org.springframework.web.reactive.result.condition.AbstractRequestCondition.isEmpty.

true if empty; false otherwise

Annotations
@Override
parseExpressionsback to summary
private List<ProducesRequestCondition.ProduceMediaTypeExpression> parseExpressions(String[] produces, String[] headers)
org.springframework.web.reactive.result.condition back to summary

pack-priv Class ProducesRequestCondition.ProduceMediaTypeExpression

extends AbstractMediaTypeExpression
Class Inheritance

Parses and matches a single media type expression to a request's 'Accept' header.

Constructor Summary

AccessConstructor and Description
pack-priv
ProduceMediaTypeExpression(MediaType mediaType, boolean negated)

pack-priv

Method Summary

Modifier and TypeMethod and Description
protected boolean
Inherited from org.springframework.web.reactive.result.condition.AbstractMediaTypeExpression:
compareToequalsgetMediaTypehashCodeisNegatedmatchmatchParameterstoString

Constructor Detail

ProduceMediaTypeExpressionback to summary
pack-priv ProduceMediaTypeExpression(MediaType mediaType, boolean negated)
ProduceMediaTypeExpressionback to summary
pack-priv ProduceMediaTypeExpression(String expression)

Method Detail

matchMediaTypeback to summary
protected boolean matchMediaType(ServerWebExchange exchange) throws NotAcceptableStatusException

Implements abstract org.springframework.web.reactive.result.condition.AbstractMediaTypeExpression.matchMediaType.

Annotations
@Override