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.List; 020 021import org.springframework.http.MediaType; 022 023/** 024 * Exception thrown when a client POSTs, PUTs, or PATCHes content of a type 025 * not supported by request handler. 026 * 027 * @author Arjen Poutsma 028 * @since 3.0 029 */ 030@SuppressWarnings("serial") 031public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException { 032 033 private final MediaType contentType; 034 035 036 /** 037 * Create a new HttpMediaTypeNotSupportedException. 038 * @param message the exception message 039 */ 040 public HttpMediaTypeNotSupportedException(String message) { 041 super(message); 042 this.contentType = null; 043 } 044 045 /** 046 * Create a new HttpMediaTypeNotSupportedException. 047 * @param contentType the unsupported content type 048 * @param supportedMediaTypes the list of supported media types 049 */ 050 public HttpMediaTypeNotSupportedException(MediaType contentType, List<MediaType> supportedMediaTypes) { 051 this(contentType, supportedMediaTypes, "Content type '" + contentType + "' not supported"); 052 } 053 054 /** 055 * Create a new HttpMediaTypeNotSupportedException. 056 * @param contentType the unsupported content type 057 * @param supportedMediaTypes the list of supported media types 058 * @param msg the detail message 059 */ 060 public HttpMediaTypeNotSupportedException(MediaType contentType, List<MediaType> supportedMediaTypes, String msg) { 061 super(msg, supportedMediaTypes); 062 this.contentType = contentType; 063 } 064 065 066 /** 067 * Return the HTTP request content type method that caused the failure. 068 */ 069 public MediaType getContentType() { 070 return this.contentType; 071 } 072 073}