From 82e23718473e6acf99cea5717465b69391029ef7 Mon Sep 17 00:00:00 2001 From: 007gzs <007gzs@gmail.com> Date: Tue, 26 Jun 2018 13:53:55 +0800 Subject: [PATCH] =?UTF-8?q?#644=20WxOpenConfigStorage=E5=A2=9E=E5=8A=A0set?= =?UTF-8?q?ApacheHttpClientBuilder()=E6=96=B9=E6=B3=95=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9http=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=9B=B8=E5=85=B3=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/open/api/WxOpenConfigStorage.java | 3 +++ .../api/impl/WxOpenInMemoryConfigStorage.java | 12 ++++++++++- .../WxOpenServiceApacheHttpClientImpl.java | 20 ++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java index b0d833b2..de9044ee 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.open.api; import cn.binarywang.wx.miniapp.config.WxMaConfig; +import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; @@ -46,6 +47,8 @@ public interface WxOpenConfigStorage { String getHttpProxyPassword(); + ApacheHttpClientBuilder getApacheHttpClientBuilder(); + WxMpConfigStorage getWxMpConfigStorage(String appId); WxMaConfig getWxMaConfig(String appId); diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java index 56e1d9a1..8c521970 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java @@ -34,6 +34,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage { private int httpProxyPort; private String httpProxyUsername; private String httpProxyPassword; + private ApacheHttpClientBuilder apacheHttpClientBuilder; private Map authorizerRefreshTokens = new Hashtable<>(); private Map authorizerAccessTokens = new Hashtable<>(); @@ -146,6 +147,15 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage { this.httpProxyPassword = httpProxyPassword; } + @Override + public ApacheHttpClientBuilder getApacheHttpClientBuilder() { + return apacheHttpClientBuilder; + } + + public ApacheHttpClientBuilder setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) { + return this.apacheHttpClientBuilder = apacheHttpClientBuilder; + } + @Override public WxMpConfigStorage getWxMpConfigStorage(String appId) { return new WxOpenInnerConfigStorage(this, appId); @@ -448,7 +458,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage { @Override public ApacheHttpClientBuilder getApacheHttpClientBuilder() { - return null; + return wxOpenConfigStorage.getApacheHttpClientBuilder(); } diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java index e428af56..d9b7b495 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceApacheHttpClientImpl.java @@ -4,7 +4,9 @@ import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.http.HttpType; import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; +import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.open.api.WxOpenConfigStorage; import org.apache.http.HttpHost; import org.apache.http.impl.client.CloseableHttpClient; @@ -21,14 +23,22 @@ public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl @Override public void initHttp() { WxOpenConfigStorage configStorage = this.getWxOpenConfigStorage(); - if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) { - this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort()); + ApacheHttpClientBuilder apacheHttpClientBuilder = configStorage.getApacheHttpClientBuilder(); + if (null == apacheHttpClientBuilder) { + apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get(); } - this.httpClient = DefaultApacheHttpClientBuilder.get() - .httpProxyHost(configStorage.getHttpProxyHost()) + + apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost()) .httpProxyPort(configStorage.getHttpProxyPort()) .httpProxyUsername(configStorage.getHttpProxyUsername()) - .httpProxyPassword(configStorage.getHttpProxyPassword()).build(); + .httpProxyPassword(configStorage.getHttpProxyPassword()); + + if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) { + this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort()); + } + + this.httpClient = apacheHttpClientBuilder.build(); + } @Override