Browse Source

Merge pull request #711 in DESIGN/design from ~RICHIE/design:release/10.0 to release/10.0

* commit 'b6f567dab66065b2a89db0ffcfb0d1427147fb6b':
  无JIRA任务 去掉httpclient的使用
bugfix/10.0
richie 6 years ago
parent
commit
0c9ee893c0
  1. 82
      designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java

82
designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java

@ -3,15 +3,16 @@ package com.fr.design.mainframe.errorinfo;
import com.fr.base.FRContext;
import com.fr.design.mainframe.SiteCenterToken;
import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils;
import com.fr.general.CommonIOUtils;
import com.fr.general.GeneralContext;
import com.fr.general.IOUtils;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONException;
import com.fr.general.http.HttpResponseType;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject;
import com.fr.license.function.VT4FR;
import com.fr.log.FineLoggerFactory;
import com.fr.log.LogHandler;
import com.fr.stable.ArrayUtils;
import com.fr.stable.EnvChangedListener;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
@ -93,9 +94,7 @@ public class ErrorInfoUploader {
try {
String downloadURL = CloudCenter.getInstance().acquireUrlByKind("solution.download", "http://cloud.fanruan.com/api/solution");
downloadURL = String.format("%s?token=%s", downloadURL, SiteCenterToken.generateToken());
HttpClient hc = new HttpClient(downloadURL);
hc.asGet();
InputStream in = hc.getResponseStream();
InputStream in = HttpToolbox.post(downloadURL, new HashMap<String, Object>(), HttpResponseType.STREAM);
StableUtils.makesureFileExist(localCacheZip);
FileOutputStream out = new FileOutputStream(localCacheZip);
IOUtils.copyBinaryTo(in, out);
@ -114,15 +113,11 @@ public class ErrorInfoUploader {
// 判断本地文件大小.
String checkURL = CloudCenter.getInstance().acquireUrlByKind("solution.check", "http://cloud.fanruan.com/api/solution/cache/check");
checkURL = String.format("%s?token=%s", checkURL, SiteCenterToken.generateToken());
HttpClient client = new HttpClient(checkURL);
client.asGet();
if (client.isServerAlive()) {
try {
JSONObject res = new JSONObject(client.getResponseText());
// 简单粗暴, 直接判断文件大小.
return res.optLong("version") != localCacheZip.length();
} catch (JSONException ignore) {
}
try {
JSONObject res = new JSONObject(HttpToolbox.get(checkURL));
// 简单粗暴, 直接判断文件大小.
return res.optLong("version") != localCacheZip.length();
} catch (Exception ignore) {
}
return false;
}
@ -140,27 +135,29 @@ public class ErrorInfoUploader {
}
File[] files = folder.listFiles();
if (files.length > MAX_ERROR_SIZE) {
StableUtils.deleteFile(folder);
if (ArrayUtils.getLength(files) > MAX_ERROR_SIZE) {
CommonIOUtils.deleteFile(folder);
return;
}
try {
for (File file : files) {
String filePath = file.getPath();
String suffix = filePath.substring(filePath.lastIndexOf("."));
if (suffix.endsWith(SUFFIX)) {
Thread.sleep(1000L);
String content = IOUtils.inputStream2String(new FileInputStream(file));
if (content.length() > MAX_ERROR_SIZE) {
file.delete();
continue;
}
String url = CloudCenter.getInstance().acquireUrlByKind("design.error");
if (sendErroInfo(url, content)) {
file.delete();
if (ArrayUtils.isNotEmpty(files)) {
for (File file : files) {
String filePath = file.getPath();
String suffix = filePath.substring(filePath.lastIndexOf("."));
if (suffix.endsWith(SUFFIX)) {
Thread.sleep(1000L);
String content = IOUtils.inputStream2String(new FileInputStream(file));
if (content.length() > MAX_ERROR_SIZE) {
CommonIOUtils.deleteFile(file);
continue;
}
String url = CloudCenter.getInstance().acquireUrlByKind("design.error");
if (sendErrorInfo(url, content)) {
CommonIOUtils.deleteFile(file);
}
}
}
}
@ -169,25 +166,18 @@ public class ErrorInfoUploader {
}
}
private boolean sendErroInfo(String url, String content) {
HashMap<String, String> para = new HashMap<>();
private boolean sendErrorInfo(String url, String content) {
HashMap<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
para.put("content", content);
HttpClient httpClient = new HttpClient(url, para, true);
httpClient.asGet();
if (!httpClient.isServerAlive()) {
return false;
}
String res = httpClient.getResponseText();
boolean success;
try {
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
} catch (Exception ex) {
success = true;
String responseText = HttpToolbox.post(url, para);
return "success".equals(new JSONObject(responseText).get("status"));
} catch (Exception ignore) {
}
return success;
return false;
}

Loading…
Cancel
Save