|
@@ -13,6 +13,7 @@ import java.util.Calendar;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.TimeZone;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import javax.crypto.Mac;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
@@ -27,6 +28,7 @@ import org.apache.http.client.methods.HttpPut;
|
|
|
import org.apache.http.entity.InputStreamEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
@@ -79,11 +81,21 @@ public class UpYunClient {
|
|
|
|
|
|
private final String SEPARATOR = "/";
|
|
|
|
|
|
+ private static CloseableHttpClient httpclient;
|
|
|
+
|
|
|
private static RequestConfig requestConfig;
|
|
|
|
|
|
private String domain;
|
|
|
|
|
|
static {
|
|
|
+ PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(10,
|
|
|
+ TimeUnit.SECONDS);
|
|
|
+ cm.setValidateAfterInactivity(2000);
|
|
|
+ cm.setMaxTotal(1000);
|
|
|
+ cm.setDefaultMaxPerRoute(1000);
|
|
|
+ httpclient = HttpClients.custom().setConnectionManager(cm).disableAutomaticRetries()
|
|
|
+ .build();
|
|
|
+
|
|
|
requestConfig = RequestConfig.custom().setConnectionRequestTimeout(10000)
|
|
|
.setSocketTimeout(10000).setConnectTimeout(10000).build();
|
|
|
}
|
|
@@ -172,7 +184,6 @@ public class UpYunClient {
|
|
|
CloseableHttpResponse response = null;
|
|
|
|
|
|
long s = System.currentTimeMillis();
|
|
|
- CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
try {
|
|
|
|
|
|
String date = getDate();
|
|
@@ -197,7 +208,6 @@ public class UpYunClient {
|
|
|
IOUtils.closeQuietly(in);
|
|
|
IOUtils.closeQuietly(response);
|
|
|
httpPut.releaseConnection();
|
|
|
- IOUtils.closeQuietly(httpclient);
|
|
|
}
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
@@ -225,7 +235,6 @@ public class UpYunClient {
|
|
|
CloseableHttpResponse response = null;
|
|
|
|
|
|
long s = System.currentTimeMillis();
|
|
|
- CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
try {
|
|
|
String date = getDate();
|
|
|
String authorization = sign(userName, md5Password, METHOD_DELETE, path, date, "", "");
|
|
@@ -246,7 +255,6 @@ public class UpYunClient {
|
|
|
} finally {
|
|
|
IOUtils.closeQuietly(response);
|
|
|
httpDelete.releaseConnection();
|
|
|
- IOUtils.closeQuietly(httpclient);
|
|
|
}
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|