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