refactor: HttpClient 线程安全, 可以全局复用, 也可配置自定义的 httpClient 到 WxClient.#85
refactor: HttpClient 线程安全, 可以全局复用, 也可配置自定义的 httpClient 到 WxClient.#85howareyouo wants to merge 2 commits intoborball:masterfrom howareyouo:master
Conversation
|
@howareyouo Thanks for the PR. WxClient might have multiple instances in the system especially for a SaaS provider, i.g. they have multiple clientIds. I understand your main purpose for this PR is to provide the API users a possibility to customize their own HTTP client implementation, in this way they can set proxy or something was not considered in the default one. One solution to achieve this, not sure if you are able to implement.
public interface HttpClientsHolder {
/**
* Get a map of ClientId:HttpClient mapping
* key shall be WX clientId, value shall be the HttpClient this clientId suppose to use
*
* @return
*/
Map<String, HttpClient> getHttpClients();
}
|
|
Your solution sounds ok to me, I shall do this by you way. |
refactor: HttpClient 线程安全, 可以全局复用.
见文档: https://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e213
也可以在初始化
WxClient前通过setDefaultHttpClient指定自定义的 HttpClient.例如集成
hoverfly-java进行单元测试时, 通过HttpClients.createSystem()创建遵循系统代理设置的httpclient对微信接口返回数据进行自动 mock.