001/*
002 * Copyright 2002-2020 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.server;
018
019import java.util.Collections;
020import java.util.List;
021
022import org.springframework.http.HttpStatus;
023import org.springframework.http.MediaType;
024
025/**
026 * Exception for errors that fit response status 415 (unsupported media type).
027 *
028 * @author Rossen Stoyanchev
029 * @since 5.0
030 * @deprecated in favor of {@link UnsupportedMediaTypeStatusException},
031 * with this class never thrown by Spring code and to be removed in 5.3
032 */
033@Deprecated
034@SuppressWarnings("serial")
035public class MediaTypeNotSupportedStatusException extends ResponseStatusException {
036
037        private final List<MediaType> supportedMediaTypes;
038
039
040        /**
041         * Constructor for when the Content-Type is invalid.
042         */
043        public MediaTypeNotSupportedStatusException(String reason) {
044                super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, reason);
045                this.supportedMediaTypes = Collections.emptyList();
046        }
047
048        /**
049         * Constructor for when the Content-Type is not supported.
050         */
051        public MediaTypeNotSupportedStatusException(List<MediaType> supportedMediaTypes) {
052                super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "Unsupported media type", null);
053                this.supportedMediaTypes = Collections.unmodifiableList(supportedMediaTypes);
054        }
055
056
057        /**
058         * Return the list of supported content types in cases when the Accept
059         * header is parsed but not supported, or an empty list otherwise.
060         */
061        public List<MediaType> getSupportedMediaTypes() {
062                return this.supportedMediaTypes;
063        }
064
065}