Class RequestAttributesUtils


  • public abstract class RequestAttributesUtils
    extends java.lang.Object
    RequestAttributes Utilities Class
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    RequestAttributesUtils
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object[] getHandlerMethodArguments​(java.lang.reflect.Method method)
      Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
      static java.lang.Object[] getHandlerMethodArguments​(org.springframework.core.MethodParameter parameter)
      Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
      static java.lang.Object[] getHandlerMethodArguments​(org.springframework.web.context.request.RequestAttributes requestAttributes, java.lang.reflect.Method method)
      Gets the HandlerMethod method parameter
      static java.lang.Object[] getHandlerMethodArguments​(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.core.MethodParameter parameter)
      Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
      static java.lang.Object[] getHandlerMethodArguments​(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the HandlerMethod method parameter
      static java.lang.Object[] getHandlerMethodArguments​(org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
      static <T> T getHandlerMethodRequestBodyArgument​(java.lang.reflect.Method method)
      Gets the @RequestBody method parameter from the RequestContextHolder.getRequestAttributes()
      static <T> T getHandlerMethodRequestBodyArgument​(org.springframework.web.context.request.RequestAttributes requestAttributes, java.lang.reflect.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 getHandlerMethodReturnValue​(java.lang.reflect.Method method)
      Gets the value returned by the HandlerMethod method from the RequestContextHolder.getRequestAttributes()
      static <T> T getHandlerMethodReturnValue​(org.springframework.web.context.request.RequestAttributes requestAttributes, java.lang.reflect.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, java.lang.String attributeName)
      Get an attribute from the RequestAttributes with the specified name.
      static void setHandlerMethodRequestBodyArgument​(java.lang.reflect.Method method, java.lang.Object requestBodyArgument)
      Set the @RequestBody method parameter in HandlerMethod to the RequestAttributes
      static void setHandlerMethodRequestBodyArgument​(org.springframework.web.context.request.RequestAttributes requestAttributes, java.lang.reflect.Method method, java.lang.Object requestBodyArgument)
      Set the @RequestBody method parameter in HandlerMethod to the RequestAttributes
      static void setHandlerMethodReturnValue​(java.lang.reflect.Method method, java.lang.Object returnValue)
      Set the HandlerMethod method return value to the RequestContextHolder.getRequestAttributes()
      static void setHandlerMethodReturnValue​(org.springframework.web.context.request.RequestAttributes requestAttributes, java.lang.reflect.Method method, java.lang.Object returnValue)
      Set the HandlerMethod method return value to the RequestAttributes
      static void setRequestAttribute​(org.springframework.web.context.request.RequestAttributes requestAttributes, java.lang.String attributeName, java.lang.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 Detail

      • HANDLER_METHOD_ARGUMENTS_ATTRIBUTE_NAME_PREFIX

        public static final java.lang.String HANDLER_METHOD_ARGUMENTS_ATTRIBUTE_NAME_PREFIX
        The prefix of the attribute name of the HandlerMethod method parameter
        See Also:
        Constant Field Values
      • HANDLER_METHOD_REQUEST_BODY_ARGUMENT_ATTRIBUTE_NAME_PREFIX

        public static final java.lang.String HANDLER_METHOD_REQUEST_BODY_ARGUMENT_ATTRIBUTE_NAME_PREFIX
        The prefix of the attribute name of the HandlerMethod method parameter annotated ResponseBody
        See Also:
        Constant Field Values
      • HANDLER_METHOD_RETURN_VALUE_ATTRIBUTE_NAME_PREFIX

        public static final java.lang.String HANDLER_METHOD_RETURN_VALUE_ATTRIBUTE_NAME_PREFIX
        The prefix of the attribute name of the HandlerMethod method return value
        See Also:
        Constant Field Values
    • Method Detail

      • setRequestAttribute

        public static void setRequestAttribute​(@Nonnull
                                               org.springframework.web.context.request.RequestAttributes requestAttributes,
                                               @Nullable
                                               java.lang.String attributeName,
                                               @Nullable
                                               java.lang.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,
                                                java.lang.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:
        java.lang.IllegalArgumentException - if the RequestAttributes or attributeName is null
      • setHandlerMethodRequestBodyArgument

        public static void setHandlerMethodRequestBodyArgument​(java.lang.reflect.Method method,
                                                               java.lang.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,
                                                               java.lang.reflect.Method method,
                                                               java.lang.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​(java.lang.reflect.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,
                                                                java.lang.reflect.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.Object[] getHandlerMethodArguments​(java.lang.reflect.Method method)
        Gets the HandlerMethod method parameter from the RequestContextHolder.getRequestAttributes()
        Parameters:
        method - Method
        Returns:
        non-null
      • getHandlerMethodArguments

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

        public static void setHandlerMethodReturnValue​(java.lang.reflect.Method method,
                                                       java.lang.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,
                                                       java.lang.reflect.Method method,
                                                       java.lang.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​(java.lang.reflect.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,
                                                        java.lang.reflect.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