001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.accept; 018 019import java.util.Collections; 020import java.util.List; 021 022import org.springframework.http.MediaType; 023import org.springframework.web.HttpMediaTypeNotAcceptableException; 024import org.springframework.web.context.request.NativeWebRequest; 025 026/** 027 * A strategy for resolving the requested media types for a request. 028 * 029 * @author Rossen Stoyanchev 030 * @since 3.2 031 */ 032@FunctionalInterface 033public interface ContentNegotiationStrategy { 034 035 /** 036 * A singleton list with {@link MediaType#ALL} that is returned from 037 * {@link #resolveMediaTypes} when no specific media types are requested. 038 * @since 5.0.5 039 */ 040 List<MediaType> MEDIA_TYPE_ALL_LIST = Collections.singletonList(MediaType.ALL); 041 042 043 /** 044 * Resolve the given request to a list of media types. The returned list is 045 * ordered by specificity first and by quality parameter second. 046 * @param webRequest the current request 047 * @return the requested media types, or {@link #MEDIA_TYPE_ALL_LIST} if none 048 * were requested. 049 * @throws HttpMediaTypeNotAcceptableException if the requested media 050 * types cannot be parsed 051 */ 052 List<MediaType> resolveMediaTypes(NativeWebRequest webRequest) 053 throws HttpMediaTypeNotAcceptableException; 054 055}