From 018f6386e297b5ac001689c541d52f886b9efc7a Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 25 Apr 2019 15:51:51 +0800 Subject: [PATCH] =?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 1f7aeec63..8b188397c 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 000000000..fb89143d8 --- /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); + } +}