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.http; 018 019import org.springframework.util.InvalidMimeTypeException; 020 021/** 022 * Exception thrown from {@link MediaType#parseMediaType(String)} in case of 023 * encountering an invalid media type specification String. 024 * 025 * @author Juergen Hoeller 026 * @since 3.2.2 027 */ 028@SuppressWarnings("serial") 029public class InvalidMediaTypeException extends IllegalArgumentException { 030 031 private String mediaType; 032 033 034 /** 035 * Create a new InvalidMediaTypeException for the given media type. 036 * @param mediaType the offending media type 037 * @param message a detail message indicating the invalid part 038 */ 039 public InvalidMediaTypeException(String mediaType, String message) { 040 super("Invalid media type \"" + mediaType + "\": " + message); 041 this.mediaType = mediaType; 042 } 043 044 /** 045 * Constructor that allows wrapping {@link InvalidMimeTypeException}. 046 */ 047 InvalidMediaTypeException(InvalidMimeTypeException ex) { 048 super(ex.getMessage(), ex); 049 this.mediaType = ex.getMimeType(); 050 } 051 052 053 /** 054 * Return the offending media type. 055 */ 056 public String getMediaType() { 057 return this.mediaType; 058 } 059 060}