From 018f6386e297b5ac001689c541d52f886b9efc7a Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 25 Apr 2019 15:51:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-16494=20=E6=A8=A1=E6=9D=BF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=94=B6=E9=9B=86,=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=9C=89=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/template/info/SendHelper.java | 17 +++++---- .../template/info/SendHelperTest.java | 35 +++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 designer-base/src/test/java/com/fr/design/mainframe/template/info/SendHelperTest.java diff --git a/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java b/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java index 1f7aeec63d..8b188397c5 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java @@ -5,8 +5,8 @@ import com.fr.general.CloudCenter; import com.fr.general.ComparatorUtils; import com.fr.general.http.HttpToolbox; import com.fr.json.JSONObject; +import com.fr.log.FineLoggerFactory; -import java.io.IOException; import java.util.HashMap; /** @@ -30,14 +30,17 @@ class SendHelper { } private static boolean sendSingleTemplateInfo(String url, String content) { - HashMap para = new HashMap<>(); - para.put("token", SiteCenterToken.generateToken()); - para.put("content", content); - try { - String res = HttpToolbox.get(url, para); + HashMap para = new HashMap<>(); + para.put("token", SiteCenterToken.generateToken()); + para.put("content", content); + + String res = HttpToolbox.post(url, para); + return ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); - } catch (IOException ignore) { + } catch (Throwable e) { + // 客户不需要关心,错误等级为 debug 就行了 + FineLoggerFactory.getLogger().debug(e.getMessage(), e); } return false; } diff --git a/designer-base/src/test/java/com/fr/design/mainframe/template/info/SendHelperTest.java b/designer-base/src/test/java/com/fr/design/mainframe/template/info/SendHelperTest.java new file mode 100644 index 0000000000..fb89143d8d --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/mainframe/template/info/SendHelperTest.java @@ -0,0 +1,35 @@ +package com.fr.design.mainframe.template.info; + +import com.fr.invoke.Reflect; +import com.fr.stable.xml.XMLableReader; +import com.fr.third.javax.xml.stream.XMLStreamException; + +import java.io.StringReader; + +import static org.junit.Assert.assertTrue; + +/** + * Created by plough on 2019/4/25. + */ +public class SendHelperTest { + private static final String CONSUMING_URL = "http://cloud.fanruan.com/api/monitor/record_of_reports_consuming/single"; + private static final String PROCESS_URL = "http://cloud.fanruan.com/api/monitor/record_of_reports_process/single"; + + private static final String NORMAL_INFO = "\n" + + "\n" + + "\n" + + ""; + + // 只在调试的时候运行,不需要每次都自动运行 + public static void main(String[] args) throws XMLStreamException { + StringReader sr = new StringReader(NORMAL_INFO); + XMLableReader xmlReader = XMLableReader.createXMLableReader(sr); + TemplateInfo templateInfo = TemplateInfo.newInstanceByRead(xmlReader); + + boolean res = Reflect.on(SendHelper.class).call("sendSingleTemplateInfo", CONSUMING_URL, templateInfo.getConsumingMapJsonString()).get(); + assertTrue(res); + + boolean res2 = Reflect.on(SendHelper.class).call("sendSingleTemplateInfo", PROCESS_URL, templateInfo.getProcessMapJsonString()).get(); + assertTrue(res2); + } +} From 476d3821d682ffe2bd4f9161588345130f4589fd Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 25 Apr 2019 15:53:34 +0800 Subject: [PATCH 2/3] =?UTF-8?q?REPORT-16494=20=E6=A8=A1=E6=9D=BF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=94=B6=E9=9B=86,=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=9C=89=E6=8A=A5=E9=94=99=3D>=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/template/info/SendHelper.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java b/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java index 8b188397c5..b3437e4d3a 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java @@ -30,13 +30,12 @@ class SendHelper { } private static boolean sendSingleTemplateInfo(String url, String content) { - try { - HashMap para = new HashMap<>(); - para.put("token", SiteCenterToken.generateToken()); - para.put("content", content); + HashMap para = new HashMap<>(); + para.put("token", SiteCenterToken.generateToken()); + para.put("content", content); + try { String res = HttpToolbox.post(url, para); - return ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); } catch (Throwable e) { // 客户不需要关心,错误等级为 debug 就行了 From 376cc6c7b5b37016c5be9b261f5782ea14f711c6 Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 25 Apr 2019 15:54:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?REPORT-16494=20=E6=A8=A1=E6=9D=BF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=94=B6=E9=9B=86,=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=9C=89=E6=8A=A5=E9=94=99=3D>=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/mainframe/template/info/SendHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java b/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java index b3437e4d3a..db489fb3c5 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/template/info/SendHelper.java @@ -8,6 +8,7 @@ import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import java.util.HashMap; +import java.util.Map; /** * 负责向服务器发送信息 @@ -30,7 +31,7 @@ class SendHelper { } private static boolean sendSingleTemplateInfo(String url, String content) { - HashMap para = new HashMap<>(); + Map para = new HashMap<>(); para.put("token", SiteCenterToken.generateToken()); para.put("content", content);