1 /* 2 * Copyright 2002-2013 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.http; 18 19 import org.springframework.util.InvalidMimeTypeException; 20 21 /** 22 * Exception thrown from {@link MediaType#parseMediaType(String)} in case of 23 * encountering an invalid media type specification String. 24 * 25 * @author Juergen Hoeller 26 * @since 3.2.2 27 */ 28 @SuppressWarnings("serial") 29 public class InvalidMediaTypeException extends IllegalArgumentException { 30 31 private String mediaType; 32 33 34 /** 35 * Create a new InvalidMediaTypeException for the given media type. 36 * @param mediaType the offending media type 37 * @param message a detail message indicating the invalid part 38 */ 39 public InvalidMediaTypeException(String mediaType, String message) { 40 super("Invalid media type \"" + mediaType + "\": " + message); 41 this.mediaType = mediaType; 42 } 43 44 /** 45 * Constructor that allows wrapping {@link InvalidMimeTypeException}. 46 */ 47 InvalidMediaTypeException(InvalidMimeTypeException ex) { 48 super(ex.getMessage(), ex); 49 this.mediaType = ex.getMimeType(); 50 } 51 52 53 /** 54 * Return the offending media type. 55 */ 56 public String getMediaType() { 57 return this.mediaType; 58 } 59 60 }