org.springframework.web.servlet.mvc.condition

Class ProducesRequestCondition

    • Constructor Detail

      • ProducesRequestCondition

        public ProducesRequestCondition(java.lang.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 - expressions with syntax defined by RequestMapping.produces()
      • ProducesRequestCondition

        public ProducesRequestCondition(java.lang.String[] produces,
                                        @Nullable
                                        java.lang.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 - expressions with syntax defined by RequestMapping.produces()
        headers - expressions with syntax defined by RequestMapping.headers()
    • Method Detail

      • getExpressions

        public java.util.Set<MediaTypeExpression> getExpressions()
        Return the contained "produces" expressions.
      • getProducibleMediaTypes

        public java.util.Set<MediaType> getProducibleMediaTypes()
        Return the contained producible media types excluding negated expressions.
      • getContent

        protected java.util.List<org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.ProduceMediaTypeExpression> getContent()
        Description copied from class: AbstractRequestCondition
        Return the discrete items a request condition is composed of.

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

        Specified by:
        getContent in class AbstractRequestCondition<ProducesRequestCondition>
        Returns:
        a collection of objects, never null
      • combine

        public ProducesRequestCondition combine(ProducesRequestCondition other)
        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 - the condition to combine with.
        Returns:
        a request condition instance that is the result of combining the two condition instances.
      • getMatchingCondition

        @Nullable
        public ProducesRequestCondition getMatchingCondition(HttpServletRequest request)
        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:
        request - the current request
        Returns:
        the same instance if there are no expressions; or a new condition with matching expressions; or null if no expressions match.