Skip to content

Commit

Permalink
# 215
Browse files Browse the repository at this point in the history
  • Loading branch information
liyi committed Oct 29, 2019
1 parent a276acf commit 41f8b49
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ WEIXIN-POPULAR CHANGELOG
===========================
https://github.com/liyiorg/weixin-popular

Changes in version 2.8.29 (2019-10-29)
-------------------------------------
* #215 添加HttpClient 代理配置

Changes in version 2.8.28 (2019-07-26)
-------------------------------------
* #199 刷卡支付 授权码查询OPENID接口 添加返回字段sub_openid
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.liyiorg</groupId>
<artifactId>weixin-popular</artifactId>
<version>2.8.28</version>
<version>2.8.29</version>

<name>weixin-popular</name>
<description>The weixin-popular is a JAVA SDK for weixin. Weixin web url is https://mp.weixin.qq.com.</description>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/weixin/popular/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface Version {

String VERSION = "2.8.28";
String VERSION = "2.8.29";
}
38 changes: 28 additions & 10 deletions src/main/java/weixin/popular/client/HttpClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.net.ssl.SSLException;

import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.protocol.HttpClientContext;
Expand All @@ -38,9 +39,20 @@ public class HttpClientFactory{

private static final String[] supportedProtocols = new String[]{"TLSv1"};

private static HttpHost proxy;

public static CloseableHttpClient createHttpClient() {
return createHttpClient(100,10,5000,2);
}

/**
* 设置代理
* @since 2.8.29
* @param proxy 代理
*/
public static void setProxy(HttpHost proxy){
HttpClientFactory.proxy = proxy;
}

/**
*
Expand All @@ -59,11 +71,14 @@ public static CloseableHttpClient createHttpClient(int maxTotal,int maxPerRoute,
poolingHttpClientConnectionManager.setDefaultMaxPerRoute(maxPerRoute);
SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(timeout).build();
poolingHttpClientConnectionManager.setDefaultSocketConfig(socketConfig);
return HttpClientBuilder.create()
.setConnectionManager(poolingHttpClientConnectionManager)
.setSSLSocketFactory(sf)
.setRetryHandler(new HttpRequestRetryHandlerImpl(retryExecutionCount))
.build();
HttpClientBuilder builder = HttpClientBuilder.create();
if(proxy != null){
builder.setProxy(proxy);
}
return builder.setConnectionManager(poolingHttpClientConnectionManager)
.setSSLSocketFactory(sf)
.setRetryHandler(new HttpRequestRetryHandlerImpl(retryExecutionCount))
.build();
} catch (KeyManagementException e) {
logger.error("", e);
} catch (NoSuchAlgorithmException e) {
Expand Down Expand Up @@ -99,11 +114,14 @@ public static CloseableHttpClient createKeyMaterialHttpClient(KeyStore keystore,
SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslContext,supportedProtocols,
null,SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(timeout).build();
return HttpClientBuilder.create()
.setDefaultSocketConfig(socketConfig)
.setSSLSocketFactory(sf)
.setRetryHandler(new HttpRequestRetryHandlerImpl(retryExecutionCount))
.build();
HttpClientBuilder builder = HttpClientBuilder.create();
if(proxy != null){
builder.setProxy(proxy);
}
return builder.setDefaultSocketConfig(socketConfig)
.setSSLSocketFactory(sf)
.setRetryHandler(new HttpRequestRetryHandlerImpl(retryExecutionCount))
.build();
} catch (KeyManagementException e) {
logger.error("", e);
} catch (NoSuchAlgorithmException e) {
Expand Down

0 comments on commit 41f8b49

Please sign in to comment.