WANG 6 vuotta sitten
vanhempi
commit
f43bbe83a6
1 muutettua tiedostoa jossa 6 lisäystä ja 13 poistoa
  1. 6 13
      src/main/java/cn/com/qmth/examcloud/web/upyun/UpYunClient.java

+ 6 - 13
src/main/java/cn/com/qmth/examcloud/web/upyun/UpYunClient.java

@@ -19,17 +19,14 @@ import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.commons.compress.utils.IOUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.http.HttpHost;
 import org.apache.http.HttpStatus;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpDelete;
 import org.apache.http.client.methods.HttpPut;
-import org.apache.http.conn.routing.HttpRoute;
 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;
@@ -82,21 +79,13 @@ public class UpYunClient {
 
 	private final String SEPARATOR = "/";
 
-	private static CloseableHttpClient httpclient;
-
 	private static RequestConfig requestConfig;
 
 	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();
+		requestConfig = RequestConfig.custom().setConnectionRequestTimeout(10000)
+				.setSocketTimeout(10000).setConnectTimeout(10000).build();
 	}
 
 	/**
@@ -183,6 +172,7 @@ public class UpYunClient {
 		CloseableHttpResponse response = null;
 
 		long s = System.currentTimeMillis();
+		CloseableHttpClient httpclient = HttpClients.createDefault();
 		try {
 
 			String date = getDate();
@@ -207,6 +197,7 @@ public class UpYunClient {
 			IOUtils.closeQuietly(in);
 			IOUtils.closeQuietly(response);
 			httpPut.releaseConnection();
+			IOUtils.closeQuietly(httpclient);
 		}
 
 		if (log.isDebugEnabled()) {
@@ -234,6 +225,7 @@ 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, "", "");
@@ -254,6 +246,7 @@ public class UpYunClient {
 		} finally {
 			IOUtils.closeQuietly(response);
 			httpDelete.releaseConnection();
+			IOUtils.closeQuietly(httpclient);
 		}
 
 		if (log.isDebugEnabled()) {