Class WebMvcUtils
java.lang.Object
io.microsphere.spring.webmvc.util.WebMvcUtils
Spring Web MVC Utilities Class
- Since:
- 1.0.0
- Author:
- Mercy
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
appendContextInitializerClassInitParameter
(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer> contextInitializerClass) Append initialized parameter forContext Initializer Class
static void
appendFrameworkServletContextInitializerClassInitParameter
(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer> contextInitializerClass) Append initialized parameter forContext Initializer Class
intoFrameworkServlet
static void
appendGlobalInitializerClassInitParameter
(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer> contextInitializerClass) Append initialized parameter forGlobal Initializer Class
protected static String
appendInitParameter
(String existedParameterValue, String... parameterValues) static void
appendInitParameters
(jakarta.servlet.ServletContext servletContext, String parameterName, String... parameterValues) AppendServletContext Intialized Parameters
static Object[]
getHandlerMethodArguments
(jakarta.servlet.ServletRequest request, Method method) Gets theHandlerMethod
method parameterstatic Object[]
getHandlerMethodArguments
(jakarta.servlet.ServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets theHandlerMethod
method parameterstatic Object[]
getHandlerMethodArguments
(Method method) Gets theHandlerMethod
method parameterstatic Object[]
getHandlerMethodArguments
(org.springframework.web.context.request.WebRequest webRequest, Method method) static Object[]
getHandlerMethodArguments
(org.springframework.web.context.request.WebRequest webRequest, org.springframework.core.MethodParameter parameter) static Object[]
getHandlerMethodArguments
(org.springframework.web.context.request.WebRequest webRequest, org.springframework.web.method.HandlerMethod handlerMethod) static <T> T
getHandlerMethodRequestBodyArgument
(jakarta.servlet.ServletRequest request, Method method) Gets the@RequestBody
method parameter from theServletRequest
contextstatic <T> T
getHandlerMethodRequestBodyArgument
(jakarta.servlet.ServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets the@RequestBody
method parameter from theServletRequest
contextstatic <T> T
getHandlerMethodReturnValue
(jakarta.servlet.ServletRequest request, Method method) Gets the value returned by theHandlerMethod
methodstatic <T> T
getHandlerMethodReturnValue
(jakarta.servlet.ServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets the value returned by theHandlerMethod
methodstatic <T> T
getHandlerMethodReturnValue
(Method method) Gets the value returned by theHandlerMethod
methodstatic jakarta.servlet.http.HttpServletRequest
Gets the currentHttpServletRequest
objectstatic jakarta.servlet.http.HttpServletRequest
getHttpServletRequest
(org.springframework.web.context.request.WebRequest webRequest) static org.springframework.web.context.WebApplicationContext
Gets theWebApplicationContext
associated with the current Servlet Request requeststatic org.springframework.web.context.WebApplicationContext
getWebApplicationContext
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.ServletContext servletContext) Get theWebApplicationContext
fromHttpServletRequest
static boolean
isControllerAdviceBeanType
(Class<?> beanType) Determine whether the Bean Type is present annotated byControllerAdvice
static boolean
isPageRenderRequest
(org.springframework.web.servlet.ModelAndView modelAndView) Is page render requeststatic void
setHandlerMethodRequestBodyArgument
(jakarta.servlet.ServletRequest request, Method method, Object requestBodyArgument) Set the@RequestBody
method parameter inHandlerMethod
to theServletRequest
contextstatic void
setHandlerMethodRequestBodyArgument
(Method method, Object requestBodyArgument) Set the@RequestBody
method parameter inHandlerMethod
to theServletRequest
contextstatic void
setHandlerMethodReturnValue
(jakarta.servlet.http.HttpServletRequest request, Method method, Object returnValue)
-
Field Details
-
HANDLER_METHOD_ARGUMENTS_ATTRIBUTE_NAME_PREFIX
- See Also:
-
HANDLER_METHOD_REQUEST_BODY_ARGUMENT_ATTRIBUTE_NAME_PREFIX
- See Also:
-
HANDLER_METHOD_RETURN_VALUE_ATTRIBUTE_NAME_PREFIX
- See Also:
-
supportedConverterTypes
-
-
Constructor Details
-
WebMvcUtils
public WebMvcUtils()
-
-
Method Details
-
getHttpServletRequest
public static jakarta.servlet.http.HttpServletRequest getHttpServletRequest() throws IllegalStateExceptionGets the currentHttpServletRequest
objectBy default,
HttpServletRequest
is initialized inRequestContextFilter
,HttpServletRequest
from the Servlet HTTP request threadThreadLocal
is obtained fromInheritableThreadLocal
and can be obtained in the child thread.- Returns:
null
returns the current
HttpServletRequest
object.- Throws:
IllegalStateException
-
getHttpServletRequest
public static jakarta.servlet.http.HttpServletRequest getHttpServletRequest(org.springframework.web.context.request.WebRequest webRequest) -
getWebApplicationContext
public static org.springframework.web.context.WebApplicationContext getWebApplicationContext() throws IllegalStateExceptionGets theWebApplicationContext
associated with the current Servlet Request request- Returns:
- Current Servlet Request associated with
WebApplicationContext
- Throws:
IllegalStateException
- In a non-Web scenario, an exception is thrown
-
setHandlerMethodRequestBodyArgument
Set the@RequestBody
method parameter inHandlerMethod
to theServletRequest
context- Parameters:
method
- HandlerMethod
requestBodyArgument
-@RequestBody
The method parameters
-
setHandlerMethodReturnValue
-
setHandlerMethodRequestBodyArgument
public static void setHandlerMethodRequestBodyArgument(jakarta.servlet.ServletRequest request, Method method, Object requestBodyArgument) Set the@RequestBody
method parameter inHandlerMethod
to theServletRequest
context- Parameters:
request
-ServletRequest
method
- HandlerMethod
requestBodyArgument
-@RequestBody
The method parameters
-
getHandlerMethodRequestBodyArgument
public static <T> T getHandlerMethodRequestBodyArgument(jakarta.servlet.ServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets the@RequestBody
method parameter from theServletRequest
context- Type Parameters:
T
-@RequestBody
Method parameter Types- Parameters:
request
-ServletRequest
handlerMethod
-HandlerMethod
- Returns:
@RequestBody
Method parameters if present, otherwise,null
-
getHandlerMethodRequestBodyArgument
public static <T> T getHandlerMethodRequestBodyArgument(jakarta.servlet.ServletRequest request, Method method) Gets the@RequestBody
method parameter from theServletRequest
context- Type Parameters:
T
-@RequestBody
Method parameter Types- Parameters:
request
-ServletRequest
method
- HandlerMethod
- Returns:
@RequestBody
method parameter if present, otherwisenull
-
getHandlerMethodArguments
public static Object[] getHandlerMethodArguments(org.springframework.web.context.request.WebRequest webRequest, org.springframework.web.method.HandlerMethod handlerMethod) -
getHandlerMethodArguments
public static Object[] getHandlerMethodArguments(org.springframework.web.context.request.WebRequest webRequest, org.springframework.core.MethodParameter parameter) -
getHandlerMethodArguments
-
getHandlerMethodArguments
public static Object[] getHandlerMethodArguments(jakarta.servlet.ServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets theHandlerMethod
method parameter- Parameters:
request
-ServletRequest
handlerMethod
-HandlerMethod
- Returns:
- non-null
-
getHandlerMethodArguments
public static Object[] getHandlerMethodArguments(jakarta.servlet.ServletRequest request, Method method) Gets theHandlerMethod
method parameter- Parameters:
request
-ServletRequest
method
-Method
- Returns:
- non-null
-
getHandlerMethodArguments
Gets theHandlerMethod
method parameter- Parameters:
method
-Method
- Returns:
- non-null
-
getHandlerMethodReturnValue
public static <T> T getHandlerMethodReturnValue(jakarta.servlet.ServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets the value returned by theHandlerMethod
method- Type Parameters:
T
- Method return value type- Parameters:
request
-ServletRequest
handlerMethod
-HandlerMethod
- Returns:
HandlerMethod
Method return value
-
getHandlerMethodReturnValue
public static <T> T getHandlerMethodReturnValue(jakarta.servlet.ServletRequest request, Method method) Gets the value returned by theHandlerMethod
method- Type Parameters:
T
- Method return value type- Parameters:
request
-ServletRequest
method
-Method
- Returns:
HandlerMethod
Method return value
-
getHandlerMethodReturnValue
Gets the value returned by theHandlerMethod
method- Type Parameters:
T
- Method return value type- Parameters:
method
-Method
- Returns:
HandlerMethod
Method return value
-
isControllerAdviceBeanType
Determine whether the Bean Type is present annotated byControllerAdvice
- Parameters:
beanType
- Bean Type- Returns:
- If
ControllerAdvice
bean type is present , returntrue
, orfalse
.
-
getWebApplicationContext
public static org.springframework.web.context.WebApplicationContext getWebApplicationContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.ServletContext servletContext) Get theWebApplicationContext
fromHttpServletRequest
- Parameters:
request
-HttpServletRequest
servletContext
-ServletContext
- Returns:
WebApplicationContext
- Throws:
IllegalStateException
- if no servlet-specific context has been found- See Also:
-
RequestContextUtils#getWebApplicationContext(ServletRequest)
DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE
-
appendInitParameter
-
appendInitParameters
public static void appendInitParameters(jakarta.servlet.ServletContext servletContext, String parameterName, String... parameterValues) AppendServletContext Intialized Parameters
- Parameters:
servletContext
-ServletContext
parameterName
- the name of init parameterparameterValues
- the values of init parameters
-
appendGlobalInitializerClassInitParameter
public static void appendGlobalInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer> contextInitializerClass) Append initialized parameter forGlobal Initializer Class
- Parameters:
servletContext
-ServletContext
contextInitializerClass
- the class ofApplicationContextInitializer
- See Also:
-
ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM
-
appendContextInitializerClassInitParameter
public static void appendContextInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer> contextInitializerClass) Append initialized parameter forContext Initializer Class
- Parameters:
servletContext
-ServletContext
contextInitializerClass
- the class ofApplicationContextInitializer
- See Also:
-
ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM
-
appendFrameworkServletContextInitializerClassInitParameter
public static void appendFrameworkServletContextInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer> contextInitializerClass) Append initialized parameter forContext Initializer Class
intoFrameworkServlet
- Parameters:
servletContext
-ServletContext
contextInitializerClass
- the class ofApplicationContextInitializer
- See Also:
-
FrameworkServlet.applyInitializers(ConfigurableApplicationContext)
-
isPageRenderRequest
public static boolean isPageRenderRequest(org.springframework.web.servlet.ModelAndView modelAndView) Is page render request- Parameters:
modelAndView
-ModelAndView
- Returns:
- If current request is for page render , return
true
, orfalse
.
-