Class WebMvcUtils

java.lang.Object
io.microsphere.spring.webmvc.util.WebMvcUtils
All Implemented Interfaces:
io.microsphere.util.Utils

public abstract class WebMvcUtils extends Object implements io.microsphere.util.Utils
Spring Web MVC Utilities Class
Since:
1.0.0
Author:
Mercy
  • Field Details

    • SUPPORTED_CONVERTER_TYPES

      public static final Set<Class<? extends org.springframework.http.converter.HttpMessageConverter<?>>> SUPPORTED_CONVERTER_TYPES
      The supported HttpMessageConverter types
    • INIT_PARAM_DELIMITERS

      public static final String INIT_PARAM_DELIMITERS
      Any number of these characters are considered delimiters between multiple values in a single init-param String value.
      See Also:
  • Method Details

    • getHttpServletRequest

      @Nullable public static jakarta.servlet.http.HttpServletRequest getHttpServletRequest() throws IllegalStateException
      Gets the current HttpServletRequest object

      By default, HttpServletRequest is initialized in RequestContextFilter, HttpServletRequest from the Servlet HTTP request thread ThreadLocal is obtained from InheritableThreadLocal and can be obtained in the child thread.

      Returns:
      null returns the current HttpServletRequest object.
      Throws:
      IllegalStateException
    • getHttpServletRequest

      @Nullable public static jakarta.servlet.http.HttpServletRequest getHttpServletRequest(org.springframework.web.context.request.RequestAttributes requestAttributes)
    • getWebApplicationContext

      @Nonnull public static org.springframework.web.context.WebApplicationContext getWebApplicationContext() throws IllegalStateException
      Gets the WebApplicationContext 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
    • getWebApplicationContext

      @Nullable public static org.springframework.web.context.WebApplicationContext getWebApplicationContext(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.ServletContext servletContext)
      Get the WebApplicationContext from HttpServletRequest
      Parameters:
      request - HttpServletRequest
      servletContext - ServletContext
      Returns:
      WebApplicationContext
      Throws:
      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(Method method, Object requestBodyArgument)
      Set the @RequestBody method parameter in HandlerMethod to the HttpServletRequest context
      Parameters:
      method - Handler Method
      requestBodyArgument - @RequestBody The method parameters
    • setHandlerMethodRequestBodyArgument

      public static void setHandlerMethodRequestBodyArgument(jakarta.servlet.http.HttpServletRequest request, Method method, Object requestBodyArgument)
      Set the @RequestBody method parameter in HandlerMethod to the HttpServletRequest context
      Parameters:
      request - HttpServletRequest
      method - Handler Method
      requestBodyArgument - @RequestBody The method parameters
    • setHandlerMethodReturnValue

      public static void setHandlerMethodReturnValue(Method method, Object returnValue)
      Set the return value of the HandlerMethod to the HttpServletRequest context
      Parameters:
      method - Handler Method
      returnValue - The return value
    • setHandlerMethodReturnValue

      public static void setHandlerMethodReturnValue(jakarta.servlet.http.HttpServletRequest request, Method method, Object returnValue)
      Set the return value of the HandlerMethod to the HttpServletRequest context
      Parameters:
      request - HttpServletRequest
      method - Handler Method
      returnValue - The return value
    • getHandlerMethodRequestBodyArgument

      @Nullable public static <T> T getHandlerMethodRequestBodyArgument(org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the @RequestBody method parameter from the HttpServletRequest context
      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(jakarta.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod)
      Gets the @RequestBody method parameter from the HttpServletRequest context
      Type Parameters:
      T - @RequestBody Method parameter Types
      Parameters:
      request - HttpServletRequest
      handlerMethod - HandlerMethod
      Returns:
      @RequestBody Method parameters if present, otherwise,null
    • getHandlerMethodRequestBodyArgument

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

      @Nonnull public static <T> T getHandlerMethodRequestBodyArgument(jakarta.servlet.http.HttpServletRequest request, Method method)
      Gets the @RequestBody method parameter from the HttpServletRequest context
      Type Parameters:
      T - @RequestBody Method parameter Types
      Parameters:
      request - HttpServletRequest
      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
      Parameters:
      handlerMethod - HandlerMethod
      Returns:
      non-null
    • getHandlerMethodArguments

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

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

      @Nonnull public static Object[] getHandlerMethodArguments(jakarta.servlet.http.HttpServletRequest request, Method method)
      Gets the HandlerMethod method parameter
      Parameters:
      request - HttpServletRequest
      method - Method
      Returns:
      non-null
    • getHandlerMethodReturnValue

      @Nullable public static <T> T getHandlerMethodReturnValue(org.springframework.web.method.HandlerMethod handlerMethod)
    • getHandlerMethodReturnValue

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

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

      @Nullable public static <T> T getHandlerMethodReturnValue(jakarta.servlet.http.HttpServletRequest request, Method method)
      Gets the value returned by the HandlerMethod method
      Type Parameters:
      T - Method return value type
      Parameters:
      request - HttpServletRequest
      method - Method
      Returns:
      HandlerMethod Method return value
    • isControllerAdviceBeanType

      public static boolean isControllerAdviceBeanType(Class<?> beanType)
      Determine whether the Bean Type is present annotated by ControllerAdvice
      Parameters:
      beanType - Bean Type
      Returns:
      If ControllerAdvice bean type is present , return true , or false.
    • setInitParameters

      public static void setInitParameters(jakarta.servlet.ServletContext servletContext, String parameterName, String... parameterValues)
      Sets ServletContext Intialized Parameters
      Parameters:
      servletContext - ServletContext
      parameterName - the name of init parameter
      parameterValues - the values of init parameters
    • setGlobalInitializerClassInitParameter

      public static void setGlobalInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses)
      Sets the initialized parameter for Global Initializer Class
      Parameters:
      servletContext - ServletContext
      contextInitializerClasses - the classes of ApplicationContextInitializer
      See Also:
      • ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM
    • setContextInitializerClassInitParameter

      public static void setContextInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses)
      Sets the initialized parameter for Context Initializer Class
      Parameters:
      servletContext - ServletContext
      contextInitializerClasses - the classes of ApplicationContextInitializer
      See Also:
      • ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM
    • setFrameworkServletContextInitializerClassInitParameter

      public static void setFrameworkServletContextInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses)
      Sets initialized parameter for Context Initializer Class into FrameworkServlet
      Parameters:
      servletContext - ServletContext
      contextInitializerClasses - the classes of ApplicationContextInitializer
      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 , or false.
    • getClassNames

      protected static String[] getClassNames(Class<?>... classes)