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