类 WebUtils


  • public class WebUtils
    extends java.lang.Object
    web utils.
    作者:
    nkorange
    • 字段概要

      字段 
      修饰符和类型 字段 说明
      private static java.lang.String COMMA  
      private static java.lang.String ENCODING_KEY  
      private static java.lang.String SEMI  
      private static java.lang.String TMP_SUFFIX  
    • 构造器概要

      构造器 
      构造器 说明
      WebUtils()  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static java.lang.String getAcceptEncoding​(javax.servlet.http.HttpServletRequest req)
      get accept encode from request.
      static java.lang.String getUserAgent​(javax.servlet.http.HttpServletRequest request)
      Returns the value of the request header "user-agent" as a String.
      static void onFileUpload​(org.springframework.web.multipart.MultipartFile multipartFile, java.util.function.Consumer<java.io.File> consumer, org.springframework.web.context.request.async.DeferredResult<com.alibaba.nacos.common.model.RestResult<java.lang.String>> response)
      Handle file upload operations.
      static java.lang.String optional​(javax.servlet.http.HttpServletRequest req, java.lang.String key, java.lang.String defaultValue)
      get target value from parameterMap, if not found will return default value.
      static <T> void process​(org.springframework.web.context.request.async.DeferredResult<T> deferredResult, java.util.concurrent.CompletableFuture<T> future, java.lang.Runnable success, java.util.function.Function<java.lang.Throwable,​T> errorHandler)
      Register DeferredResult in the callback of CompletableFuture.
      static <T> void process​(org.springframework.web.context.request.async.DeferredResult<T> deferredResult, java.util.concurrent.CompletableFuture<T> future, java.util.function.Function<java.lang.Throwable,​T> errorHandler)
      Register DeferredResult in the callback of CompletableFuture.
      static java.lang.String required​(javax.servlet.http.HttpServletRequest req, java.lang.String key)
      get target value from parameterMap, if not found will throw IllegalArgumentException.
      private static java.lang.String resolveValue​(java.lang.String value, java.lang.String encoding)
      decode target value.
      private static java.lang.String resolveValueWithUrlDecode​(java.lang.String value, java.lang.String encoding)
      decode target value with UrlDecode.
      static void response​(javax.servlet.http.HttpServletResponse response, java.lang.String body, int code)
      response data to client.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • ENCODING_KEY

        private static final java.lang.String ENCODING_KEY
        另请参阅:
        常量字段值
      • COMMA

        private static final java.lang.String COMMA
        另请参阅:
        常量字段值
      • SEMI

        private static final java.lang.String SEMI
        另请参阅:
        常量字段值
      • TMP_SUFFIX

        private static final java.lang.String TMP_SUFFIX
        另请参阅:
        常量字段值
    • 构造器详细资料

      • WebUtils

        public WebUtils()
    • 方法详细资料

      • required

        public static java.lang.String required​(javax.servlet.http.HttpServletRequest req,
                                                java.lang.String key)
        get target value from parameterMap, if not found will throw IllegalArgumentException.
        参数:
        req - HttpServletRequest
        key - key
        返回:
        value
      • optional

        public static java.lang.String optional​(javax.servlet.http.HttpServletRequest req,
                                                java.lang.String key,
                                                java.lang.String defaultValue)
        get target value from parameterMap, if not found will return default value.
        参数:
        req - HttpServletRequest
        key - key
        defaultValue - default value
        返回:
        value
      • resolveValue

        private static java.lang.String resolveValue​(java.lang.String value,
                                                     java.lang.String encoding)
        decode target value.
        参数:
        value - value
        encoding - encode
        返回:
        Decoded data
      • resolveValueWithUrlDecode

        private static java.lang.String resolveValueWithUrlDecode​(java.lang.String value,
                                                                  java.lang.String encoding)
        decode target value with UrlDecode.

        Under Content-Type:application/x-www-form-urlencoded situation.

        参数:
        value - value
        encoding - encode
        返回:
        Decoded data
      • getAcceptEncoding

        public static java.lang.String getAcceptEncoding​(javax.servlet.http.HttpServletRequest req)
        get accept encode from request.
        参数:
        req - HttpServletRequest
        返回:
        accept encode
      • getUserAgent

        public static java.lang.String getUserAgent​(javax.servlet.http.HttpServletRequest request)
        Returns the value of the request header "user-agent" as a String.
        参数:
        request - HttpServletRequest
        返回:
        the value of the request header "user-agent", or the value of the request header "client-version" if the request does not have a header of "user-agent".
      • response

        public static void response​(javax.servlet.http.HttpServletResponse response,
                                    java.lang.String body,
                                    int code)
                             throws java.io.IOException
        response data to client.
        参数:
        response - HttpServletResponse
        body - body
        code - http code
        抛出:
        java.io.IOException - IOException
      • onFileUpload

        public static void onFileUpload​(org.springframework.web.multipart.MultipartFile multipartFile,
                                        java.util.function.Consumer<java.io.File> consumer,
                                        org.springframework.web.context.request.async.DeferredResult<com.alibaba.nacos.common.model.RestResult<java.lang.String>> response)
        Handle file upload operations.
        参数:
        multipartFile - file
        consumer - post processor
        response - DeferredResult
      • process

        public static <T> void process​(org.springframework.web.context.request.async.DeferredResult<T> deferredResult,
                                       java.util.concurrent.CompletableFuture<T> future,
                                       java.util.function.Function<java.lang.Throwable,​T> errorHandler)
        Register DeferredResult in the callback of CompletableFuture.
        类型参数:
        T - target type
        参数:
        deferredResult - DeferredResult
        future - CompletableFuture
        errorHandler - Function
      • process

        public static <T> void process​(org.springframework.web.context.request.async.DeferredResult<T> deferredResult,
                                       java.util.concurrent.CompletableFuture<T> future,
                                       java.lang.Runnable success,
                                       java.util.function.Function<java.lang.Throwable,​T> errorHandler)
        Register DeferredResult in the callback of CompletableFuture.
        类型参数:
        T - target type
        参数:
        deferredResult - DeferredResult
        future - CompletableFuture
        success - if future success, callback runnable
        errorHandler - Function