Interface SpringWebHelper

All Known Implementing Classes:
UnknownSpringWebHelper

public interface SpringWebHelper
The helper interface for Spring Web
Since:
1.0.0
Author:
Mercy
See Also:
  • WebRequest
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addCookie(org.springframework.web.context.request.NativeWebRequest request, String cookieName, String cookieValue)
    Adds the specified cookie to the response.
    void
    addHeader(org.springframework.web.context.request.NativeWebRequest request, String headerName, String... headerValues)
    Adds a response header with the given name and value.
    getBestMatchingHandler(org.springframework.web.context.request.NativeWebRequest request)
    Get the mapped handler for the best matching pattern.
    getBestMatchingPattern(org.springframework.web.context.request.NativeWebRequest request)
    Get the best matching pattern within the handler mapping.
    getCookieValue(org.springframework.web.context.request.NativeWebRequest request, String cookieName)
    Get the cookie value for the given cookie name.
    default String
    getHeader(org.springframework.web.context.request.NativeWebRequest request, String headerName)
    Get the header value from the request by the given header name.
    default String[]
    getHeaderValues(org.springframework.web.context.request.NativeWebRequest request, String headerName)
    Get the header values from the request by the given header name.
    Map<String,org.springframework.util.MultiValueMap<String,String>>
    getMatrixVariables(org.springframework.web.context.request.NativeWebRequest request)
    Get a map with URI variable names and a corresponding MultiValueMap of URI matrix variables for each.
    getMethod(org.springframework.web.context.request.NativeWebRequest request)
    Get the HTTP method of the request
    getPathWithinHandlerMapping(org.springframework.web.context.request.NativeWebRequest request)
    Get the path within the handler mapping, in case of a pattern match, or the full relevant URI (typically within the DispatcherServlet's mapping) else.
    Set<org.springframework.http.MediaType>
    getProducibleMediaTypes(org.springframework.web.context.request.NativeWebRequest request)
    Get the set of producible MediaTypes applicable to the mapped handler.
    default <T> T
    getRequestBody(org.springframework.web.context.request.NativeWebRequest request, Class<T> requestBodyType)
    Get the request body for the given request body type.
    Get the Spring Web Type
    getUriTemplateVariables(org.springframework.web.context.request.NativeWebRequest request)
    Get the URI templates map, mapping variable names to values.
    void
    setHeader(org.springframework.web.context.request.NativeWebRequest request, String headerName, String headerValue)
    Sets a response header with the given name and value.
    default void
    writeResponseBody(org.springframework.web.context.request.NativeWebRequest request, String name, String value)
    Write value to the response body.
  • Method Details

    • getMethod

      @Nullable String getMethod(@Nonnull org.springframework.web.context.request.NativeWebRequest request)
      Get the HTTP method of the request
      Parameters:
      request - the NativeWebRequest
      Returns:
      the HTTP method if found, otherwise null
      See Also:
      • HttpServletRequest.getMethod()
      • HttpRequest.getMethod()
    • getHeader

      @Nullable default String getHeader(@Nonnull org.springframework.web.context.request.NativeWebRequest request, String headerName)
      Get the header value from the request by the given header name.
      Parameters:
      request - the NativeWebRequest
      headerName - the name of header
      Returns:
      the header value if found, otherwise null
      See Also:
      • HttpServletRequest.getHeader(String)
      • HttpMessage.getHeaders()
      • HttpHeaders.getFirst(String)
    • getHeaderValues

      @Nullable default String[] getHeaderValues(@Nonnull org.springframework.web.context.request.NativeWebRequest request, String headerName)
      Get the header values from the request by the given header name.
      Parameters:
      request - the NativeWebRequest
      headerName - the name of header
      Returns:
      the header values if found, otherwise null
      See Also:
      • HttpServletRequest.getHeaders(String)
      • HttpMessage.getHeaders()
      • HttpHeaders.get(Object)
    • setHeader

      void setHeader(@Nonnull org.springframework.web.context.request.NativeWebRequest request, @Nullable String headerName, @Nullable String headerValue)
      Sets a response header with the given name and value. If the header had already been set, the new value overwrites all previous values.
      Parameters:
      request - the NativeWebRequest
      headerName - the name of header
      headerValue - the header value
      See Also:
      • HttpServletResponse.setHeader(String, String)
      • HttpHeaders.set(String, String)
    • addHeader

      void addHeader(@Nonnull org.springframework.web.context.request.NativeWebRequest request, @Nullable String headerName, @Nullable String... headerValues)
      Adds a response header with the given name and value. This method allows response headers to have multiple values.
      Parameters:
      request - the NativeWebRequest
      headerName - the name of header
      headerValues - the header values
      See Also:
      • HttpServletResponse.addHeader(String, String)
      • HttpHeaders.add(String, String)
    • getCookieValue

      @Nullable String getCookieValue(@Nonnull org.springframework.web.context.request.NativeWebRequest request, String cookieName)
      Get the cookie value for the given cookie name.
      Parameters:
      request - the NativeWebRequest
      cookieName - the name of Cookie
      Returns:
      the cookie value if found, otherwise null
      See Also:
      • HttpServletRequest.getCookies()
      • ServerHttpRequest.getCookies()
    • addCookie

      void addCookie(@Nonnull org.springframework.web.context.request.NativeWebRequest request, String cookieName, String cookieValue)
      Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.
      Parameters:
      request - the NativeWebRequest
      cookieName - the name of Cookie
      cookieValue - the cookie value
      See Also:
      • HttpServletResponse.addCookie(Cookie)
      • ServerHttpResponse.addCookie(ResponseCookie)
    • getRequestBody

      default <T> T getRequestBody(@Nonnull org.springframework.web.context.request.NativeWebRequest request, Class<T> requestBodyType)
      Get the request body for the given request body type.
      Type Parameters:
      T - the type of request body
      Parameters:
      request - the NativeWebRequest
      requestBodyType - the request body type
      Returns:
      the request body if found, otherwise null
      See Also:
      • RequestBody
      • org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor#resolveArgument
      • org.springframework.web.reactive.result.method.annotation.RequestBodyMethodArgumentResolver#resolveArgument
    • writeResponseBody

      default void writeResponseBody(@Nonnull org.springframework.web.context.request.NativeWebRequest request, String name, String value)
      Write value to the response body.
      Parameters:
      request - the NativeWebRequest
      name - the name
      value - the value
    • getBestMatchingHandler

      @Nullable Object getBestMatchingHandler(@Nonnull org.springframework.web.context.request.NativeWebRequest request)
      Get the mapped handler for the best matching pattern.
      Parameters:
      request - the NativeWebRequest
      Returns:
      the mapped handler for the best matching pattern if found, otherwise null
      See Also:
      • HandlerMethod
      • org.springframework.web.servlet.function.RouterFunction
      • org.springframework.web.reactive.function.server.RouterFunction
      • org.springframework.web.servlet.HandlerMapping#getHandler
      • org.springframework.web.reactive.HandlerMapping#getHandler
      • org.springframework.web.servlet.HandlerMapping#BEST_MATCHING_HANDLER_ATTRIBUTE
      • org.springframework.web.reactive.HandlerMapping#BEST_MATCHING_HANDLER_ATTRIBUTE
    • getPathWithinHandlerMapping

      @Nullable String getPathWithinHandlerMapping(@Nonnull org.springframework.web.context.request.NativeWebRequest request)
      Get the path within the handler mapping, in case of a pattern match, or the full relevant URI (typically within the DispatcherServlet's mapping) else.
      Parameters:
      request - the NativeWebRequest
      Returns:
      the path within handler mapping if found, otherwise null
      See Also:
      • org.springframework.web.servlet.handler.AbstractUrlHandlerMapping#exposePathWithinMapping
      • org.springframework.web.reactive.handler.AbstractUrlHandlerMapping#lookupHandler
      • org.springframework.web.servlet.HandlerMapping#PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
      • org.springframework.web.reactive.HandlerMapping#PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
    • getBestMatchingPattern

      @Nullable String getBestMatchingPattern(@Nonnull org.springframework.web.context.request.NativeWebRequest request)
      Get the best matching pattern within the handler mapping.
      Parameters:
      request - the NativeWebRequest
      Returns:
      the best matching pattern within the handler mapping if found, otherwise null
      See Also:
      • RequestMapping.path()
      • org.springframework.web.servlet.handler.AbstractUrlHandlerMapping#exposePathWithinMapping
      • org.springframework.web.reactive.handler.AbstractUrlHandlerMapping#lookupHandler
      • org.springframework.web.servlet.HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE
      • org.springframework.web.reactive.HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE
    • getUriTemplateVariables

      @Nullable Map<String,String> getUriTemplateVariables(@Nonnull org.springframework.web.context.request.NativeWebRequest request)
      Get the URI templates map, mapping variable names to values.
      Parameters:
      request - the NativeWebRequest
      Returns:
      the URI template variables if found, otherwise null
      See Also:
      • PathVariable
      • org.springframework.web.servlet.handler.AbstractUrlHandlerMapping#exposeUriTemplateVariables
      • org.springframework.web.reactive.handler.AbstractUrlHandlerMapping#lookupHandler
      • org.springframework.web.servlet.HandlerMapping#URI_TEMPLATE_VARIABLES_ATTRIBUTE
      • org.springframework.web.reactive.HandlerMapping#URI_TEMPLATE_VARIABLES_ATTRIBUTE
    • getMatrixVariables

      @Nullable Map<String,org.springframework.util.MultiValueMap<String,String>> getMatrixVariables(@Nonnull org.springframework.web.context.request.NativeWebRequest request)
      Get a map with URI variable names and a corresponding MultiValueMap of URI matrix variables for each.
      Parameters:
      request - the NativeWebRequest
      Returns:
      the matrix variables if found, otherwise null
      See Also:
      • MatrixVariable
      • org.springframework.web.servlet.mvc.method.annotation.MatrixVariableMapMethodArgumentResolver#resolveArgument
      • org.springframework.web.reactive.result.method.annotation.MatrixVariableMapMethodArgumentResolver#resolveArgumentValue
      • org.springframework.web.servlet.HandlerMapping#MATRIX_VARIABLES_ATTRIBUTE
      • org.springframework.web.reactive.HandlerMapping#MATRIX_VARIABLES_ATTRIBUTE
    • getProducibleMediaTypes

      @Nullable Set<org.springframework.http.MediaType> getProducibleMediaTypes(@Nonnull org.springframework.web.context.request.NativeWebRequest request)
      Get the set of producible MediaTypes applicable to the mapped handler.
      Parameters:
      request - the NativeWebRequest
      Returns:
      the producible media types if found, otherwise null
      See Also:
      • RequestMapping.produces()
      • org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping#handleMatch
      • org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping#handleMatch
      • org.springframework.web.servlet.HandlerMapping#PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
      • org.springframework.web.reactive.HandlerMapping#PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
    • getType

      @Nonnull SpringWebType getType()
      Get the Spring Web Type
      Returns:
      SpringWebType