Class HandlerMethod

java.lang.Object
org.springframework.graphql.data.method.HandlerMethod
Direct Known Subclasses:
InvocableHandlerMethodSupport

public class HandlerMethod extends Object
Encapsulates information about a handler method consisting of a method and a bean. Provides convenient access to method parameters, the method return value, method annotations, etc.

The class may be created with a bean instance or with a bean name (e.g. lazy-init bean, prototype bean). Use createWithResolvedBean() to obtain a HandlerMethod instance with a bean instance resolved through the associated BeanFactory.

Since:
1.0.0
Author:
Rossen Stoyanchev
  • Field Details

    • logger

      protected static final Log logger
  • Constructor Details

    • HandlerMethod

      public HandlerMethod(Object bean, Method method)
      Constructor with a handler instance and a method.
      Parameters:
      bean - the handler instance
      method - the handler method
    • HandlerMethod

      public HandlerMethod(String beanName, BeanFactory beanFactory, Method method)
      Constructor with a bean name for the handler along with a BeanFactory to allow resolving the handler instance later.
      Parameters:
      beanName - the bean name
      beanFactory - the bean factory to use for bean resolution
      method - the handler method
    • HandlerMethod

      protected HandlerMethod(HandlerMethod handlerMethod)
      Copy constructor for use from subclasses that accept more arguments.
      Parameters:
      handlerMethod - the handler method
  • Method Details

    • getBean

      public Object getBean()
      Return the bean for this handler method.
    • getMethod

      public Method getMethod()
      Return the method for this handler method.
    • getBeanType

      public Class<?> getBeanType()
      This method returns the type of the handler for this handler method.

      Note that if the bean type is a CGLIB-generated class, the original user-defined class is returned.

    • getBridgedMethod

      protected Method getBridgedMethod()
      If the bean method is a bridge method, this method returns the bridged (user-defined) method. Otherwise it returns the same method as getMethod().
    • getMethodParameters

      public MethodParameter[] getMethodParameters()
      Return the method parameters for this handler method.
    • getReturnType

      public MethodParameter getReturnType()
      Return the HandlerMethod return type.
    • getReturnValueType

      public MethodParameter getReturnValueType(@Nullable Object returnValue)
      Return the actual return value type.
      Parameters:
      returnValue - the return value instance, can be null
    • isVoid

      public boolean isVoid()
      Return true if the method return type is void, false otherwise.
    • getMethodAnnotation

      @Nullable public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType)
      Return a single annotation on the underlying method traversing its super methods if no annotation can be found on the given method itself.

      Also supports merged composed annotations with attribute overrides as of Spring Framework 4.3.

      Type Parameters:
      A - the annotation type
      Parameters:
      annotationType - the type of annotation to introspect the method for
      Returns:
      the annotation, or null if none found
      See Also:
    • hasMethodAnnotation

      public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType)
      Return whether the parameter is declared with the given annotation type.
      Type Parameters:
      A - the annotation type
      Parameters:
      annotationType - the annotation type to look for
      See Also:
    • createWithResolvedBean

      public HandlerMethod createWithResolvedBean()
      If the provided instance contains a bean name rather than an object instance, the bean name is resolved before a HandlerMethod is created and returned.
    • getShortLogMessage

      public String getShortLogMessage()
      Return a short representation of this handler method for log message purposes.
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • findProvidedArgument

      @Nullable protected static Object findProvidedArgument(MethodParameter parameter, @Nullable Object... providedArgs)
    • formatArgumentError

      protected static String formatArgumentError(MethodParameter param, String message)
    • assertTargetBean

      protected void assertTargetBean(Method method, Object targetBean, Object[] args)
      Assert that the target bean class is an instance of the class where the given method is declared. In some cases the actual endpoint instance at request- processing time may be a JDK dynamic proxy (lazy initialization, prototype beans, and others). Endpoint classes that require proxying should prefer class-based proxy mechanisms.
      Parameters:
      method - the handler method
      targetBean - the bean instance
      args - the method arguments
    • formatInvokeError

      protected String formatInvokeError(String text, Object[] args)