|
@@ -27,6 +27,8 @@ import com.upyun.UpYunUtils;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.ExamCloudRuntimeException;
|
|
import cn.com.qmth.examcloud.commons.base.exception.ExamCloudRuntimeException;
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLog;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLogFactory;
|
|
|
|
|
|
/**
|
|
/**
|
|
* upyun SDK定制版
|
|
* upyun SDK定制版
|
|
@@ -37,6 +39,8 @@ import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
*/
|
|
*/
|
|
public class UpYunClient {
|
|
public class UpYunClient {
|
|
|
|
|
|
|
|
+ protected ExamCloudLog log = ExamCloudLogFactory.getLog(this.getClass());
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 空间名
|
|
* 空间名
|
|
*/
|
|
*/
|
|
@@ -119,8 +123,8 @@ public class UpYunClient {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public String writeFile(String filePath, InputStream in) {
|
|
public String writeFile(String filePath, InputStream in) {
|
|
- filePath = formatPath(filePath);
|
|
|
|
- String url = "http://" + API_DOMAIN + filePath;
|
|
|
|
|
|
+ String path = formatPath(filePath);
|
|
|
|
+ String url = "http://" + API_DOMAIN + path;
|
|
|
|
|
|
HttpPut httpPut = new HttpPut(url);
|
|
HttpPut httpPut = new HttpPut(url);
|
|
httpPut.setConfig(this.requestConfig);
|
|
httpPut.setConfig(this.requestConfig);
|
|
@@ -130,15 +134,16 @@ public class UpYunClient {
|
|
httpPut.addHeader(DATE, date);
|
|
httpPut.addHeader(DATE, date);
|
|
|
|
|
|
httpPut.addHeader(AUTHORIZATION, UpYunUtils
|
|
httpPut.addHeader(AUTHORIZATION, UpYunUtils
|
|
- .sign(METHOD_PUT, date, filePath, userName, this.md5Password, null).trim());
|
|
|
|
|
|
+ .sign(METHOD_PUT, date, path, userName, this.md5Password, null).trim());
|
|
|
|
|
|
httpPut.addHeader(MKDIR, "true");
|
|
httpPut.addHeader(MKDIR, "true");
|
|
|
|
|
|
httpPut.setEntity(new InputStreamEntity(in));
|
|
httpPut.setEntity(new InputStreamEntity(in));
|
|
CloseableHttpResponse response = httpclient.execute(httpPut);
|
|
CloseableHttpResponse response = httpclient.execute(httpPut);
|
|
int statusCode = response.getStatusLine().getStatusCode();
|
|
int statusCode = response.getStatusLine().getStatusCode();
|
|
- System.out.println(EntityUtils.toString(response.getEntity(), "UTF-8"));
|
|
|
|
|
|
+
|
|
if (HttpStatus.SC_OK != statusCode) {
|
|
if (HttpStatus.SC_OK != statusCode) {
|
|
|
|
+ log.error("[upyun error] " + EntityUtils.toString(response.getEntity(), "UTF-8"));
|
|
throw new StatusException("EX-100001", "upyun upload failure");
|
|
throw new StatusException("EX-100001", "upyun upload failure");
|
|
}
|
|
}
|
|
} catch (StatusException e) {
|
|
} catch (StatusException e) {
|
|
@@ -152,9 +157,8 @@ public class UpYunClient {
|
|
IOUtils.closeQuietly(in);
|
|
IOUtils.closeQuietly(in);
|
|
}
|
|
}
|
|
|
|
|
|
- String path = " http://" + bucketName + ".b0.upaiyun.com" + filePath;
|
|
|
|
- return path;
|
|
|
|
-
|
|
|
|
|
|
+ String fileUrl = " http://" + bucketName + ".b0.upaiyun.com" + filePath;
|
|
|
|
+ return fileUrl;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|