Class RestClient

java.lang.Object
com.flyfish.oauth.client.RestClient

public final class RestClient extends Object
Rest请求客户端
Author:
Mr.Wang

1. 全builder调用,用户系统内部相互通信 2. 支持异步回调 3. 多样性组合 4. 解耦实现

  • Method Details

    • create

      public static RestClient.RestClientBuilder create()
    • destroy

      public static void destroy()
      销毁单例资源
    • onError

      public RestClient onError(Consumer<RestClient.RestClientException> errorConsumer)
      设置请求失败时的回调
      Parameters:
      errorConsumer - 错误回调
      Returns:
      结果
    • responseType

      public RestClient responseType(com.flyfish.oauth.client.RestClient.ResponseType responseType)
      设置响应类型
      Parameters:
      responseType - 响应类型
      Returns:
      结果
    • execute

      public void execute(Consumer<org.apache.http.HttpEntity> consumer)
      异步执行,接收结果
      Parameters:
      consumer - 结果
    • executeForMap

      public Map<String,Object> executeForMap() throws IOException
      执行请求,返回Map
      Returns:
      map
      Throws:
      IOException - 异常
    • executeForString

      public String executeForString() throws IOException
      执行请求,返回字符串
      Returns:
      字符串
      Throws:
      IOException - 异常
    • execute

      public <T> T execute() throws IOException
      执行请求,返回响应实体,自行处理
      Returns:
      响应实体
      Throws:
      IOException - 异常
    • execute

      public <T> T execute(com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
      执行请求,根据type引用实例化
      Type Parameters:
      T - 泛型
      Parameters:
      typeReference - 类型引用
      Returns:
      结果