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