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.messaging.handler.invocation; 018 019import org.springframework.core.MethodParameter; 020import org.springframework.messaging.Message; 021import org.springframework.messaging.MessagingException; 022 023/** 024 * Common exception resulting from the invocation of 025 * {@link org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver}. 026 * 027 * @author Juergen Hoeller 028 * @since 4.3.6 029 * @see HandlerMethodArgumentResolver 030 */ 031@SuppressWarnings("serial") 032public class MethodArgumentResolutionException extends MessagingException { 033 034 private final MethodParameter parameter; 035 036 037 /** 038 * Create a new instance providing the invalid {@code MethodParameter}. 039 */ 040 public MethodArgumentResolutionException(Message<?> message, MethodParameter parameter) { 041 super(message, getMethodParameterMessage(parameter)); 042 this.parameter = parameter; 043 } 044 045 /** 046 * Create a new instance providing the invalid {@code MethodParameter} and 047 * a prepared description. 048 */ 049 public MethodArgumentResolutionException(Message<?> message, MethodParameter parameter, String description) { 050 super(message, getMethodParameterMessage(parameter) + ": " + description); 051 this.parameter = parameter; 052 } 053 054 055 /** 056 * Return the MethodParameter that was rejected. 057 */ 058 public final MethodParameter getMethodParameter() { 059 return this.parameter; 060 } 061 062 063 private static String getMethodParameterMessage(MethodParameter parameter) { 064 return "Could not resolve method parameter at index " + parameter.getParameterIndex() + 065 " in " + parameter.getMethod().toGenericString(); 066 } 067 068}