Package io.microsphere.spring.web.util
Class RequestAttributesUtils
java.lang.Object
io.microsphere.spring.web.util.RequestAttributesUtils
RequestAttributes Utilities Class- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe prefix of the attribute name of theHandlerMethodmethod parameterstatic final StringThe prefix of the attribute name of theHandlerMethodmethod parameter annotatedResponseBodystatic final StringThe prefix of the attribute name of theHandlerMethodmethod return value -
Method Summary
Modifier and TypeMethodDescriptionstatic Object[]getHandlerMethodArguments(Method method) Gets theHandlerMethodmethod parameter from theRequestContextHolder.getRequestAttributes()static Object[]getHandlerMethodArguments(org.springframework.core.MethodParameter parameter) Gets theHandlerMethodmethod parameter from theRequestContextHolder.getRequestAttributes()static Object[]getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method) Gets theHandlerMethodmethod parameterstatic Object[]getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.core.MethodParameter parameter) Gets theHandlerMethodmethod parameter from theRequestContextHolder.getRequestAttributes()static Object[]getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod) Gets theHandlerMethodmethod parameterstatic Object[]getHandlerMethodArguments(org.springframework.web.method.HandlerMethod handlerMethod) Gets theHandlerMethodmethod parameter from theRequestContextHolder.getRequestAttributes()static <T> TGets the@RequestBodymethod parameter from theRequestContextHolder.getRequestAttributes()static <T> TgetHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method) Gets the@RequestBodymethod parameter from theRequestAttributesstatic <T> TgetHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod) Gets the@RequestBodymethod parameter from theRequestAttributesstatic <T> TgetHandlerMethodRequestBodyArgument(org.springframework.web.method.HandlerMethod handlerMethod) Gets the@RequestBodymethod parameter from theRequestContextHolder.getRequestAttributes()static <T> TgetHandlerMethodReturnValue(Method method) Gets the value returned by theHandlerMethodmethod from theRequestContextHolder.getRequestAttributes()static <T> TgetHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method) Gets the value returned by theHandlerMethodmethodstatic <T> TgetHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, org.springframework.web.method.HandlerMethod handlerMethod) Gets the value returned by theHandlerMethodmethodstatic <T> TgetHandlerMethodReturnValue(org.springframework.web.method.HandlerMethod handlerMethod) Gets the value returned by theHandlerMethodmethod from theRequestContextHolder.getRequestAttributes()static <T> TgetRequestAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String attributeName) Get an attribute from theRequestAttributeswith the specified name.static voidsetHandlerMethodRequestBodyArgument(Method method, Object requestBodyArgument) Set the@RequestBodymethod parameter inHandlerMethodto theRequestAttributesstatic voidsetHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method, Object requestBodyArgument) Set the@RequestBodymethod parameter inHandlerMethodto theRequestAttributesstatic voidsetHandlerMethodReturnValue(Method method, Object returnValue) Set theHandlerMethodmethod return value to theRequestContextHolder.getRequestAttributes()static voidsetHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method, Object returnValue) Set theHandlerMethodmethod return value to theRequestAttributesstatic voidsetRequestAttribute(org.springframework.web.context.request.RequestAttributes requestAttributes, String attributeName, Object attributeValue) Set an attribute to theRequestAttributeswith the specified name and value.
-
Field Details
-
HANDLER_METHOD_ARGUMENTS_ATTRIBUTE_NAME_PREFIX
The prefix of the attribute name of theHandlerMethodmethod parameter- See Also:
-
HANDLER_METHOD_REQUEST_BODY_ARGUMENT_ATTRIBUTE_NAME_PREFIX
The prefix of the attribute name of theHandlerMethodmethod parameter annotatedResponseBody- See Also:
-
HANDLER_METHOD_RETURN_VALUE_ATTRIBUTE_NAME_PREFIX
The prefix of the attribute name of theHandlerMethodmethod 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 theRequestAttributeswith the specified name and value.- Parameters:
requestAttributes- theRequestAttributesto set the attributeattributeName- the name of the attribute to setattributeValue- 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 theRequestAttributeswith the specified name.- Type Parameters:
T- the type of the attribute- Parameters:
requestAttributes- theRequestAttributesto get the attribute fromattributeName- the name of the attribute to get- Returns:
- the attribute value, or
nullif not found - Throws:
IllegalArgumentException- if theRequestAttributesor attributeName is null
-
setHandlerMethodRequestBodyArgument
Set the@RequestBodymethod parameter inHandlerMethodto theRequestAttributes- Parameters:
method- HandlerMethodrequestBodyArgument-@RequestBodyThe method parameters
-
setHandlerMethodRequestBodyArgument
public static void setHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method, Object requestBodyArgument) Set the@RequestBodymethod parameter inHandlerMethodto theRequestAttributes- Parameters:
requestAttributes-RequestAttributesmethod- HandlerMethodrequestBodyArgument-@RequestBodyThe method parameters
-
getHandlerMethodRequestBodyArgument
@Nullable public static <T> T getHandlerMethodRequestBodyArgument(org.springframework.web.method.HandlerMethod handlerMethod) Gets the@RequestBodymethod parameter from theRequestContextHolder.getRequestAttributes()- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
handlerMethod-HandlerMethod- Returns:
@RequestBodyMethod 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@RequestBodymethod parameter from theRequestAttributes- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
requestAttributes-RequestAttributeshandlerMethod-HandlerMethod- Returns:
@RequestBodyMethod parameters if present, otherwise,null
-
getHandlerMethodRequestBodyArgument
Gets the@RequestBodymethod parameter from theRequestContextHolder.getRequestAttributes()- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
method- HandlerMethod- Returns:
@RequestBodymethod parameter if present, otherwisenull
-
getHandlerMethodRequestBodyArgument
@Nullable public static <T> T getHandlerMethodRequestBodyArgument(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method) Gets the@RequestBodymethod parameter from theRequestAttributes- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
requestAttributes-RequestAttributesmethod- HandlerMethod- Returns:
@RequestBodymethod parameter if present, otherwisenull
-
getHandlerMethodArguments
@Nonnull public static Object[] getHandlerMethodArguments(org.springframework.web.method.HandlerMethod handlerMethod) Gets theHandlerMethodmethod parameter from theRequestContextHolder.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 theHandlerMethodmethod parameter- Parameters:
requestAttributes-RequestAttributeshandlerMethod-HandlerMethod- Returns:
- non-null
-
getHandlerMethodArguments
@Nonnull public static Object[] getHandlerMethodArguments(org.springframework.core.MethodParameter parameter) Gets theHandlerMethodmethod parameter from theRequestContextHolder.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 theHandlerMethodmethod parameter from theRequestContextHolder.getRequestAttributes()- Parameters:
requestAttributes-RequestAttributesparameter-MethodParameter- Returns:
- non-null
-
getHandlerMethodArguments
Gets theHandlerMethodmethod parameter from theRequestContextHolder.getRequestAttributes()- Parameters:
method-Method- Returns:
- non-null
-
getHandlerMethodArguments
@Nonnull public static Object[] getHandlerMethodArguments(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method) Gets theHandlerMethodmethod parameter- Parameters:
requestAttributes-RequestAttributesmethod-Method- Returns:
- non-null
-
setHandlerMethodReturnValue
Set theHandlerMethodmethod return value to theRequestContextHolder.getRequestAttributes()- Parameters:
method-MethodreturnValue- Method return value
-
setHandlerMethodReturnValue
public static void setHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method, Object returnValue) Set theHandlerMethodmethod return value to theRequestAttributes- Parameters:
requestAttributes-RequestAttributesmethod-MethodreturnValue- Method return value
-
getHandlerMethodReturnValue
@Nullable public static <T> T getHandlerMethodReturnValue(org.springframework.web.method.HandlerMethod handlerMethod) Gets the value returned by theHandlerMethodmethod from theRequestContextHolder.getRequestAttributes()- Type Parameters:
T- Method return value type- Parameters:
handlerMethod-HandlerMethod- Returns:
HandlerMethodMethod 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 theHandlerMethodmethod- Type Parameters:
T- Method return value type- Parameters:
requestAttributes-RequestAttributeshandlerMethod-HandlerMethod- Returns:
HandlerMethodMethod return value
-
getHandlerMethodReturnValue
Gets the value returned by theHandlerMethodmethod from theRequestContextHolder.getRequestAttributes()- Type Parameters:
T- Method return value type- Parameters:
method-Method- Returns:
HandlerMethodMethod return value
-
getHandlerMethodReturnValue
@Nullable public static <T> T getHandlerMethodReturnValue(org.springframework.web.context.request.RequestAttributes requestAttributes, Method method) Gets the value returned by theHandlerMethodmethod- Type Parameters:
T- Method return value type- Parameters:
requestAttributes-RequestAttributesmethod-Method- Returns:
HandlerMethodMethod return value
-