public class InvocableHandlerMethod extends HandlerMethod
HandlerMethodArgumentResolver
s.
Argument resolution often requires a WebDataBinder
for data binding or for type conversion.
Use the setDataBinderFactory(WebDataBinderFactory)
property to supply a binder factory to pass to
argument resolvers.
Use setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)
to customize
the list of argument resolvers.
Modifier and Type | Field and Description |
---|---|
private HandlerMethodArgumentResolverComposite |
argumentResolvers |
private WebDataBinderFactory |
dataBinderFactory |
private ParameterNameDiscoverer |
parameterNameDiscoverer |
logger
Constructor and Description |
---|
InvocableHandlerMethod(HandlerMethod handlerMethod)
Create an instance from a
HandlerMethod . |
InvocableHandlerMethod(java.lang.Object bean,
java.lang.reflect.Method method)
Create an instance from the given handler and method.
|
InvocableHandlerMethod(java.lang.Object bean,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
Construct a new handler method with the given bean instance, method name and parameters.
|
Modifier and Type | Method and Description |
---|---|
private void |
assertTargetBean(java.lang.reflect.Method method,
java.lang.Object targetBean,
java.lang.Object[] args)
Assert that the target bean class is an instance of the class where the given
method is declared.
|
private java.lang.String |
getArgumentResolutionErrorMessage(java.lang.String message,
int index) |
protected java.lang.String |
getDetailedErrorMessage(java.lang.String message)
Adds HandlerMethod details such as the controller type and method signature to the given error message.
|
private java.lang.String |
getInvocationErrorMessage(java.lang.String message,
java.lang.Object[] resolvedArgs) |
private java.lang.Object[] |
getMethodArgumentValues(NativeWebRequest request,
ModelAndViewContainer mavContainer,
java.lang.Object... providedArgs)
Get the method argument values for the current request.
|
private java.lang.Object |
invoke(java.lang.Object... args)
Invoke the handler method with the given argument values.
|
java.lang.Object |
invokeForRequest(NativeWebRequest request,
ModelAndViewContainer mavContainer,
java.lang.Object... providedArgs)
Invoke the method after resolving its argument values in the context of the given request.
|
private java.lang.Object |
resolveProvidedArgument(MethodParameter parameter,
java.lang.Object... providedArgs)
Attempt to resolve a method parameter from the list of provided argument values.
|
void |
setDataBinderFactory(WebDataBinderFactory dataBinderFactory)
Set the
WebDataBinderFactory to be passed to argument resolvers allowing them to create
a WebDataBinder for data binding and type conversion purposes. |
void |
setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers)
Set
HandlerMethodArgumentResolver s to use to use for resolving method argument values. |
void |
setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer)
Set the ParameterNameDiscoverer for resolving parameter names when needed
(e.g.
|
createWithResolvedBean, equals, getBean, getBeanType, getBridgedMethod, getMethod, getMethodAnnotation, getMethodParameters, getReturnType, getReturnValueType, hashCode, isVoid, toString
private WebDataBinderFactory dataBinderFactory
private HandlerMethodArgumentResolverComposite argumentResolvers
private ParameterNameDiscoverer parameterNameDiscoverer
public InvocableHandlerMethod(java.lang.Object bean, java.lang.reflect.Method method)
public InvocableHandlerMethod(HandlerMethod handlerMethod)
HandlerMethod
.public InvocableHandlerMethod(java.lang.Object bean, java.lang.String methodName, java.lang.Class<?>... parameterTypes) throws java.lang.NoSuchMethodException
bean
- the object beanmethodName
- the method nameparameterTypes
- the method parameter typesjava.lang.NoSuchMethodException
- when the method cannot be foundpublic void setDataBinderFactory(WebDataBinderFactory dataBinderFactory)
WebDataBinderFactory
to be passed to argument resolvers allowing them to create
a WebDataBinder
for data binding and type conversion purposes.dataBinderFactory
- the data binder factory.public void setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers)
HandlerMethodArgumentResolver
s to use to use for resolving method argument values.public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer)
Default is a DefaultParameterNameDiscoverer
.
public final java.lang.Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer, java.lang.Object... providedArgs) throws java.lang.Exception
Argument
values are commonly resolved through HandlerMethodArgumentResolver
s. The provideArgs
parameter however may supply argument values to be used directly, i.e. without argument resolution.
Examples of provided argument values include a WebDataBinder
, a SessionStatus
, or
a thrown exception instance. Provided argument values are checked before argument resolvers.
request
- the current requestmavContainer
- the ModelAndViewContainer for this requestprovidedArgs
- "given" arguments matched by type, not resolvedjava.lang.Exception
- raised if no suitable argument resolver can be found, or the method raised an exceptionprivate java.lang.Object[] getMethodArgumentValues(NativeWebRequest request, ModelAndViewContainer mavContainer, java.lang.Object... providedArgs) throws java.lang.Exception
java.lang.Exception
private java.lang.String getArgumentResolutionErrorMessage(java.lang.String message, int index)
protected java.lang.String getDetailedErrorMessage(java.lang.String message)
message
- error message to append the HandlerMethod details toprivate java.lang.Object resolveProvidedArgument(MethodParameter parameter, java.lang.Object... providedArgs)
private java.lang.Object invoke(java.lang.Object... args) throws java.lang.Exception
java.lang.Exception
private void assertTargetBean(java.lang.reflect.Method method, java.lang.Object targetBean, java.lang.Object[] args)
@Controller
's that require proxying should prefer
class-based proxy mechanisms.private java.lang.String getInvocationErrorMessage(java.lang.String message, java.lang.Object[] resolvedArgs)