mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
修复checkstyle检查出来的部分代码问题
This commit is contained in:
@@ -4,51 +4,41 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
/**
|
||||
* httpclient build interface
|
||||
* httpclient build interface.
|
||||
*
|
||||
* @author kakotor
|
||||
*/
|
||||
public interface ApacheHttpClientBuilder {
|
||||
|
||||
/**
|
||||
* 构建httpclient实例
|
||||
* 构建httpclient实例.
|
||||
*
|
||||
* @return new instance of CloseableHttpClient
|
||||
*/
|
||||
CloseableHttpClient build();
|
||||
|
||||
/**
|
||||
* 代理服务器地址
|
||||
*
|
||||
* @param httpProxyHost
|
||||
* 代理服务器地址.
|
||||
*/
|
||||
ApacheHttpClientBuilder httpProxyHost(String httpProxyHost);
|
||||
|
||||
/**
|
||||
* 代理服务器端口
|
||||
*
|
||||
* @param httpProxyPort
|
||||
* 代理服务器端口.
|
||||
*/
|
||||
ApacheHttpClientBuilder httpProxyPort(int httpProxyPort);
|
||||
|
||||
/**
|
||||
* 代理服务器用户名
|
||||
*
|
||||
* @param httpProxyUsername
|
||||
* 代理服务器用户名.
|
||||
*/
|
||||
ApacheHttpClientBuilder httpProxyUsername(String httpProxyUsername);
|
||||
|
||||
/**
|
||||
* 代理服务器密码
|
||||
*
|
||||
* @param httpProxyPassword
|
||||
* 代理服务器密码.
|
||||
*/
|
||||
ApacheHttpClientBuilder httpProxyPassword(String httpProxyPassword);
|
||||
|
||||
/**
|
||||
* ssl连接socket工厂
|
||||
*
|
||||
* @param sslConnectionSocketFactory
|
||||
* ssl连接socket工厂.
|
||||
*/
|
||||
ApacheHttpClientBuilder sslConnectionSocketFactory(SSLConnectionSocketFactory sslConnectionSocketFactory);
|
||||
}
|
||||
|
||||
@@ -29,9 +29,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* httpclient 连接管理器 自带DNS解析
|
||||
* <p>
|
||||
* 大部分代码拷贝自:DefaultApacheHttpClientBuilder
|
||||
* httpclient 连接管理器 自带DNS解析.
|
||||
* <p>大部分代码拷贝自:DefaultApacheHttpClientBuilder</p>
|
||||
*
|
||||
* @author Andy.Huo
|
||||
*/
|
||||
@@ -64,7 +63,7 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
|
||||
private String httpProxyPassword;
|
||||
|
||||
/**
|
||||
* 闲置连接监控线程
|
||||
* 闲置连接监控线程.
|
||||
*/
|
||||
private IdleConnectionMonitorThread idleConnectionMonitorThread;
|
||||
private HttpClientBuilder httpClientBuilder;
|
||||
@@ -162,7 +161,7 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每路的最大链接数,默认10
|
||||
* 每路的最大链接数,默认10.
|
||||
*
|
||||
* @param maxConnPerHost 每路的最大链接数,默认10
|
||||
*/
|
||||
@@ -171,7 +170,7 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* 最大总连接数,默认50
|
||||
* 最大总连接数,默认50.
|
||||
*
|
||||
* @param maxTotalConn 最大总连接数,默认50
|
||||
*/
|
||||
@@ -180,7 +179,7 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义httpclient的User Agent
|
||||
* 自定义httpclient的User Agent.
|
||||
*
|
||||
* @param userAgent User Agent
|
||||
*/
|
||||
@@ -196,9 +195,12 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
|
||||
if (prepared.get()) {
|
||||
return;
|
||||
}
|
||||
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
.register("http", this.plainConnectionSocketFactory).register("https", this.sslConnectionSocketFactory)
|
||||
.build();
|
||||
|
||||
Registry<ConnectionSocketFactory> registry =
|
||||
RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
.register("http", this.plainConnectionSocketFactory)
|
||||
.register("https", this.sslConnectionSocketFactory)
|
||||
.build();
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
PoolingHttpClientConnectionManager connectionManager;
|
||||
@@ -219,8 +221,8 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
|
||||
connectionManager
|
||||
.setDefaultSocketConfig(SocketConfig.copy(SocketConfig.DEFAULT).setSoTimeout(this.soTimeout).build());
|
||||
|
||||
this.idleConnectionMonitorThread = new IdleConnectionMonitorThread(connectionManager, this.idleConnTimeout,
|
||||
this.checkWaitTime);
|
||||
this.idleConnectionMonitorThread = new IdleConnectionMonitorThread(
|
||||
connectionManager, this.idleConnTimeout, this.checkWaitTime);
|
||||
this.idleConnectionMonitorThread.setDaemon(true);
|
||||
this.idleConnectionMonitorThread.start();
|
||||
|
||||
@@ -234,8 +236,8 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
|
||||
if (StringUtils.isNotBlank(this.httpProxyHost) && StringUtils.isNotBlank(this.httpProxyUsername)) {
|
||||
// 使用代理服务器 需要用户认证的代理服务器
|
||||
CredentialsProvider provider = new BasicCredentialsProvider();
|
||||
provider.setCredentials(new AuthScope(this.httpProxyHost, this.httpProxyPort),
|
||||
new UsernamePasswordCredentials(this.httpProxyUsername, this.httpProxyPassword));
|
||||
provider.setCredentials(new AuthScope(this.httpProxyHost, this.httpProxyPort)
|
||||
, new UsernamePasswordCredentials(this.httpProxyUsername, this.httpProxyPassword));
|
||||
this.httpClientBuilder.setDefaultCredentialsProvider(provider);
|
||||
}
|
||||
|
||||
@@ -267,8 +269,10 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
|
||||
private final int checkWaitTime;
|
||||
private volatile boolean shutdown;
|
||||
|
||||
public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr, int idleConnTimeout,
|
||||
int checkWaitTime) {
|
||||
/**
|
||||
* 构造方法.
|
||||
*/
|
||||
public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr, int idleConnTimeout, int checkWaitTime) {
|
||||
super("IdleConnectionMonitorThread");
|
||||
this.connMgr = connMgr;
|
||||
this.idleConnTimeout = idleConnTimeout;
|
||||
@@ -289,12 +293,18 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发.
|
||||
*/
|
||||
public void trigger() {
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭.
|
||||
*/
|
||||
public void shutdown() {
|
||||
this.shutdown = true;
|
||||
synchronized (this) {
|
||||
|
||||
@@ -2,8 +2,8 @@ package me.chanjar.weixin.common.util.http.okhttp;
|
||||
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.HttpResponseProxy;
|
||||
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.HttpResponseProxy;
|
||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
||||
Reference in New Issue
Block a user