WANG 6 rokov pred
rodič
commit
163b165677

+ 11 - 7
examcloud-exchange-inner-service/src/main/java/cn/com/qmth/examcloud/exchange/inner/service/upyun/UpYunClient.java

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