Class WebMvcUtils
- java.lang.Object
-
- io.microsphere.spring.webmvc.util.WebMvcUtils
-
- All Implemented Interfaces:
io.microsphere.util.Utils
public abstract class WebMvcUtils extends java.lang.Object implements io.microsphere.util.UtilsSpring Web MVC Utilities Class- Since:
- 1.0.0
- Author:
- Mercy
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringINIT_PARAM_DELIMITERSAny number of these characters are considered delimiters between multiple values in a single init-param String value.static java.util.Set<java.lang.Class<? extends org.springframework.http.converter.HttpMessageConverter<?>>>SUPPORTED_CONVERTER_TYPESThe supportedHttpMessageConvertertypes
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static java.lang.String[]getClassNames(java.lang.Class<?>... classes)static java.lang.Object[]getHandlerMethodArguments(java.lang.reflect.Method method)Gets theHandlerMethodmethod parameterstatic java.lang.Object[]getHandlerMethodArguments(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method)Gets theHandlerMethodmethod parameterstatic java.lang.Object[]getHandlerMethodArguments(javax.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod)Gets theHandlerMethodmethod parameterstatic java.lang.Object[]getHandlerMethodArguments(org.springframework.web.method.HandlerMethod handlerMethod)Gets theHandlerMethodmethod parameterstatic <T> TgetHandlerMethodRequestBodyArgument(java.lang.reflect.Method method)Gets the@RequestBodymethod parameter from theHttpServletRequestcontextstatic <T> TgetHandlerMethodRequestBodyArgument(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method)Gets the@RequestBodymethod parameter from theHttpServletRequestcontextstatic <T> TgetHandlerMethodRequestBodyArgument(javax.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod)Gets the@RequestBodymethod parameter from theHttpServletRequestcontextstatic <T> TgetHandlerMethodRequestBodyArgument(org.springframework.web.method.HandlerMethod handlerMethod)Gets the@RequestBodymethod parameter from theHttpServletRequestcontextstatic <T> TgetHandlerMethodReturnValue(java.lang.reflect.Method method)Gets the value returned by theHandlerMethodmethodstatic <T> TgetHandlerMethodReturnValue(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method)Gets the value returned by theHandlerMethodmethodstatic <T> TgetHandlerMethodReturnValue(javax.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod)Gets the value returned by theHandlerMethodmethodstatic <T> TgetHandlerMethodReturnValue(org.springframework.web.method.HandlerMethod handlerMethod)static javax.servlet.http.HttpServletRequestgetHttpServletRequest()Gets the currentHttpServletRequestobjectstatic javax.servlet.http.HttpServletRequestgetHttpServletRequest(org.springframework.web.context.request.RequestAttributes requestAttributes)static org.springframework.web.context.WebApplicationContextgetWebApplicationContext()Gets theWebApplicationContextassociated with the current Servlet Request requeststatic org.springframework.web.context.WebApplicationContextgetWebApplicationContext(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext servletContext)Get theWebApplicationContextfromHttpServletRequeststatic booleanisControllerAdviceBeanType(java.lang.Class<?> beanType)Determine whether the Bean Type is present annotated byControllerAdvicestatic booleanisPageRenderRequest(org.springframework.web.servlet.ModelAndView modelAndView)Is page render requeststatic voidsetContextInitializerClassInitParameter(javax.servlet.ServletContext servletContext, java.lang.Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses)Sets the initialized parameter forContext Initializer Classstatic voidsetFrameworkServletContextInitializerClassInitParameter(javax.servlet.ServletContext servletContext, java.lang.Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses)Sets initialized parameter forContext Initializer ClassintoFrameworkServletstatic voidsetGlobalInitializerClassInitParameter(javax.servlet.ServletContext servletContext, java.lang.Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses)Sets the initialized parameter forGlobal Initializer Classstatic voidsetHandlerMethodRequestBodyArgument(java.lang.reflect.Method method, java.lang.Object requestBodyArgument)Set the@RequestBodymethod parameter inHandlerMethodto theHttpServletRequestcontextstatic voidsetHandlerMethodRequestBodyArgument(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method, java.lang.Object requestBodyArgument)Set the@RequestBodymethod parameter inHandlerMethodto theHttpServletRequestcontextstatic voidsetHandlerMethodReturnValue(java.lang.reflect.Method method, java.lang.Object returnValue)Set the return value of theHandlerMethodto theHttpServletRequestcontextstatic voidsetHandlerMethodReturnValue(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method, java.lang.Object returnValue)Set the return value of theHandlerMethodto theHttpServletRequestcontextstatic voidsetInitParameters(javax.servlet.ServletContext servletContext, java.lang.String parameterName, java.lang.String... parameterValues)SetsServletContext Intialized Parameters
-
-
-
Field Detail
-
SUPPORTED_CONVERTER_TYPES
public static final java.util.Set<java.lang.Class<? extends org.springframework.http.converter.HttpMessageConverter<?>>> SUPPORTED_CONVERTER_TYPES
The supportedHttpMessageConvertertypes
-
INIT_PARAM_DELIMITERS
public static final java.lang.String INIT_PARAM_DELIMITERS
Any number of these characters are considered delimiters between multiple values in a single init-param String value.- See Also:
ContextLoader.INIT_PARAM_DELIMITERS, Constant Field Values
-
-
Method Detail
-
getHttpServletRequest
@Nullable public static javax.servlet.http.HttpServletRequest getHttpServletRequest() throws java.lang.IllegalStateExceptionGets the currentHttpServletRequestobjectBy default,
HttpServletRequestis initialized inRequestContextFilter,HttpServletRequestfrom the Servlet HTTP request threadThreadLocalis obtained fromInheritableThreadLocaland can be obtained in the child thread.- Returns:
nullreturns the currentHttpServletRequestobject.- Throws:
java.lang.IllegalStateException
-
getHttpServletRequest
@Nullable public static javax.servlet.http.HttpServletRequest getHttpServletRequest(org.springframework.web.context.request.RequestAttributes requestAttributes)
-
getWebApplicationContext
@Nonnull public static org.springframework.web.context.WebApplicationContext getWebApplicationContext() throws java.lang.IllegalStateExceptionGets theWebApplicationContextassociated with the current Servlet Request request- Returns:
- Current Servlet Request associated with
WebApplicationContext - Throws:
java.lang.IllegalStateException- In a non-Web scenario, an exception is thrown
-
getWebApplicationContext
@Nullable public static org.springframework.web.context.WebApplicationContext getWebApplicationContext(javax.servlet.http.HttpServletRequest request, @Nullable javax.servlet.ServletContext servletContext)Get theWebApplicationContextfromHttpServletRequest- Parameters:
request-HttpServletRequestservletContext-ServletContext- Returns:
WebApplicationContext- Throws:
java.lang.IllegalStateException- if no servlet-specific context has been found- See Also:
RequestContextUtils#getWebApplicationContext(HttpServletRequest),RequestContextUtils.findWebApplicationContext(HttpServletRequest, ServletContext),DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE
-
setHandlerMethodRequestBodyArgument
public static void setHandlerMethodRequestBodyArgument(java.lang.reflect.Method method, java.lang.Object requestBodyArgument)Set the@RequestBodymethod parameter inHandlerMethodto theHttpServletRequestcontext- Parameters:
method- HandlerMethodrequestBodyArgument-@RequestBodyThe method parameters
-
setHandlerMethodRequestBodyArgument
public static void setHandlerMethodRequestBodyArgument(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method, java.lang.Object requestBodyArgument)Set the@RequestBodymethod parameter inHandlerMethodto theHttpServletRequestcontext- Parameters:
request-HttpServletRequestmethod- HandlerMethodrequestBodyArgument-@RequestBodyThe method parameters
-
setHandlerMethodReturnValue
public static void setHandlerMethodReturnValue(java.lang.reflect.Method method, java.lang.Object returnValue)Set the return value of theHandlerMethodto theHttpServletRequestcontext- Parameters:
method- HandlerMethodreturnValue- The return value
-
setHandlerMethodReturnValue
public static void setHandlerMethodReturnValue(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method, java.lang.Object returnValue)Set the return value of theHandlerMethodto theHttpServletRequestcontext- Parameters:
request-HttpServletRequestmethod- HandlerMethodreturnValue- The return value
-
getHandlerMethodRequestBodyArgument
@Nullable public static <T> T getHandlerMethodRequestBodyArgument(org.springframework.web.method.HandlerMethod handlerMethod)
Gets the@RequestBodymethod parameter from theHttpServletRequestcontext- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
handlerMethod-HandlerMethod- Returns:
@RequestBodyMethod parameters if present, otherwise,null
-
getHandlerMethodRequestBodyArgument
@Nullable public static <T> T getHandlerMethodRequestBodyArgument(javax.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod)Gets the@RequestBodymethod parameter from theHttpServletRequestcontext- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
request-HttpServletRequesthandlerMethod-HandlerMethod- Returns:
@RequestBodyMethod parameters if present, otherwise,null
-
getHandlerMethodRequestBodyArgument
@Nonnull public static <T> T getHandlerMethodRequestBodyArgument(java.lang.reflect.Method method)
Gets the@RequestBodymethod parameter from theHttpServletRequestcontext- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
method- HandlerMethod- Returns:
@RequestBodymethod parameter if present, otherwisenull
-
getHandlerMethodRequestBodyArgument
@Nonnull public static <T> T getHandlerMethodRequestBodyArgument(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method)Gets the@RequestBodymethod parameter from theHttpServletRequestcontext- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
request-HttpServletRequestmethod- HandlerMethod- Returns:
@RequestBodymethod parameter if present, otherwisenull
-
getHandlerMethodArguments
@Nonnull public static java.lang.Object[] getHandlerMethodArguments(org.springframework.web.method.HandlerMethod handlerMethod)
Gets theHandlerMethodmethod parameter- Parameters:
handlerMethod-HandlerMethod- Returns:
- non-null
-
getHandlerMethodArguments
@Nonnull public static java.lang.Object[] getHandlerMethodArguments(javax.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod)Gets theHandlerMethodmethod parameter- Parameters:
request-HttpServletRequesthandlerMethod-HandlerMethod- Returns:
- non-null
-
getHandlerMethodArguments
@Nonnull public static java.lang.Object[] getHandlerMethodArguments(java.lang.reflect.Method method)
Gets theHandlerMethodmethod parameter- Parameters:
method-HandlerMethod- Returns:
- non-null
-
getHandlerMethodArguments
@Nonnull public static java.lang.Object[] getHandlerMethodArguments(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method)Gets theHandlerMethodmethod parameter- Parameters:
request-HttpServletRequestmethod-Method- Returns:
- non-null
-
getHandlerMethodReturnValue
@Nullable public static <T> T getHandlerMethodReturnValue(org.springframework.web.method.HandlerMethod handlerMethod)
-
getHandlerMethodReturnValue
@Nullable public static <T> T getHandlerMethodReturnValue(javax.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod)Gets the value returned by theHandlerMethodmethod- Type Parameters:
T- Method return value type- Parameters:
request-HttpServletRequesthandlerMethod-HandlerMethod- Returns:
HandlerMethodMethod return value
-
getHandlerMethodReturnValue
@Nullable public static <T> T getHandlerMethodReturnValue(java.lang.reflect.Method method)
Gets the value returned by theHandlerMethodmethod- Type Parameters:
T- Method return value type- Parameters:
method-Method- Returns:
HandlerMethodMethod return value
-
getHandlerMethodReturnValue
@Nullable public static <T> T getHandlerMethodReturnValue(javax.servlet.http.HttpServletRequest request, java.lang.reflect.Method method)Gets the value returned by theHandlerMethodmethod- Type Parameters:
T- Method return value type- Parameters:
request-HttpServletRequestmethod-Method- Returns:
HandlerMethodMethod return value
-
isControllerAdviceBeanType
public static boolean isControllerAdviceBeanType(java.lang.Class<?> beanType)
Determine whether the Bean Type is present annotated byControllerAdvice- Parameters:
beanType- Bean Type- Returns:
- If
ControllerAdvicebean type is present , returntrue, orfalse.
-
setInitParameters
public static void setInitParameters(javax.servlet.ServletContext servletContext, java.lang.String parameterName, java.lang.String... parameterValues)SetsServletContext Intialized Parameters- Parameters:
servletContext-ServletContextparameterName- the name of init parameterparameterValues- the values of init parameters
-
setGlobalInitializerClassInitParameter
public static void setGlobalInitializerClassInitParameter(javax.servlet.ServletContext servletContext, java.lang.Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses)Sets the initialized parameter forGlobal Initializer Class- Parameters:
servletContext-ServletContextcontextInitializerClasses- the classes ofApplicationContextInitializer- See Also:
ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM
-
setContextInitializerClassInitParameter
public static void setContextInitializerClassInitParameter(javax.servlet.ServletContext servletContext, java.lang.Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses)Sets the initialized parameter forContext Initializer Class- Parameters:
servletContext-ServletContextcontextInitializerClasses- the classes ofApplicationContextInitializer- See Also:
ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM
-
setFrameworkServletContextInitializerClassInitParameter
public static void setFrameworkServletContextInitializerClassInitParameter(javax.servlet.ServletContext servletContext, java.lang.Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses)Sets initialized parameter forContext Initializer ClassintoFrameworkServlet- Parameters:
servletContext-ServletContextcontextInitializerClasses- the classes 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.
-
getClassNames
protected static java.lang.String[] getClassNames(java.lang.Class<?>... classes)
-
-