001/* 002 * Copyright 2002-2018 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.converter; 018 019import org.springframework.http.HttpInputMessage; 020import org.springframework.lang.Nullable; 021import org.springframework.util.Assert; 022 023/** 024 * Thrown by {@link HttpMessageConverter} implementations when the 025 * {@link HttpMessageConverter#read} method fails. 026 * 027 * @author Arjen Poutsma 028 * @author Juergen Hoeller 029 * @since 3.0 030 */ 031@SuppressWarnings("serial") 032public class HttpMessageNotReadableException extends HttpMessageConversionException { 033 034 @Nullable 035 private final HttpInputMessage httpInputMessage; 036 037 038 /** 039 * Create a new HttpMessageNotReadableException. 040 * @param msg the detail message 041 * @deprecated as of 5.1, in favor of {@link #HttpMessageNotReadableException(String, HttpInputMessage)} 042 */ 043 @Deprecated 044 public HttpMessageNotReadableException(String msg) { 045 super(msg); 046 this.httpInputMessage = null; 047 } 048 049 /** 050 * Create a new HttpMessageNotReadableException. 051 * @param msg the detail message 052 * @param cause the root cause (if any) 053 * @deprecated as of 5.1, in favor of {@link #HttpMessageNotReadableException(String, Throwable, HttpInputMessage)} 054 */ 055 @Deprecated 056 public HttpMessageNotReadableException(String msg, @Nullable Throwable cause) { 057 super(msg, cause); 058 this.httpInputMessage = null; 059 } 060 061 /** 062 * Create a new HttpMessageNotReadableException. 063 * @param msg the detail message 064 * @param httpInputMessage the original HTTP message 065 * @since 5.1 066 */ 067 public HttpMessageNotReadableException(String msg, HttpInputMessage httpInputMessage) { 068 super(msg); 069 this.httpInputMessage = httpInputMessage; 070 } 071 072 /** 073 * Create a new HttpMessageNotReadableException. 074 * @param msg the detail message 075 * @param cause the root cause (if any) 076 * @param httpInputMessage the original HTTP message 077 * @since 5.1 078 */ 079 public HttpMessageNotReadableException(String msg, @Nullable Throwable cause, HttpInputMessage httpInputMessage) { 080 super(msg, cause); 081 this.httpInputMessage = httpInputMessage; 082 } 083 084 085 /** 086 * Return the original HTTP message. 087 * @since 5.1 088 */ 089 public HttpInputMessage getHttpInputMessage() { 090 Assert.state(this.httpInputMessage != null, "No HttpInputMessage available - use non-deprecated constructors"); 091 return this.httpInputMessage; 092 } 093 094}