001/*
002 * Copyright 2002-2013 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;
018
019import java.util.Collections;
020import java.util.List;
021
022import javax.servlet.ServletException;
023
024import org.springframework.http.MediaType;
025
026/**
027 * Abstract base for exceptions related to media types. Adds a list of supported {@link MediaType MediaTypes}.
028 *
029 * @author Arjen Poutsma
030 * @since 3.0
031 */
032@SuppressWarnings("serial")
033public abstract class HttpMediaTypeException extends ServletException {
034
035        private final List<MediaType> supportedMediaTypes;
036
037
038        /**
039         * Create a new HttpMediaTypeException.
040         * @param message the exception message
041         */
042        protected HttpMediaTypeException(String message) {
043                super(message);
044                this.supportedMediaTypes = Collections.emptyList();
045        }
046
047        /**
048         * Create a new HttpMediaTypeException with a list of supported media types.
049         * @param supportedMediaTypes the list of supported media types
050         */
051        protected HttpMediaTypeException(String message, List<MediaType> supportedMediaTypes) {
052                super(message);
053                this.supportedMediaTypes = Collections.unmodifiableList(supportedMediaTypes);
054        }
055
056
057        /**
058         * Return the list of supported media types.
059         */
060        public List<MediaType> getSupportedMediaTypes() {
061                return this.supportedMediaTypes;
062        }
063
064}