类 AsyncResponseContext


  • public class AsyncResponseContext
    extends Object
    Async Http Response.
    • 方法详细资料

      • autoDecompress

        public AsyncResponseContext autoDecompress​(boolean autoDecompress)
        If decompress response body automatically. Default true
      • handle

        public <T> CompletableFuture<Response<T>> handle​(BodySubscriberProvider<T> subscriberProvider)
        Handle the response, return a response future. If any exceptions were thrown during call handler, will return a exceptional Future.
        类型参数:
        T - return value type
        参数:
        subscriberProvider - provide a BodySubscriber to handle the body
      • handle

        public <T,​R> CompletableFuture<Response<R>> handle​(BodySubscriberProvider<T> subscriberProvider,
                                                                 Function<? super T,​? extends R> mapper)
        Handle the response using a BodySubscriber, then transformed the result by the function mapper. If any exceptions were thrown during call handler, will return a exceptional Future.
        类型参数:
        R - return value type
        参数:
        subscriberProvider - provider the BodySubscriber to handle the response
        mapper - the function to convert the body get by the BodySubscriber
      • readToString

        public CompletableFuture<Response<String>> readToString​(Charset charset)
        Collect the response body as String.
        参数:
        charset - the charset used to decode response body.
        返回:
        the response Future
      • readToString

        public CompletableFuture<Response<String>> readToString()
        Collect the response body as String. This method would get charset from response headers. If not set, would use UTF-8.
        返回:
        the response Future
      • readToBytes

        public CompletableFuture<Response<byte[]>> readToBytes()
        Collect the response body to byte array.
        返回:
        the response Future
      • decodeJson

        public <T> CompletableFuture<Response<T>> decodeJson​(Class<T> type)
        Unmarshal response body as json. This method would get charset from response headers. If not set, would use UTF-8.
        类型参数:
        T - The json value type
      • decodeJson

        public <T> CompletableFuture<Response<T>> decodeJson​(net.dongliu.commons.reflect.TypeInfer<T> typeInfer)
        Unmarshal response body as json. This method would get charset from response headers. If not set, would use UTF-8.
        类型参数:
        T - The json value type
        参数:
        typeInfer - for getting actual generic type
      • decodeJson

        public <T> CompletableFuture<Response<T>> decodeJson​(Class<T> type,
                                                             Charset charset)
        Unmarshal response body as json.
        类型参数:
        T - The json value type
        参数:
        charset - the charset used to decode response body.
      • decodeJson

        public <T> CompletableFuture<Response<T>> decodeJson​(net.dongliu.commons.reflect.TypeInfer<T> typeInfer,
                                                             Charset charset)
        Unmarshal response body as json
        类型参数:
        T - The json value type
        参数:
        charset - the charset used to decode response body.
        typeInfer - for getting actual generic type