## org.springframework.web.servlet.mvc.method.annotation
Class ServletInvocableHandlerMethod

    java.lang.Object
      org.springframework.web.method.HandlerMethod
          org.springframework.web.method.support.InvocableHandlerMethod
              org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod

    public class ServletInvocableHandlerMethod

extends InvocableHandlerMethod

Extends `InvocableHandlerMethod` with the ability to handle the value returned from the method through a registered `HandlerMethodArgumentResolver` that supports the given return value type. Return value handling may include writing to the response or updating the `ModelAndViewContainer` structure.

If the underlying method has a `ResponseStatus` instruction, the status on the response is set accordingly after the method is invoked but before the return value is handled.

Since:
  3.1
Author:
  Rossen Stoyanchev
See Also:
  `invokeAndHandle(NativeWebRequest, ModelAndViewContainer, Object...)`

Field Summary

Fields inherited from class org.springframework.web.method.HandlerMethod
`logger`

Constructor Summary
`ServletInvocableHandlerMethod(Object handler, Method method)` Creates a `ServletInvocableHandlerMethod` instance with the given bean and method.

Method Summary
`void` `invokeAndHandle(NativeWebRequest request, ModelAndViewContainer mavContainer, Object... providedArgs)` Invokes the method and handles the return value through a registered `HandlerMethodReturnValueHandler`.
`void` `setHandlerMethodReturnValueHandlers(HandlerMethodReturnValueHandlerComposite returnValueHandlers)`

Methods inherited from class org.springframework.web.method.support.InvocableHandlerMethod
`getDetailedErrorMessage, invokeForRequest, setDataBinderFactory, setHandlerMethodArgumentResolvers, setParameterNameDiscoverer`

Methods inherited from class org.springframework.web.method.HandlerMethod
`createWithResolvedBean, equals, getBean, getBeanType, getBridgedMethod, getMethod, getMethodAnnotation, getMethodParameters, getReturnType, hashCode, isVoid, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### ServletInvocableHandlerMethod

    public ServletInvocableHandlerMethod(Object handler,
                                         Method method)

  Creates a `ServletInvocableHandlerMethod` instance with the given bean and method.

  Parameters:
    `handler` - the object handler
    `method` - the method

Method Detail

### setHandlerMethodReturnValueHandlers

    public void setHandlerMethodReturnValueHandlers(HandlerMethodReturnValueHandlerComposite returnValueHandlers)

### invokeAndHandle

    public final void invokeAndHandle(NativeWebRequest request,
                                      ModelAndViewContainer mavContainer,
                                      Object... providedArgs)
                               throws Exception

  Invokes the method and handles the return value through a registered `HandlerMethodReturnValueHandler`.

  Return value handling may be skipped entirely when the method returns `null` (also possibly due to a `void` return type) and one of the following additional conditions is true:

  - A `HandlerMethodArgumentResolver` has set the `ModelAndViewContainer.setRequestHandled(boolean)` flag to `false` -- e.g. method arguments providing access to the response.
  - The request qualifies as "not modified" as defined in `ServletWebRequest.checkNotModified(long)` and `ServletWebRequest.checkNotModified(String)`. In this case a response with "not modified" response headers will be automatically generated without the need for return value handling.
  - The status on the response is set due to a @`ResponseStatus` instruction.

  After the return value is handled, callers of this method can use the `ModelAndViewContainer` to gain access to model attributes, view selection choices, and to check if view resolution is even needed.

  Parameters:
    `request` - the current request
    `mavContainer` - the `ModelAndViewContainer` for the current request
    `providedArgs` - argument values to try to use without the need for view resolution
  Throws:
    `Exception`