Class InvocableHandlerMethod
- java.lang.Object
- org.springframework.web.method.HandlerMethod
- org.springframework.web.method.support.InvocableHandlerMethod
- Direct Known Subclasses:
ServletInvocableHandlerMethod
public class InvocableHandlerMethod extends HandlerMethod
Provides a method for invoking the handler method for a given request after resolving its method argument values through registeredHandlerMethodArgumentResolver
s.Argument resolution often requires a
WebDataBinder
for data binding or for type conversion. Use thesetDataBinderFactory(WebDataBinderFactory)
property to supply a binder factory to pass to argument resolvers.Use
setHandlerMethodArgumentResolvers(org.springframework.web.method.support.HandlerMethodArgumentResolverComposite)
to customize the list of argument resolvers.- Since:
- 3.1
- Author:
- Rossen Stoyanchev, Juergen Hoeller
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.web.method.HandlerMethod
HandlerMethod.HandlerMethodParameter
Field Summary
Fields inherited from class org.springframework.web.method.HandlerMethod
logger
Constructor Summary
Constructors Constructor Description InvocableHandlerMethod(Object bean, Method method)
Create an instance from a bean instance and a method.InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)
Construct a new handler method with the given bean instance, method name and parameters.InvocableHandlerMethod(HandlerMethod handlerMethod)
Create an instance from aHandlerMethod
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
doInvoke(Object... args)
Invoke the handler method with the given argument values.protected String
getDetailedErrorMessage(String text)
Adds HandlerMethod details such as the bean type and method signature to the message.Object
invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer, Object... providedArgs)
Invoke the method after resolving its argument values in the context of the given request.void
setDataBinderFactory(WebDataBinderFactory dataBinderFactory)
Set theWebDataBinderFactory
to be passed to argument resolvers allowing them to create aWebDataBinder
for data binding and type conversion purposes.void
setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers)
SetHandlerMethodArgumentResolver
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.Methods inherited from class org.springframework.web.method.HandlerMethod
createWithResolvedBean, equals, getBean, getBeanType, getBridgedMethod, getMethod, getMethodAnnotation, getMethodParameters, getResolvedFromHandlerMethod, getResponseStatus, getResponseStatusReason, getReturnType, getReturnValueType, getShortLogMessage, hashCode, hasMethodAnnotation, isVoid, toString
Constructor Detail
InvocableHandlerMethod
public InvocableHandlerMethod(HandlerMethod handlerMethod)
Create an instance from aHandlerMethod
.
InvocableHandlerMethod
public InvocableHandlerMethod(Object bean, Method method)
Create an instance from a bean instance and a method.
InvocableHandlerMethod
public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException
Construct a new handler method with the given bean instance, method name and parameters.- Parameters:
bean
- the object beanmethodName
- the method nameparameterTypes
- the method parameter types- Throws:
NoSuchMethodException
- when the method cannot be found
Method Detail
setHandlerMethodArgumentResolvers
public void setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers)
SetHandlerMethodArgumentResolver
s to use to use for resolving method argument values.
setParameterNameDiscoverer
public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer)
Set the ParameterNameDiscoverer for resolving parameter names when needed (e.g. default request attribute name).Default is a
DefaultParameterNameDiscoverer
.
setDataBinderFactory
public void setDataBinderFactory(WebDataBinderFactory dataBinderFactory)
Set theWebDataBinderFactory
to be passed to argument resolvers allowing them to create aWebDataBinder
for data binding and type conversion purposes.
invokeForRequest
public Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception
Invoke the method after resolving its argument values in the context of the given request.Argument values are commonly resolved through
HandlerMethodArgumentResolver
s. TheprovidedArgs
parameter however may supply argument values to be used directly, i.e. without argument resolution. Examples of provided argument values include aWebDataBinder
, aSessionStatus
, or a thrown exception instance. Provided argument values are checked before argument resolvers.- Parameters:
request
- the current requestmavContainer
- the ModelAndViewContainer for this requestprovidedArgs
- "given" arguments matched by type, not resolved- Returns:
- the raw value returned by the invoked method
- Throws:
Exception
- raised if no suitable argument resolver can be found, or if the method raised an exception
doInvoke
protected Object doInvoke(Object... args) throws Exception
Invoke the handler method with the given argument values.- Throws:
Exception
getDetailedErrorMessage
protected String getDetailedErrorMessage(String text)
Adds HandlerMethod details such as the bean type and method signature to the message.- Parameters:
text
- error message to append the HandlerMethod details to