Skip to content

请解决httpClient连接池关闭的问题 #3601

Open
@talentluke

Description

@talentluke

com.github.binarywang.wxpay.service.impl.WxPayServiceApacheHttpImpl这个类里面存在大量 try (CloseableHttpClient httpClient = this.createApiV3HttpClient();当出现异常时,httpClient的close方法会关闭连接池,导致下次请求报错,异常情况,不应该关闭连接池吧

例如,postV3WithWechatpaySerial方法

public String postV3WithWechatpaySerial(String url, String requestStr) throws WxPayException {
HttpPost httpPost = this.createHttpPost(url, requestStr);
this.configureRequest(httpPost);
try (CloseableHttpClient httpClient = this.createApiV3HttpClient();
CloseableHttpResponse response = httpClient.execute(httpPost)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
String responseString = "{}";
HttpEntity entity = response.getEntity();
if (entity != null) {
responseString = EntityUtils.toString(entity, StandardCharsets.UTF_8);
}

  if (HttpStatus.SC_OK == statusCode || HttpStatus.SC_NO_CONTENT == statusCode) {
    this.logRequestAndResponse(url, requestStr, responseString);
    return responseString;
  }

  //有错误提示信息返回
  JsonObject jsonObject = GsonParser.parse(responseString);
  throw convertException(jsonObject);
} catch (Exception e) {
  this.logError(url, requestStr, e);
  throw (e instanceof WxPayException) ? (WxPayException) e : new WxPayException(e.getMessage(), e);
} finally {
  httpPost.releaseConnection();
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions