Class RequestAttributesUtils

java.lang.Object
io.microsphere.spring.web.util.RequestAttributesUtils

public abstract class RequestAttributesUtils extends Object
RequestAttributes Utilities Class
Since:
1.0.0
Author:
Mercy
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The prefix of the attribute name of the HandlerMethod method parameter
    static final String
    The prefix of the attribute name of the HandlerMethod method parameter annotated ResponseBody
    static final String
    The prefix of the attribute name of the HandlerMethod method return value
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object[]
    Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
    static Object[]
    getHandlerMethodArguments(org.springframework.core.MethodParameter parameter)
    Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
    static Object[]
    getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method)
    Gets the HandlerMethod method parameter
    static Object[]
    getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.core.MethodParameter parameter)
    Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
    static Object[]
    getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod)
    Gets the HandlerMethod method parameter
    static Object[]
    getHandlerMethodArguments(org.springframework.web.method.HandlerMethod handlerMethod)
    Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
    static <T> T
    Gets the @RequestBody method parameter from the RequestContextHolder.getRequestAttributes()
    static <T> T
    getHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method)
    Gets the @RequestBody method parameter from the RequestAttributes
    static <T> T
    getHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod)
    Gets the @RequestBody method parameter from the RequestAttributes
    static <T> T
    getHandlerMethodRequestBodyArgument(org.springframework.web.method.HandlerMethod handlerMethod)
    Gets the @RequestBody method parameter from the RequestContextHolder.getRequestAttributes()
    static <T> T
    Gets the value returned by the HandlerMethod method from the RequestContextHolder.getRequestAttributes()
    static <T> T
    getHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method)
    Gets the value returned by the HandlerMethod method
    static <T> T
    getHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod)
    Gets the value returned by the HandlerMethod method
    static <T> T
    getHandlerMethodReturnValue(org.springframework.web.method.HandlerMethod handlerMethod)
    Gets the value returned by the HandlerMethod method from the RequestContextHolder.getRequestAttributes()
    static <T> T
    getRequestAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String attributeName)
    Get an attribute from the RequestAttributes with the specified name.
    static void
    setHandlerMethodRequestBodyArgument(Method method, Object requestBodyArgument)
    Set the @RequestBody method parameter in HandlerMethod to the RequestAttributes
    static void
    setHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method, Object requestBodyArgument)
    Set the @RequestBody method parameter in HandlerMethod to the RequestAttributes
    static void
    Set the HandlerMethod method return value to the RequestContextHolder.getRequestAttributes()
    static void
    setHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method, Object returnValue)
    Set the HandlerMethod method return value to the RequestAttributes
    static void
    setRequestAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String attributeName, Object attributeValue)
    Set an attribute to the RequestAttributes with the specified name and value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • HANDLER_METHOD_ARGUMENTS_ATTRIBUTE_NAME_PREFIX

      public static final String HANDLER_METHOD_ARGUMENTS_ATTRIBUTE_NAME_PREFIX
      The prefix of the attribute name of the HandlerMethod method parameter
      See Also:
    • HANDLER_METHOD_REQUEST_BODY_ARGUMENT_ATTRIBUTE_NAME_PREFIX

      public static final String HANDLER_METHOD_REQUEST_BODY_ARGUMENT_ATTRIBUTE_NAME_PREFIX
      The prefix of the attribute name of the HandlerMethod method parameter annotated ResponseBody
      See Also:
    • HANDLER_METHOD_RETURN_VALUE_ATTRIBUTE_NAME_PREFIX

      public static final String HANDLER_METHOD_RETURN_VALUE_ATTRIBUTE_NAME_PREFIX
      The prefix of the attribute name of the HandlerMethod method return value
      See Also:
  • Method Details

    • setRequestAttribute

      public static void setRequestAttribute(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, @Nullable String attributeName, @Nullable Object attributeValue)
      Set an attribute to the RequestAttributes with the specified name and value.
      Parameters:
      requestAttributes - the RequestAttributes to set the attribute
      attributeName - the name of the attribute to set
      attributeValue - the value of the attribute to set
    • getRequestAttribute

      @Nullable public static <T> T getRequestAttribute(@Nonnull org.springframework.web.context.request.RequestAttributes requestAttributes, String attributeName)
      Get an attribute from the RequestAttributes with the specified name.
      Type Parameters:
      T - the type of the attribute
      Parameters:
      requestAttributes - the RequestAttributes to get the attribute from
      attributeName - the name of the attribute to get
      Returns:
      the attribute value, or null if not found
      Throws:
      IllegalArgumentException - if the RequestAttributes or attributeName is null
    • setHandlerMethodRequestBodyArgument

      public static void setHandlerMethodRequestBodyArgument(Method method, Object requestBodyArgument)
      Set the @RequestBody method parameter in HandlerMethod to the RequestAttributes
      Parameters:
      method - Handler Method
      requestBodyArgument - @RequestBody The method parameters
    • setHandlerMethodRequestBodyArgument

      public static void setHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method, Object requestBodyArgument)
      Set the @RequestBody method parameter in HandlerMethod to the RequestAttributes
      Parameters:
      requestAttributes - RequestAttributes
      method - Handler Method
      requestBodyArgument - @RequestBody The method parameters
    • getHandlerMethodRequestBodyArgument

      @Nullable public static <T> T getHandlerMethodRequestBodyArgument(org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the @RequestBody method parameter from the RequestContextHolder.getRequestAttributes()
      Type Parameters:
      T - @RequestBody Method parameter Types
      Parameters:
      handlerMethod - HandlerMethod
      Returns:
      @RequestBody Method parameters if present, otherwise,null
    • getHandlerMethodRequestBodyArgument

      @Nullable public static <T> T getHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the @RequestBody method parameter from the RequestAttributes
      Type Parameters:
      T - @RequestBody Method parameter Types
      Parameters:
      requestAttributes - RequestAttributes
      handlerMethod - HandlerMethod
      Returns:
      @RequestBody Method parameters if present, otherwise,null
    • getHandlerMethodRequestBodyArgument

      @Nullable public static <T> T getHandlerMethodRequestBodyArgument(Method method)
      Gets the @RequestBody method parameter from the RequestContextHolder.getRequestAttributes()
      Type Parameters:
      T - @RequestBody Method parameter Types
      Parameters:
      method - Handler Method
      Returns:
      @RequestBody method parameter if present, otherwise null
    • getHandlerMethodRequestBodyArgument

      @Nullable public static <T> T getHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method)
      Gets the @RequestBody method parameter from the RequestAttributes
      Type Parameters:
      T - @RequestBody Method parameter Types
      Parameters:
      requestAttributes - RequestAttributes
      method - Handler Method
      Returns:
      @RequestBody method parameter if present, otherwise null
    • getHandlerMethodArguments

      @Nonnull public static Object[] getHandlerMethodArguments(org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
      Parameters:
      handlerMethod - HandlerMethod
      Returns:
      non-null
    • getHandlerMethodArguments

      @Nonnull public static Object[] getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the HandlerMethod method parameter
      Parameters:
      requestAttributes - RequestAttributes
      handlerMethod - HandlerMethod
      Returns:
      non-null
    • getHandlerMethodArguments

      @Nonnull public static Object[] getHandlerMethodArguments(org.springframework.core.MethodParameter parameter)
      Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
      Parameters:
      parameter - MethodParameter
      Returns:
      non-null
    • getHandlerMethodArguments

      @Nonnull public static Object[] getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.core.MethodParameter parameter)
      Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
      Parameters:
      requestAttributes - RequestAttributes
      parameter - MethodParameter
      Returns:
      non-null
    • getHandlerMethodArguments

      @Nonnull public static Object[] getHandlerMethodArguments(Method method)
      Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
      Parameters:
      method - Method
      Returns:
      non-null
    • getHandlerMethodArguments

      @Nonnull public static Object[] getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method)
      Gets the HandlerMethod method parameter
      Parameters:
      requestAttributes - RequestAttributes
      method - Method
      Returns:
      non-null
    • setHandlerMethodReturnValue

      public static void setHandlerMethodReturnValue(Method method, Object returnValue)
      Set the HandlerMethod method return value to the RequestContextHolder.getRequestAttributes()
      Parameters:
      method - Method
      returnValue - Method return value
    • setHandlerMethodReturnValue

      public static void setHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method, Object returnValue)
      Set the HandlerMethod method return value to the RequestAttributes
      Parameters:
      requestAttributes - RequestAttributes
      method - Method
      returnValue - Method return value
    • getHandlerMethodReturnValue

      @Nullable public static <T> T getHandlerMethodReturnValue(org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the value returned by the HandlerMethod method from the RequestContextHolder.getRequestAttributes()
      Type Parameters:
      T - Method return value type
      Parameters:
      handlerMethod - HandlerMethod
      Returns:
      HandlerMethod Method return value
    • getHandlerMethodReturnValue

      @Nullable public static <T> T getHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the value returned by the HandlerMethod method
      Type Parameters:
      T - Method return value type
      Parameters:
      requestAttributes - RequestAttributes
      handlerMethod - HandlerMethod
      Returns:
      HandlerMethod Method return value
    • getHandlerMethodReturnValue

      @Nullable public static <T> T getHandlerMethodReturnValue(Method method)
      Gets the value returned by the HandlerMethod method from the RequestContextHolder.getRequestAttributes()
      Type Parameters:
      T - Method return value type
      Parameters:
      method - Method
      Returns:
      HandlerMethod Method return value
    • getHandlerMethodReturnValue

      @Nullable public static <T> T getHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method)
      Gets the value returned by the HandlerMethod method
      Type Parameters:
      T - Method return value type
      Parameters:
      requestAttributes - RequestAttributes
      method - Method
      Returns:
      HandlerMethod Method return value