Skip to content

Commit 895817f

Browse files
committed
fix:使用HttpComponents时若不配置proxy password启动报错问题
1 parent 521d46d commit 895817f

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelServiceHttpComponentsImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import me.chanjar.weixin.channel.config.WxChannelConfig;
66
import me.chanjar.weixin.channel.util.JsonUtils;
77
import me.chanjar.weixin.common.util.http.HttpClientType;
8-
import me.chanjar.weixin.common.util.http.apache.ApacheBasicResponseHandler;
98
import me.chanjar.weixin.common.util.http.hc.BasicResponseHandler;
109
import me.chanjar.weixin.common.util.http.hc.DefaultHttpComponentsClientBuilder;
1110
import me.chanjar.weixin.common.util.http.hc.HttpComponentsClientBuilder;
@@ -41,7 +40,7 @@ public void initHttp() {
4140
apacheHttpClientBuilder.httpProxyHost(config.getHttpProxyHost())
4241
.httpProxyPort(config.getHttpProxyPort())
4342
.httpProxyUsername(config.getHttpProxyUsername())
44-
.httpProxyPassword(config.getHttpProxyPassword().toCharArray());
43+
.httpProxyPassword(config.getHttpProxyPassword() == null ? null : config.getHttpProxyPassword().toCharArray());
4544

4645
if (config.getHttpProxyHost() != null && config.getHttpProxyPort() > 0) {
4746
this.httpProxy = new HttpHost(config.getHttpProxyHost(), config.getHttpProxyPort());

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceHttpComponentsImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public void initHttp() {
8282
apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
8383
.httpProxyPort(this.configStorage.getHttpProxyPort())
8484
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
85-
.httpProxyPassword(this.configStorage.getHttpProxyPassword().toCharArray());
85+
.httpProxyPassword(this.configStorage.getHttpProxyPassword() == null ? null :
86+
this.configStorage.getHttpProxyPassword().toCharArray());
8687

8788
if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
8889
this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/impl/WxCpCgServiceHttpComponentsImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public void initHttp() {
3535
apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
3636
.httpProxyPort(this.configStorage.getHttpProxyPort())
3737
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
38-
.httpProxyPassword(this.configStorage.getHttpProxyPassword().toCharArray());
38+
.httpProxyPassword(this.configStorage.getHttpProxyPassword() == null ? null :
39+
this.configStorage.getHttpProxyPassword().toCharArray());
3940

4041
if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
4142
this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceHttpComponentsImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import me.chanjar.weixin.common.util.http.hc.DefaultHttpComponentsClientBuilder;
1111
import me.chanjar.weixin.common.util.http.hc.HttpComponentsClientBuilder;
1212
import me.chanjar.weixin.common.util.json.GsonParser;
13-
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
1413
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
1514
import org.apache.hc.client5.http.classic.methods.HttpPost;
1615
import org.apache.hc.client5.http.config.RequestConfig;
@@ -87,9 +86,10 @@ public void initHttp() {
8786
HttpComponentsClientBuilder apacheHttpClientBuilder = DefaultHttpComponentsClientBuilder.get();
8887

8988
apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
90-
.httpProxyPort(this.configStorage.getHttpProxyPort())
91-
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
92-
.httpProxyPassword(this.configStorage.getHttpProxyPassword().toCharArray());
89+
.httpProxyPort(this.configStorage.getHttpProxyPort())
90+
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
91+
.httpProxyPassword(this.configStorage.getHttpProxyPassword() == null ? null :
92+
this.configStorage.getHttpProxyPassword().toCharArray());
9393

9494
if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
9595
this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceHttpComponentsImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public void initHttp() {
5151
apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost())
5252
.httpProxyPort(configStorage.getHttpProxyPort())
5353
.httpProxyUsername(configStorage.getHttpProxyUsername())
54-
.httpProxyPassword(configStorage.getHttpProxyPassword().toCharArray());
54+
.httpProxyPassword(configStorage.getHttpProxyPassword() == null ? null :
55+
configStorage.getHttpProxyPassword().toCharArray());
5556

5657
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
5758
this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());

weixin-java-qidian/src/main/java/me/chanjar/weixin/qidian/api/impl/WxQidianServiceHttpComponentsImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ public void initHttp() {
4848
HttpComponentsClientBuilder apacheHttpClientBuilder = DefaultHttpComponentsClientBuilder.get();
4949

5050
apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost())
51-
.httpProxyPort(configStorage.getHttpProxyPort()).httpProxyUsername(configStorage.getHttpProxyUsername())
52-
.httpProxyPassword(configStorage.getHttpProxyPassword().toCharArray());
51+
.httpProxyPort(configStorage.getHttpProxyPort())
52+
.httpProxyUsername(configStorage.getHttpProxyUsername())
53+
.httpProxyPassword(configStorage.getHttpProxyPassword() == null ? null :
54+
configStorage.getHttpProxyPassword().toCharArray());
5355

5456
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
5557
this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());

0 commit comments

Comments
 (0)