From 5ac90a8c5fea1e97146891b7991d418319a2a715 Mon Sep 17 00:00:00 2001 From: neil <459208047@qq.com> Date: Wed, 9 Aug 2017 18:49:50 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-2539=20=E6=99=BA=E8=83=BD=E7=9B=91?= =?UTF-8?q?=E6=B5=8B=E8=AE=BE=E8=AE=A1=E5=99=A8=E6=9B=B4=E6=96=B0=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E6=96=B9=E6=A1=88.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../errorinfo/ErrorInfoLogAppender.java | 20 ++++--- .../errorinfo/ErrorInfoUploader.java | 60 +++++++++++++++++++ 2 files changed, 71 insertions(+), 9 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/errorinfo/ErrorInfoLogAppender.java b/designer/src/com/fr/design/mainframe/errorinfo/ErrorInfoLogAppender.java index 1d4f65de5..f01bb669e 100644 --- a/designer/src/com/fr/design/mainframe/errorinfo/ErrorInfoLogAppender.java +++ b/designer/src/com/fr/design/mainframe/errorinfo/ErrorInfoLogAppender.java @@ -6,6 +6,7 @@ import com.fr.base.io.XMLReadHelper; import com.fr.design.DesignerEnvManager; import com.fr.general.FRLogLevel; import com.fr.general.FRLogManager; +import com.fr.general.Inter; import com.fr.general.LogDuration; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; @@ -75,16 +76,17 @@ public class ErrorInfoLogAppender extends AppenderSkeleton { } private String readLogID(String log) { - int dotIndex = log.lastIndexOf(":"); - if (dotIndex != -1) { - int end = Math.min(dotIndex + ERROR_LEN, log.length()); - String logid = log.substring(dotIndex + 1, end).trim(); - try { - Long.parseLong(logid); - return logid; - } catch (Exception ignore) { + String errorCode = Inter.getLocText("FR-Engine_ErrorCode-Prefix"); + String[] matchs = log.split(errorCode + ".*?:"); + if (matchs.length <= 1) { + return StringUtils.EMPTY; + } + + String includeIDStr = matchs[1].trim(); + try { + return Long.parseLong(includeIDStr.substring(0, ERROR_LEN)) + StringUtils.EMPTY; + } catch (Exception ignore) { - } } return StringUtils.EMPTY; diff --git a/designer/src/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java b/designer/src/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java index 0204d33a9..7865f6d52 100644 --- a/designer/src/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java +++ b/designer/src/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java @@ -1,7 +1,9 @@ package com.fr.design.mainframe.errorinfo; +import com.fr.base.FRContext; import com.fr.general.*; import com.fr.general.http.HttpClient; +import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.stable.CodeUtils; import com.fr.stable.EnvChangedListener; @@ -10,6 +12,8 @@ import com.fr.stable.StableUtils; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.HashMap; @@ -45,7 +49,63 @@ public class ErrorInfoUploader { return collector; } + // 从云中心更新最新的解决方案文件 + private void checkUpdateSolution(){ + Thread updateThread = new Thread(new Runnable() { + @Override + public void run() { + String localCacheFilePath = StableUtils.pathJoin(ProductConstants.getEnvHome(), "solution", "solution.zip"); + File localCacheZip = new File(localCacheFilePath); + if (needUpdate(localCacheZip)) { + downloadSolution(localCacheZip); + } + } + }); + updateThread.start(); + } + + private void downloadSolution(File localCacheZip) { + try { + String downloadURL = SiteCenter.getInstance().acquireUrlByKind("solution.download", "http://cloud.fanruan.com/api/solution"); + HttpClient hc = new HttpClient(downloadURL); + hc.asGet(); + InputStream in = hc.getResponseStream(); + StableUtils.makesureFileExist(localCacheZip); + FileOutputStream out = new FileOutputStream(localCacheZip); + IOUtils.copyBinaryTo(in, out); + out.close(); + in.close(); + + IOUtils.unzip(localCacheZip, localCacheZip.getParent()); + } catch (Exception e) { + FRContext.getLogger().debug(e.getMessage()); + } + + } + + private boolean needUpdate(File localCacheZip){ + if (localCacheZip.exists()) { + // 判断本地文件大小. + String checkURL = SiteCenter.getInstance().acquireUrlByKind("solution.check", "http://cloud.fanruan.com/api/checkUpdate"); + 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) { + } + } + return false; + } + return true; + } + public void sendErrorInfo(){ + // 判断更新解决方案缓存. + checkUpdateSolution(); + //读取文件夹里的json, 加入上传队列中. File folder = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FOLDER_NAME)); if (!folder.exists()) {