|
@@ -20,6 +20,7 @@ import org.apache.http.client.methods.HttpPut;
|
|
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;
|
|
|
|
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
import com.upyun.UpException;
|
|
import com.upyun.UpException;
|
|
@@ -82,8 +83,10 @@ public class UpYunClient {
|
|
* @param password
|
|
* @param password
|
|
*/
|
|
*/
|
|
public UpYunClient(String bucketName, String userName, String password) {
|
|
public UpYunClient(String bucketName, String userName, String password) {
|
|
-
|
|
|
|
- httpclient = HttpClients.custom().disableAutomaticRetries().build();;
|
|
|
|
|
|
+ PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
|
|
|
+ cm.setMaxTotal(1000);
|
|
|
|
+ httpclient = HttpClients.custom().setConnectionManager(cm).disableAutomaticRetries()
|
|
|
|
+ .build();
|
|
requestConfig = RequestConfig.custom().setConnectionRequestTimeout(10000)
|
|
requestConfig = RequestConfig.custom().setConnectionRequestTimeout(10000)
|
|
.setSocketTimeout(10000).setConnectTimeout(10000).build();
|
|
.setSocketTimeout(10000).setConnectTimeout(10000).build();
|
|
|
|
|
|
@@ -128,7 +131,7 @@ public class UpYunClient {
|
|
|
|
|
|
HttpPut httpPut = new HttpPut(url);
|
|
HttpPut httpPut = new HttpPut(url);
|
|
httpPut.setConfig(this.requestConfig);
|
|
httpPut.setConfig(this.requestConfig);
|
|
-
|
|
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
try {
|
|
try {
|
|
String date = getGMTDate();
|
|
String date = getGMTDate();
|
|
httpPut.addHeader(DATE, date);
|
|
httpPut.addHeader(DATE, date);
|
|
@@ -139,7 +142,7 @@ public class UpYunClient {
|
|
httpPut.addHeader(MKDIR, "true");
|
|
httpPut.addHeader(MKDIR, "true");
|
|
|
|
|
|
httpPut.setEntity(new InputStreamEntity(in));
|
|
httpPut.setEntity(new InputStreamEntity(in));
|
|
- CloseableHttpResponse response = httpclient.execute(httpPut);
|
|
|
|
|
|
+ response = httpclient.execute(httpPut);
|
|
int statusCode = response.getStatusLine().getStatusCode();
|
|
int statusCode = response.getStatusLine().getStatusCode();
|
|
|
|
|
|
if (HttpStatus.SC_OK != statusCode) {
|
|
if (HttpStatus.SC_OK != statusCode) {
|
|
@@ -153,8 +156,9 @@ public class UpYunClient {
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw new ExamCloudRuntimeException(e);
|
|
throw new ExamCloudRuntimeException(e);
|
|
} finally {
|
|
} finally {
|
|
- httpPut.releaseConnection();
|
|
|
|
IOUtils.closeQuietly(in);
|
|
IOUtils.closeQuietly(in);
|
|
|
|
+ IOUtils.closeQuietly(response);
|
|
|
|
+ httpPut.releaseConnection();
|
|
}
|
|
}
|
|
|
|
|
|
String fileUrl = "http://" + bucketName + ".b0.upaiyun.com" + filePath;
|
|
String fileUrl = "http://" + bucketName + ".b0.upaiyun.com" + filePath;
|