类 DefaultApiClient


  • public class DefaultApiClient
    extends Object
    1. 管理token 2. 解析请求参数 3. 发送HTTP请求 4. 解析请求结果 create by getui on 2020/6/2
    作者:
    getui
    • 方法详细资料

      • beforeExecute

        protected void beforeExecute​(GtApiProxyFactory.ApiParam apiParam,
                                     Map<String,​Object> header,
                                     String body)
        执行http调用之前调用此方法
        参数:
        apiParam - 请求参数
        header - 请求header
        body - 请求body
      • execute

        public ApiResult<?> execute​(GtApiProxyFactory.ApiParam apiParam)
        1. 调用接口 2. 如果返回token失效,刷新token后再次调用
        参数:
        apiParam -
        返回:
      • postExecute

        protected void postExecute​(GtApiProxyFactory.ApiParam apiParam,
                                   Map<String,​Object> header,
                                   String body,
                                   String result)
        调用远程接口后调用此方法,如果报错则不会调用
        参数:
        apiParam - http请求的参数
        header - http请求的header
        body - http请求的body
      • handleException

        protected void handleException​(GtApiProxyFactory.ApiParam apiParam,
                                       Map<String,​Object> header,
                                       String body,
                                       ApiException e)
        调用远程接口报错后调用此方法
        参数:
        apiParam - http请求的参数
        header - http请求的header
        body - http请求的body
        e - http请求抛出的异常
      • afterDoExecute

        protected void afterDoExecute​(GtApiProxyFactory.ApiParam apiParam,
                                      Map<String,​Object> header,
                                      String body,
                                      String result)
        调用接口后调用此方法
        参数:
        apiParam - http请求的参数
        header - http请求的header
        body - http请求的body
        result - http请求的返回值
      • setJson

        public void setJson​(IJson json)
      • close

        public void close()
        释放 cache中的对象,但是此对象仍然可以使用,直到没有内存引用被回收
      • setAuthApiAndAuth

        public void setAuthApiAndAuth​(AuthApi authApi)