Class AbstractHttpClient

java.lang.Object
com.wechat.pay.java.core.http.AbstractHttpClient
All Implemented Interfaces:
HttpClient
Direct Known Subclasses:
ApacheHttpClientAdapter, OkHttpClientAdapter

public abstract class AbstractHttpClient extends Object implements HttpClient
请求客户端抽象基类
  • Field Details

    • credential

      protected final Credential credential
    • validator

      protected final Validator validator
  • Constructor Details

  • Method Details

    • execute

      public <T> HttpResponse<T> execute(HttpRequest httpRequest, Class<T> responseClass)
      Description copied from interface: HttpClient
      发送HTTP请求
      Specified by:
      execute in interface HttpClient
      Type Parameters:
      T - 由Class对象建模的类的类型
      Parameters:
      httpRequest - HTTP请求
      responseClass - 业务返回类的Class对象,如果不确定业务返回类型,或该请求没有返回体,可以传入Object.class
      Returns:
      HTTP返回
    • download

      public InputStream download(String url)
      Description copied from interface: HttpClient
      下载文件,文件流使用完后需要关闭
      Specified by:
      download in interface HttpClient
      Parameters:
      url - 请求URL
      Returns:
      文件流
    • innerDownload

      protected abstract InputStream innerDownload(HttpRequest httpRequest)
    • innerExecute

      protected abstract OriginalResponse innerExecute(HttpRequest httpRequest)
    • isInvalidHttpCode

      protected boolean isInvalidHttpCode(int httpCode)
    • getHttpClientInfo

      protected abstract String getHttpClientInfo()
      获取http客户端信息,用于User-Agent。 格式:客户端名称/版本 示例:okhttp3/4.9.3
      Returns:
      客户端信息