|
@@ -19,11 +19,13 @@ import javax.crypto.spec.SecretKeySpec;
|
|
|
|
|
|
import org.apache.commons.compress.utils.IOUtils;
|
|
import org.apache.commons.compress.utils.IOUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.http.HttpHost;
|
|
import org.apache.http.HttpStatus;
|
|
import org.apache.http.HttpStatus;
|
|
import org.apache.http.client.config.RequestConfig;
|
|
import org.apache.http.client.config.RequestConfig;
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.HttpDelete;
|
|
import org.apache.http.client.methods.HttpDelete;
|
|
import org.apache.http.client.methods.HttpPut;
|
|
import org.apache.http.client.methods.HttpPut;
|
|
|
|
+import org.apache.http.conn.routing.HttpRoute;
|
|
import org.apache.http.entity.InputStreamEntity;
|
|
import org.apache.http.entity.InputStreamEntity;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.HttpClients;
|
|
import org.apache.http.impl.client.HttpClients;
|
|
@@ -80,12 +82,23 @@ public class UpYunClient {
|
|
|
|
|
|
private final String SEPARATOR = "/";
|
|
private final String SEPARATOR = "/";
|
|
|
|
|
|
- private CloseableHttpClient httpclient;
|
|
|
|
|
|
+ private static CloseableHttpClient httpclient;
|
|
|
|
|
|
- private RequestConfig requestConfig;
|
|
|
|
|
|
+ private static RequestConfig requestConfig;
|
|
|
|
|
|
private String domain;
|
|
private String domain;
|
|
|
|
|
|
|
|
+ static {
|
|
|
|
+ PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
|
|
|
+ cm.setMaxTotal(1000);
|
|
|
|
+ cm.setMaxPerRoute(new HttpRoute(new HttpHost(API_DOMAIN, 80)), 800);
|
|
|
|
+ httpclient = HttpClients.custom().setConnectionManager(cm).disableAutomaticRetries()
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ requestConfig = RequestConfig.custom().setConnectionRequestTimeout(2000)
|
|
|
|
+ .setSocketTimeout(10000).setConnectTimeout(2000).build();
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 构造函数
|
|
* 构造函数
|
|
*
|
|
*
|
|
@@ -94,13 +107,6 @@ public class UpYunClient {
|
|
* @param password
|
|
* @param password
|
|
*/
|
|
*/
|
|
public UpYunClient(String bucketName, String userName, String password, String domain) {
|
|
public UpYunClient(String bucketName, String userName, String password, String domain) {
|
|
- PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
|
|
|
- cm.setMaxTotal(1000);
|
|
|
|
- cm.setDefaultMaxPerRoute(20);
|
|
|
|
- httpclient = HttpClients.custom().setConnectionManager(cm).disableAutomaticRetries()
|
|
|
|
- .build();
|
|
|
|
- requestConfig = RequestConfig.custom().setConnectionRequestTimeout(2000)
|
|
|
|
- .setSocketTimeout(10000).setConnectTimeout(2000).build();
|
|
|
|
|
|
|
|
this.bucketName = bucketName;
|
|
this.bucketName = bucketName;
|
|
this.userName = userName;
|
|
this.userName = userName;
|
|
@@ -173,7 +179,7 @@ public class UpYunClient {
|
|
String url = "https://" + API_DOMAIN + path;
|
|
String url = "https://" + API_DOMAIN + path;
|
|
|
|
|
|
HttpPut httpPut = new HttpPut(url);
|
|
HttpPut httpPut = new HttpPut(url);
|
|
- httpPut.setConfig(this.requestConfig);
|
|
|
|
|
|
+ httpPut.setConfig(UpYunClient.requestConfig);
|
|
CloseableHttpResponse response = null;
|
|
CloseableHttpResponse response = null;
|
|
|
|
|
|
long s = System.currentTimeMillis();
|
|
long s = System.currentTimeMillis();
|
|
@@ -224,7 +230,7 @@ public class UpYunClient {
|
|
String url = "https://" + API_DOMAIN + path;
|
|
String url = "https://" + API_DOMAIN + path;
|
|
|
|
|
|
HttpDelete httpDelete = new HttpDelete(url);
|
|
HttpDelete httpDelete = new HttpDelete(url);
|
|
- httpDelete.setConfig(this.requestConfig);
|
|
|
|
|
|
+ httpDelete.setConfig(UpYunClient.requestConfig);
|
|
CloseableHttpResponse response = null;
|
|
CloseableHttpResponse response = null;
|
|
|
|
|
|
long s = System.currentTimeMillis();
|
|
long s = System.currentTimeMillis();
|