Browse Source

Merge pull request #735 in DESIGN/design from ~ALEX.SUNG/design:release/10.0 to release/10.0

REPORT-13673 设计器报错收集信息请求太多,要么合并起来发送zip到后端,要么后端就拒收了

* commit '5934011c6cd0c943d4537a102c4665fe876bef57':
  REPORT-13673 设计器报错收集信息请求太多,要么合并起来发送zip到后端,要么后端就拒收了 200条合并为1个请求发送; 发送失败本地缓存文件不会删除
bugfix/10.0
Alex.Sung 6 years ago
parent
commit
b3fd20cd75
  1. 31
      designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java

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

@ -8,6 +8,7 @@ import com.fr.general.GeneralContext;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.general.http.HttpResponseType; import com.fr.general.http.HttpResponseType;
import com.fr.general.http.HttpToolbox; import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.license.function.VT4FR; import com.fr.license.function.VT4FR;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
@ -21,7 +22,9 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
/** /**
* Created by Administrator on 2017/7/24 0024. * Created by Administrator on 2017/7/24 0024.
@ -35,6 +38,9 @@ public class ErrorInfoUploader {
// 在一台不能上网的电脑里发现了10w个errorinfo... // 在一台不能上网的电脑里发现了10w个errorinfo...
private static final int MAX_ERROR_SIZE = 2000; private static final int MAX_ERROR_SIZE = 2000;
//单次发送的错误信息最大条数
private static final int MAX_ITEMS = 200;
static { static {
GeneralContext.addEnvChangedListener(new EnvChangedListener() { GeneralContext.addEnvChangedListener(new EnvChangedListener() {
@Override @Override
@ -142,21 +148,28 @@ public class ErrorInfoUploader {
try { try {
if (ArrayUtils.isNotEmpty(files)) { if (ArrayUtils.isNotEmpty(files)) {
JSONArray jsonArray = new JSONArray();
List<File> tempFiles = new ArrayList<>();
int count = 0;
for (File file : files) { for (File file : files) {
count++;
String filePath = file.getPath(); String filePath = file.getPath();
String suffix = filePath.substring(filePath.lastIndexOf(".")); String suffix = filePath.substring(filePath.lastIndexOf("."));
if (suffix.endsWith(SUFFIX)) { if (suffix.endsWith(SUFFIX)) {
Thread.sleep(1000L);
String content = IOUtils.inputStream2String(new FileInputStream(file)); String content = IOUtils.inputStream2String(new FileInputStream(file));
if (content.length() > MAX_ERROR_SIZE) { if (content.length() > MAX_ERROR_SIZE) {
CommonIOUtils.deleteFile(file); CommonIOUtils.deleteFile(file);
continue; continue;
} }
jsonArray.put(new JSONObject(content));
String url = CloudCenter.getInstance().acquireUrlByKind("design.error"); tempFiles.add(file);
if (sendErrorInfo(url, content)) { if( jsonArray.length() == MAX_ITEMS || count == files.length){
CommonIOUtils.deleteFile(file); String url = CloudCenter.getInstance().acquireUrlByKind("design.error");
if(sendErrorInfo(url, jsonArray)){
deleteFiles(tempFiles);
}
jsonArray = new JSONArray();
} }
} }
} }
@ -166,7 +179,13 @@ public class ErrorInfoUploader {
} }
} }
private boolean sendErrorInfo(String url, String content) { private void deleteFiles(List<File> files) {
for(File file : files) {
CommonIOUtils.deleteFile(file);
}
}
private boolean sendErrorInfo(String url, JSONArray content) {
HashMap<String, Object> para = new HashMap<>(); HashMap<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken()); para.put("token", SiteCenterToken.generateToken());
para.put("content", content); para.put("content", content);

Loading…
Cancel
Save